Skip to content

Negative Values for int64 not working #9

Description

@dcbo

When I register the example
parser.registerCommand("test", "sdiu", &cmd_test);
and parse the following Message:
test "Hello World" 13.23 -45 85
I get 45 for the interger instead of -45
Serial.print("int64: "); Serial.println(args[2].asInt64);
gives
int64: 45

It seems that the negative value is parsed, because when i submit a negative value for uint64
test "Hallo Welt" 13.23 -45 -85
then i get the Error;
parse error: invalid uint64_t for arg 4

Activity

  1. m-marini commented on Feb 8, 2022

    @m-marini

    Same problem.
    I fixed it substituing the end of strToInt function

        return digit == -1 ? 0 : position; // ensure that there is at least one digit
    

    with

       if (digit == -1) {
          return 0;
        }
        if (isNegative) {
          *value = -*value;
        }
        return position; // ensure that there is at least one digit
    
  2. djipco commented on Nov 20, 2022

    @djipco

    I have the same issue. Would it be possible to merge #7 which, I believe, fixes this. Meanwhile, I jerry-rigged the code with the suggestion from @m-marini (thanks for that!).

    Thank you!

  3. freudenthal commented on Oct 11, 2024

    @freudenthal

    My fix was to:

    else if (base >= 16 && 'A' <= buf[position] && buf[position] <= 'F') { digit = (buf[position] - 'A') + 10; } else { if (isNegative) { *value = -(*value); } break; }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions