mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Américo Wang" <xiyou.wangcong@gmail.com>
To: Andy Spencer <andy753421@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] fix %*s%n in sscanf
Date: Fri, 25 Sep 2009 15:02:35 +0800	[thread overview]
Message-ID: <2375c9f90909250002o59d5d375i8a670494db02287a@mail.gmail.com> (raw)
In-Reply-To: <20090925062734.GA9318@c.hsd1.tn.comcast.net>

On Fri, Sep 25, 2009 at 2:27 PM, Andy Spencer <andy753421@gmail.com> wrote:
> When using %*s, sscanf should honor conversion specifiers immediately following
> the %*s. For example, the following code should find the position of the end of
> the string "hello".
>
>  int end;
>  char buf[] = "hello    world";
>  sscanf(buf, "%*s%n", &end);
>  printf("%d\n", end);
>
> Ideally, sscanf would advance the fmt and str pointers the same as it would
> without the *, but the code for that is rather complicated and is not included
> in the patch.


Yeah, seems reasonable. So, without your patch, sscanf() in kernel
will ignore everything after '*', right?


>
> Please CC me in replies.
>
>
> Signed-off-by: Andy Spencer <andy753421@gmail.com>


Fortunately, a quick grep shows no one uses '%*' in sscanf()
in kernel space:

% grep 'sscanf(.*\".*%\*.*\".*)' -nr ./

For completeness,

Acked-by: WANG Cong <xiyou.wangcong@gmail.com>

>
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index 73a14b8..da2daf2 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -1766,7 +1766,7 @@ int vsscanf(const char * buf, const char * fmt, va_list args)
>                 * advance both strings to next white space
>                 */
>                if (*fmt == '*') {
> -                       while (!isspace(*fmt) && *fmt)
> +                       while (!isspace(*fmt) && *fmt != '%' && *fmt)
>                                fmt++;
>                        while (!isspace(*str) && *str)
>                                str++;
>

  reply	other threads:[~2009-09-25  7:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-25  6:27 Andy Spencer
2009-09-25  7:02 ` Américo Wang [this message]
2009-09-25 10:42   ` Andy Spencer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2375c9f90909250002o59d5d375i8a670494db02287a@mail.gmail.com \
    --to=xiyou.wangcong@gmail.com \
    --cc=andy753421@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®