Loading ...
Sorry, an error occurred while loading the content.

5599Re: sscanf bugs (nuttx-6.30)

Expand Messages
  • spudarnia
    Mar 30 10:16 AM
    • 0 Attachment
      > Only change is to break parsing cycle ("if (!*buf) break;") when parsed string is parsed till its end, but we have some unparsed parameters in format string. It is necessary to stop increasing "count" value (result of sscanf function). Without this we have the following: sscanf("5", "%u%u", &n, &n) == 2. That is incorrect (return value in that case must be 1).

      I don't see that problem.  I pulled lib_sscanf.c into a separate file, fixed up some environmental dependencies, and added this main:

      int main(int argc, char **argv)
        int n=-1;
        int m=-1;
        printf("return is %d, n=%d, m=%d\n", sscanf("5", "%u%n", &n, &m));
        printf("n=%d, m=%d\n", n, m);
        return 0;

      When I build and run this on Cygwin, I get:

      $ gcc -o lib_sscanf lib_sscanf.c
      $ ./lib_sscanf.exe
      return is 1, n=2673952, m=2673948
      n=5, m=1

      So I am not seeing the error that you report.

    • Show all 12 messages in this topic