Permalink
Browse files

Merge pull request #5 from cvtsi2sd/master

Fix undefined behavior in random_genXX helpers
  • Loading branch information...
2 parents bce3c17 + 5e53f91 commit 1f5efa077c8e0670793368ad8b556e63e9f461bc @asterix24 asterix24 committed on GitHub Jan 23, 2017
Showing with 5 additions and 5 deletions.
  1. +5 −5 bertos/sec/random.h
View
@@ -94,21 +94,21 @@ void random_gen(uint8_t *out, size_t len);
INLINE uint8_t random_gen8(void)
{
uint8_t x;
- random_gen(&x, 1);
+ random_gen(&x, sizeof(x));
return x;
}
INLINE uint16_t random_gen16(void)
{
- uint8_t x;
- random_gen(&x, 2);
+ uint16_t x;
+ random_gen((uint8_t *)&x, sizeof(x));
return x;
}
INLINE uint32_t random_gen32(void)
{
- uint8_t x;
- random_gen(&x, 4);
+ uint32_t x;
+ random_gen((uint8_t *)&x, sizeof(x));
return x;
}

0 comments on commit 1f5efa0

Please sign in to comment.