Skip to content

Instantly share code, notes, and snippets.

@k-takata
Created August 14, 2015 22:43
Show Gist options
  • Save k-takata/07764e23815a3959d431 to your computer and use it in GitHub Desktop.
Save k-takata/07764e23815a3959d431 to your computer and use it in GitHub Desktop.
VC14's sscanf returns different value
#include <stdio.h>
int main()
{
int i, d, n, ret;
char *strs[] = {"3", "3x", "3\x80", "3\xf0", "3\xfe", "3\xff"};
for (i = 0; i < sizeof(strs) / sizeof(strs[0]); i++) {
ret = sscanf(strs[i], "%d%n", &d, &n);
printf("str=%s: d=%d, n=%d, ret=%d\n", strs[i], d, n, ret);
}
return 0;
}
@k-takata
Copy link
Author

VC7, VC10, Cygwin:

str=3: d=3, n=1, ret=1
str=3x: d=3, n=1, ret=1
str=3�: d=3, n=1, ret=1
str=3・ d=3, n=1, ret=1
str=3: d=3, n=1, ret=1
str=3: d=3, n=1, ret=1

VC14:

str=3: d=3, n=1, ret=1
str=3x: d=3, n=1, ret=1
str=3�: d=3, n=1, ret=1
str=3・ d=3, n=1, ret=1
str=3: d=3, n=1, ret=1
str=3: d=3, n=2, ret=1

When an input string is "3\xff", VC14's sscanf sets 2 to n.

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