Util-Linux package development
 help / color / mirror / Atom feed
From: Karel Zak <kzak@redhat.com>
To: Sami Kerola <kerolasa@iki.fi>
Cc: util-linux@vger.kernel.org
Subject: Re: [PATCH] scriptreplay: fscanf portability fix
Date: Tue, 26 Jul 2011 11:58:42 +0200	[thread overview]
Message-ID: <20110726095842.GX22568@nb.net.home> (raw)
In-Reply-To: <1311365740-6251-1-git-send-email-kerolasa@iki.fi>

On Fri, Jul 22, 2011 at 10:15:40PM +0200, Sami Kerola wrote:
> This is a fix to an issue with llvm clang which I reported
> earlier.
> 
> http://www.spinics.net/lists/util-linux-ng/msg04331.html
> 
> When compiling with clang fscanf format string %[\n] will not
> work. 

 Sure, read scanf man page. The %[] format expects string +
 null byte. The bug is in the scriptreplay.c code where 
 we don't have room for the null byte :-( 
 
 I really don't think that this a llvm bug.

> --- a/term-utils/scriptreplay.c
> +++ b/term-utils/scriptreplay.c
> @@ -203,7 +203,7 @@ main(int argc, char *argv[])
>  		size_t blk;
>  		char nl;
        ^^^^^^^^
>  
> -		if ((fscanf(tfile, "%lf %zd%[\n]\n", &delay, &blk, &nl) != 3) ||
> +		if ((fscanf(tfile, "%lf %zd%c\n", &delay, &blk, &nl) != 3) ||
>  							(nl != '\n')) {

 Yep, it seems usable.

 Anyway, it's usually better to use fgets() + sscanf() to read and
 parse lines from files. The fscanf() could be tricky if your format
 depends on whitespaces.

 Applied, thanks.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

      reply	other threads:[~2011-07-26  9:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-22 20:15 [PATCH] scriptreplay: fscanf portability fix Sami Kerola
2011-07-26  9:58 ` Karel Zak [this message]

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=20110726095842.GX22568@nb.net.home \
    --to=kzak@redhat.com \
    --cc=kerolasa@iki.fi \
    --cc=util-linux@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