From cd4a8585a8e3fe77dbffb8afd04af277edede447 Mon Sep 17 00:00:00 2001 From: Gunnar Dalsnes Date: Thu, 17 Mar 2005 00:31:40 +0000 Subject: [PATCH] scanf: fix handling of %n token svn path=/trunk/; revision=14157 --- reactos/lib/ntdll/stdio/scanf.h | 37 ++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/reactos/lib/ntdll/stdio/scanf.h b/reactos/lib/ntdll/stdio/scanf.h index a8dcde70740..22ee5139370 100644 --- a/reactos/lib/ntdll/stdio/scanf.h +++ b/reactos/lib/ntdll/stdio/scanf.h @@ -422,13 +422,36 @@ _FUNCTION_ { } } break; - case 'n': { - if (!suppress) { - int*n = va_arg(ap, int*); - *n = consumed - (nch!=_EOF_); - } - } - break; + case 'n': { + if (!suppress) { + int*n = va_arg(ap, int*); + + /* + *n = consumed - (nch!=_EOF_); + + FIXME: The above is the Wine version and it doesnt work in ros + when %n is at end of input string (return one too many). + But does it fail in Wine too?? If so wine also needs fixin. + -Gunnar + */ + + *n = consumed - 1; + } + /* This is an odd one: according to the standard, + * "Execution of a %n directive does not increment the + * assignment count returned at the completion of + * execution" even if it wasn't suppressed with the + * '*' flag. The Corrigendum to the standard seems + * to contradict this (comment out the assignment to + * suppress below if you want to implement these + * alternate semantics) but the windows program I'm + * looking at expects the behavior I've coded here + * (which happens to be what glibc does as well). + */ + suppress = 1; + st = 1; + } + break; case '[': { _CHAR_ *str = suppress ? NULL : va_arg(ap, _CHAR_*); _CHAR_ *sptr = str;