get rid of undefined behavior regarding order of evaluation

master
leitner 12 months ago
parent cee447066f
commit b375c53c7d

@ -1,7 +1,8 @@
#include "parse.h"
uint16_t prs_u16(struct bytestream* bs) {
return bs_get(bs) | (bs_get(bs) << 8);
unsigned char c = bs_get(bs);
return c | (bs_get(bs) << 8);
}
#ifdef UNITTEST

@ -1,7 +1,8 @@
#include "parse.h"
uint16_t prs_u16_big(struct bytestream* bs) {
return (bs_get(bs) << 8) | bs_get(bs);
uint16_t x = bs_get(bs) << 8;
return x | bs_get(bs);
}
#ifdef UNITTEST

@ -1,7 +1,10 @@
#include "parse.h"
uint32_t prs_u32(struct bytestream* bs) {
return bs_get(bs) | (bs_get(bs) << 8) | (bs_get(bs) << 16) | (bs_get(bs) << 24);
uint32_t x = bs_get(bs);
x |= bs_get(bs) << 8;
x |= bs_get(bs) << 16;
return x | (bs_get(bs) << 24);
}
#ifdef UNITTEST

@ -1,7 +1,10 @@
#include "parse.h"
uint32_t prs_u32_big(struct bytestream* bs) {
return (bs_get(bs) << 24) | (bs_get(bs) << 16) | (bs_get(bs) << 8) | bs_get(bs);
uint32_t x = bs_get(bs) << 24;
x |= bs_get(bs) << 16;
x |= bs_get(bs) << 8;
return x | bs_get(bs);
}
#ifdef UNITTEST

Loading…
Cancel
Save