Gitweb:     
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=c6b40d16d1cfa1a01158049bb887a9bbe48ef7ba
Commit:     c6b40d16d1cfa1a01158049bb887a9bbe48ef7ba
Parent:     757dea93e136b219af09d3cd56a81063fdbdef1a
Author:     Johannes Berg <[EMAIL PROTECTED]>
AuthorDate: Tue May 8 00:27:20 2007 -0700
Committer:  Linus Torvalds <[EMAIL PROTECTED]>
CommitDate: Tue May 8 11:15:05 2007 -0700

    fix sscanf %n match at end of input string
    
    I was playing with some code that sometimes got a string where a %n
    match should have been done where the input string ended, for example
    like this:
    
      sscanf("abc123", "abc%d%n", &a, &n);  /* doesn't work */
      sscanf("abc123a", "abc%d%n", &a, &n); /* works */
    
    However, the scanf function in the kernel doesn't convert the %n in that
    case because it has already matched the complete input after %d and just
    completely stops matching then. This patch fixes that.
    
    [EMAIL PROTECTED]: cleanups]
    Signed-off-by: Johannes Berg <[EMAIL PROTECTED]>
    Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
    Signed-off-by: Linus Torvalds <[EMAIL PROTECTED]>
---
 lib/vsprintf.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index cbab1df..0172902 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -825,6 +825,17 @@ int vsscanf(const char * buf, const char * fmt, va_list 
args)
                        break;
                str = next;
        }
+
+       /*
+        * Now we've come all the way through so either the input string or the
+        * format ended. In the former case, there can be a %n at the current
+        * position in the format that needs to be filled.
+        */
+       if (*fmt == '%' && *(fmt + 1) == 'n') {
+               int *p = (int *)va_arg(args, int *);
+               *p = str - buf;
+       }
+
        return num;
 }
 
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to