[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-recutils] 1.7: suppress -Wformat error
From: |
Daiki Ueno |
Subject: |
[bug-recutils] 1.7: suppress -Wformat error |
Date: |
Thu, 27 Mar 2014 19:22:23 +0900 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
Hi Jose,
As the Fedora build sytem supplies -Werror=format-security, I got the
following error on compiling. I'm attaching a patch.
--8<---------------cut here---------------start------------->8---
csv2rec.c: In function 'field_cb':
csv2rec.c:262:30: warning: format '%d' expects argument of type 'int', but argum
ent 4 has type 'size_t' [-Wformat=]
ctx->lineno, ctx->num_field_names, ctx->num_fields
))
^
csv2rec.c:262:30: warning: format '%d' expects argument of type 'int', but argum
ent 5 has type 'size_t' [-Wformat=]
csv2rec.c:262:30: warning: format '%d' expects argument of type 'int', but argum
ent 6 has type 'size_t' [-Wformat=]
csv2rec.c:265:15: error: format not a string literal and no format arguments [-W
error=format-security]
fprintf (stderr, errmsg);
^
--8<---------------cut here---------------end--------------->8---
Regards,
--
Daiki Ueno
>From 090c51100809b4c62d9e53795a034792232dc2cf Mon Sep 17 00:00:00 2001
From: Daiki Ueno <address@hidden>
Date: Thu, 27 Mar 2014 19:12:42 +0900
Subject: [PATCH] utils: silence compiler warnings with -Wformat
---
utils/csv2rec.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/utils/csv2rec.c b/utils/csv2rec.c
index da38394..5b8806d 100644
--- a/utils/csv2rec.c
+++ b/utils/csv2rec.c
@@ -248,7 +248,6 @@ field_cb (void *s, size_t len, void *data)
{
if (ctx->num_fields > ctx->num_field_names)
{
- char *errmsg = NULL;
char *source = csv2rec_csv_file;
if (!source)
@@ -256,13 +255,10 @@ field_cb (void *s, size_t len, void *data)
source = "stdin";
}
- if (!asprintf (&errmsg,
- _("%s: %d: this line contains %d fields, but %d
header fields were read\n"),
- source,
- ctx->lineno, ctx->num_field_names,
ctx->num_fields))
- recutl_out_of_memory ();
-
- fprintf (stderr, errmsg);
+ fprintf (stderr,
+ _("%s: %lu: this line contains %lu fields, but %lu
header fields were read\n"),
+ source,
+ ctx->lineno, ctx->num_field_names, ctx->num_fields);
exit (EXIT_FAILURE);
}
field = rec_field_new (ctx->field_names[ctx->num_fields], str);
--
1.8.4.2
- [bug-recutils] 1.7: suppress -Wformat error,
Daiki Ueno <=