[s]scanf should fail when scanning any negative integer (i.e. a natural number preceded by the '-' sign) if the "%u" format specifier is given. test: #include <stdint.h> #include <stdio.h> int main() { int r; const char *x = "-1"; uint32_t y; if ( 1 == sscanf(x,"%u",&y) ) { printf("sscanf incorrectly scanned a signed integer using an " "unsigned format specifier resulting in y=%u\n", y); r = -1; } else { printf("sscanf correctly failed to scan a signed integer " "using an unsigned format specifier\n"); r = 0; } return r; } Quoting from "man (3) scanf" "u Matches an unsigned decimal integer" Reproducible: Always Steps to Reproduce: 1. run test 2. 3. Actual Results: sscanf incorrectly scanned a signed integer using an unsigned format specifier resulting in y=4294967295 Expected Results: sscanf correctly failed to scan a signed integer using an unsigned format specifier Can't say at the moment whether this is part of iso/c99 or ansi, but it really should be.
seems to me it's acting correctly according to POSIX. http://pubs.opengroup.org/onlinepubs/9699919799/functions/scanf.html u Matches an optionally signed decimal integer, whose format is the same as expected for the subject sequence of strtoul() with the value 10 for the base argument. In the absence of a size modifier, the application shall ensure that the corresponding argument is a pointer to unsigned. http://pubs.opengroup.org/onlinepubs/9699919799/functions/strtoul.html The subject sequence is defined as the longest initial subsequence of the input string, starting with the first non-white-space character that is of the expected form. The subject sequence shall contain no characters if the input string is empty or consists entirely of white-space characters, or if the first non-white-space character is other than a sign or a permissible letter or digit. if you want to dispute that, feel free to bring it to the upstream mailing list and/or bugzilla as i don't plan on doing anything unique here ...