* [PATCH] scriptreplay: fscanf portability fix
@ 2011-07-22 20:15 Sami Kerola
2011-07-26 9:58 ` Karel Zak
0 siblings, 1 reply; 2+ messages in thread
From: Sami Kerola @ 2011-07-22 20:15 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
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. For now using %c in format string seems to be best option.
p.s. The llvm people are informed about the issue.
http://llvm.org/bugs/show_bug.cgi?id=10443
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
term-utils/scriptreplay.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/term-utils/scriptreplay.c b/term-utils/scriptreplay.c
index 96993d5..7f1b497 100644
--- 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')) {
if (feof(tfile))
break;
--
1.7.6
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] scriptreplay: fscanf portability fix
2011-07-22 20:15 [PATCH] scriptreplay: fscanf portability fix Sami Kerola
@ 2011-07-26 9:58 ` Karel Zak
0 siblings, 0 replies; 2+ messages in thread
From: Karel Zak @ 2011-07-26 9:58 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-07-26 9:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-22 20:15 [PATCH] scriptreplay: fscanf portability fix Sami Kerola
2011-07-26 9:58 ` Karel Zak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox