-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug with misaligned memory access
- Loading branch information
Showing
3 changed files
with
9 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
================================================================================*/ | ||
|
||
|
@@ -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--; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
================================================================================*/ | ||
|
||
|
@@ -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; | ||
|