Skip to content

Commit

Permalink
Merge pull request #136 from kentkost/junktest-windows-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mouse07410 authored Aug 31, 2023
2 parents b93d80f + 30d7a84 commit 208d9ed
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*.trs
*.core
.tmp.*
*.exe

# Generated by `autoreconf`
config/
Expand Down
15 changes: 10 additions & 5 deletions skeletons/asn_random_fill.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,22 @@ asn_random_between(intmax_t lb, intmax_t rb) {
uintmax_t range = asn__intmax_range(lb, rb);
uintmax_t value = 0;
uintmax_t got_entropy = 0;

(void)intmax_max;
assert(RAND_MAX > 0xffffff); /* Seen 7ffffffd! */
int max = 0xffffff;

#ifdef __WIN32__
max = RAND_MAX-1;
#endif

assert(RAND_MAX > max); /* Seen 7ffffffd! */
assert(range < intmax_max);

for(; got_entropy < range;) {
got_entropy = (got_entropy << 24) | 0xffffff;
got_entropy = (got_entropy << 24) | max;
#ifdef HAVE_RANDOM
value = (value << 24) | (random() % 0xffffff);
value = (value << 24) | (random() % max);
#else
value = (value << 24) | (rand() % 0xffffff);
value = (value << 24) | (rand() % max);
#endif
}

Expand Down
5 changes: 5 additions & 0 deletions skeletons/converter-example.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ static void junk_bytes_with_probability(uint8_t *, size_t, double prob);
#define RANDOPT "R:"
static ssize_t random_max_size = 0; /* Size of the random data */

#if defined(__WIN32__) && defined(JUNKTEST)
#define random rand
#define srandom srand
#endif

#if !defined(__FreeBSD__) && !(defined(__APPLE__) && defined(__MACH__))
static void
srandomdev(void) {
Expand Down

0 comments on commit 208d9ed

Please sign in to comment.