Skip to content

Commit

Permalink
Fix potential undefined behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
crudelios committed Aug 1, 2024
1 parent 99845a5 commit 626ea78
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/core/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ int8_t buffer_read_i8(buffer *buf)
int16_t buffer_read_i16(buffer *buf)
{
if (check_size(buf, 2)) {
uint8_t b0 = buf->data[buf->index++];
uint8_t b1 = buf->data[buf->index++];
uint16_t b0 = buf->data[buf->index++];
uint16_t b1 = buf->data[buf->index++];
return (int16_t) (b0 | (b1 << 8));
} else {
return 0;
Expand All @@ -145,10 +145,10 @@ int16_t buffer_read_i16(buffer *buf)
int32_t buffer_read_i32(buffer *buf)
{
if (check_size(buf, 4)) {
uint8_t b0 = buf->data[buf->index++];
uint8_t b1 = buf->data[buf->index++];
uint8_t b2 = buf->data[buf->index++];
uint8_t b3 = buf->data[buf->index++];
uint32_t b0 = buf->data[buf->index++];
uint32_t b1 = buf->data[buf->index++];
uint32_t b2 = buf->data[buf->index++];
uint32_t b3 = buf->data[buf->index++];
return (int32_t) (b0 | (b1 << 8) | (b2 << 16) | (b3 << 24));
} else {
return 0;
Expand Down

0 comments on commit 626ea78

Please sign in to comment.