Fix undefined behaviors and misaligned member access

pull/317/head
Ryan Tharp 5 years ago
parent 1114ba1295
commit ad91071633

@ -22,6 +22,7 @@ small_random32(void)
#else
unsigned char x[4];
randombytes(x, 4);
return x[0] + (x[1] << 8) + (x[2] << 16) + (x[3] << 24);
uint32_t x4 = x[3] << 4;
return x[0] + (x[1] << 8) + (x[2] << 16) + x4;
#endif
}

@ -71,7 +71,8 @@ void
PackedSockAddr::set(const SOCKADDR_STORAGE *sa, socklen_t len)
{
// on unix, the cast does nothing, socklen_t is _already_ unsigned
if(sa->ss_family == AF_INET)
sockaddr_storage ssa = *sa; // stops member access with misaligned address
if( ssa.ss_family == AF_INET)
{
assert((unsigned)len >= sizeof(sockaddr_in));
const sockaddr_in *sin = (sockaddr_in *)sa;

@ -80,7 +80,8 @@ namespace llarp
Base32Encode(const V& value, Stack& stack)
{
size_t ret = 0, pos = 1;
int bits = 8, tmp = value[0];
int bits = 8;
uint32_t tmp = value[0];
size_t len = value.size();
while(ret < sizeof(stack) && (bits > 0 || pos < len))
{

Loading…
Cancel
Save