Signed-off-by: Will Mainio will.mainio@fastmail.com --- dlls/msvcrt/scanf.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/dlls/msvcrt/scanf.h b/dlls/msvcrt/scanf.h index 3b4686c1107..44cb0faa87e 100644 --- a/dlls/msvcrt/scanf.h +++ b/dlls/msvcrt/scanf.h @@ -615,6 +615,7 @@ _FUNCTION_ { _CHAR_ *sptr = str; RTL_BITMAP bitMask; ULONG *Mask; + VOID *scansetLastRangeEnd; int invert = 0; /* Set if we are NOT to find the chars */ #ifdef SECURE unsigned size = suppress ? UINT_MAX : va_arg(ap, unsigned); @@ -636,15 +637,17 @@ _FUNCTION_ { RtlSetBits(&bitMask, ']', 1); format++; } + scansetLastRangeEnd = (VOID *)(format - 1); while(*format && (*format != ']')) { /* According to msdn: * "Note that %[a-z] and %[z-a] are interpreted as equivalent to %[abcde...z]." */ - if((*format == '-') && (*(format + 1) != ']')) { + if((*format == '-') && ((VOID *)(format - 1) > scansetLastRangeEnd) && (*(format + 1) != ']')) { if ((*(format - 1)) < *(format + 1)) RtlSetBits(&bitMask, *(format - 1) +1 , *(format + 1) - *(format - 1)); else RtlSetBits(&bitMask, *(format + 1) , *(format - 1) - *(format + 1)); format++; + scansetLastRangeEnd = (VOID *)format; } else RtlSetBits(&bitMask, *format, 1); format++;
Signed-off-by: Will Mainio will.mainio@fastmail.com --- dlls/msvcrt/tests/scanf.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
diff --git a/dlls/msvcrt/tests/scanf.c b/dlls/msvcrt/tests/scanf.c index 57d9cc0ba12..1499e571db2 100644 --- a/dlls/msvcrt/tests/scanf.c +++ b/dlls/msvcrt/tests/scanf.c @@ -186,6 +186,22 @@ static void test_sscanf( void ) ok( ret == 1, "Error with format "%s"\n","%*[a-cd-dg-e]%c"); ok( buffer[0] == 'h', "Error with "abcefgdh" "%c"\n", buffer[0]);
+ ret = p_sscanf("-123","%[-0-9]s",buffer); + ok( ret == 1, "Error with format "%s"\n","%[-0-9]s"); + ok( strncmp("-123",buffer,strlen(buffer)) == 0, "Error with "-123" "%s"\n",buffer); + + ret = p_sscanf("-321","%[0-9-]s",buffer); + ok( ret == 1, "Error with format "%s"\n","%[0-9-]s"); + ok( strncmp("-321",buffer,strlen(buffer)) == 0, "Error with "-321" "%s"\n",buffer); + + ret = p_sscanf("-4123","%[1-2-4]s",buffer); + ok( ret == 1, "Error with format "%s"\n","%[1-2-4]s"); + ok( strncmp("-412",buffer,strlen(buffer)) == 0, "Error with "-412" "%s"\n",buffer); + + ret = p_sscanf("-456123","%[1-2-45-6]s",buffer); + ok( ret == 1, "Error with format "%s"\n","%[1-2-45-6]s"); + ok( strncmp("-45612",buffer,strlen(buffer)) == 0, "Error with "-45612" "%s"\n",buffer); + buffer1[0] = 'b'; ret = p_sscanf("a","%s%s", buffer, buffer1); ok( ret == 1, "expected 1, got %u\n", ret);