Integers footgun

Posted on May 19, 2024 in misc

Recently, a colleague of mine proposed the following change in our code base

Change:

    memcpy(network_buffer,
           original_message,
           MIN(original_message_size, OUT_BUFFER_MAX_SIZE));

To

    memcpy(network_buffer,
           &original_message[2],
           MIN(original_message_size - 2, OUT_BUFFER_MAX_SIZE));

The original intend was to skip the first two bytes (if any) because we didn't need them.

To have the full …


Continue reading