Skip to content

Commit

Permalink
Fix bug with misaligned memory access
Browse files Browse the repository at this point in the history
  • Loading branch information
Raimo33 committed Mar 2, 2025
1 parent b03e8f9 commit 2bf823c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/building-and-testing/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ To install FlashFIX you must compile it from source, as that will guarantee the

- CMake 3.10 or later
- gcc with c23 support
- CPU with unaligned memory access support
- CPU with misaligned memory access support

## Building

Expand Down
8 changes: 4 additions & 4 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Creator: Claudio Raimondi
Email: [email protected]
created at: 2025-02-24 16:35:15
last edited: 2025-03-02 18:50:22
last edited: 2025-03-02 21:57:40
================================================================================*/

Expand Down Expand Up @@ -42,12 +42,12 @@ uint8_t compute_checksum(const char *buffer, const char *const end)
{
uint16_t remaining = end - buffer;

uint8_t unaligned_bytes = align_forward(buffer);
unaligned_bytes -= (unaligned_bytes > remaining) & (unaligned_bytes - remaining);
uint8_t misaligned_bytes = align_forward(buffer);
misaligned_bytes -= (misaligned_bytes > remaining) * (misaligned_bytes - remaining);

uint8_t checksum = 0;

while (UNLIKELY(unaligned_bytes--))
while (UNLIKELY(misaligned_bytes--))
{
checksum += *buffer++;
remaining--;
Expand Down
8 changes: 4 additions & 4 deletions src/deserializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Creator: Claudio Raimondi
Email: [email protected]
created at: 2025-02-11 12:37:26
last edited: 2025-03-02 19:09:19
last edited: 2025-03-02 21:57:40
================================================================================*/

Expand Down Expand Up @@ -116,10 +116,10 @@ static const char *get_checksum_start(const char *buffer, const uint16_t buffer_
{
uint16_t remaining = buffer_size - STR_LEN("10=000\x01") + 1;

uint8_t unaligned_bytes = align_forward(buffer);
unaligned_bytes -= (unaligned_bytes > remaining) & (unaligned_bytes - remaining);
uint8_t misaligned_bytes = align_forward(buffer);
misaligned_bytes -= (misaligned_bytes > remaining) * (misaligned_bytes - remaining);

while (UNLIKELY(unaligned_bytes--))
while (UNLIKELY(misaligned_bytes--))
{
if (buffer[0] == '1' && check_zero_equal_soh(buffer + 1))
return buffer;
Expand Down

0 comments on commit 2bf823c

Please sign in to comment.