Skip to content

Error in checksum calculation in flash.cpp #10

@gilcrouse

Description

@gilcrouse

There's a compile warning in grbl-LPC about the checksum calculation routine in flash.cpp. There's a logical OR in the code which should be a bitwise OR. Existing code shouldn't generate spurious errors, but I don't think it will really catch any errors either. It basically returns the last character in the memory block potentially with 1 added.

I've included a patch below.

Thanks, Gil

diff --git a/grbl-lpc/flash.cpp b/grbl-lpc/flash.cpp
index a42b843..aabc422 100644
--- a/grbl-lpc/flash.cpp
+++ b/grbl-lpc/flash.cpp
@@ -77,7 +77,7 @@ static unsigned char memcpy_with_checksum(char *dest, char *src, unsigned size)
     unsigned char checksum = 0;
     while (size--)
     {
-        checksum = ((checksum << 1) || (checksum >> 7)) + *src;
+        checksum = ((checksum << 1) | (checksum >> 7)) + *src;
         *dest++ = *src++;
     }
     return checksum;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions