[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-idutils] bug#29204: 4 build fixes
From: |
Jim Meyering |
Subject: |
[bug-idutils] bug#29204: 4 build fixes |
Date: |
Tue, 07 Nov 2017 20:04:26 -0800 |
I've just pushed the following:
[PATCH 1/4] build: fix type-vs-format-string mismatches
[PATCH 2/4] build: address -Wimplicit-fallthrough= warnings
[PATCH 3/4] build: add die.h from coreutils
[PATCH 4/4] lid: fix invalid fallthrough after failed exec
see https://git.sv.gnu.org/cgit/idutils.git or the attached
>From e37cd40e6c3101e4fa79fee9262ae435045016e7 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Tue, 7 Nov 2017 09:29:02 -0800
Subject: [PATCH 1/4] build: fix type-vs-format-string mismatches
* libidu/idread.c (io_read): As above.
* libidu/idu-hash.c (hash_init, hash_print_stats): Likewise.
* libidu/idwrite.c (io_write): Likewise.
* libidu/scanners.c (ARGS): Likewise.
* libidu/walker.c (print_member_file, langs_excluded): Likewise.
* src/lid.c (main): Likewise.
* src/mkid.c (scan_files, report_statistics, summarize): Likewise.
---
libidu/idread.c | 2 +-
libidu/idu-hash.c | 8 ++++----
libidu/idwrite.c | 2 +-
libidu/scanners.c | 8 ++++----
libidu/walker.c | 4 ++--
src/lid.c | 2 +-
src/mkid.c | 26 +++++++++++++-------------
7 files changed, 26 insertions(+), 26 deletions(-)
diff --git a/libidu/idread.c b/libidu/idread.c
index a6a4b0e..7f34f76 100644
--- a/libidu/idread.c
+++ b/libidu/idread.c
@@ -187,7 +187,7 @@ io_read (FILE *input_FILE, void *addr, unsigned int size,
int io_type)
*(unsigned char *)addr = getc (input_FILE);
break;
default:
- error (EXIT_FAILURE, 0, _("unsupported size in io_read (): %d"),
size);
+ error (EXIT_FAILURE, 0, _("unsupported size in io_read (): %u"),
size);
}
}
else if (io_type == IO_TYPE_STR)
diff --git a/libidu/idu-hash.c b/libidu/idu-hash.c
index c22c02b..8c50a38 100644
--- a/libidu/idu-hash.c
+++ b/libidu/idu-hash.c
@@ -48,7 +48,7 @@ hash_init (struct hash_table* ht, unsigned long size,
ht->ht_empty_slots = ht->ht_size;
ht->ht_vec = xcalloc (ht->ht_size, sizeof(struct token *));
if (ht->ht_vec == 0)
- error (EXIT_FAILURE, 0, _("can't allocate %ld bytes for hash table: memory
exhausted"),
+ error (EXIT_FAILURE, 0, _("can't allocate %lu bytes for hash table: memory
exhausted"),
ht->ht_size * sizeof(struct token *));
ht->ht_capacity = ht->ht_size * 15 / 16; /* 93.75% loading factor */
ht->ht_fill = 0;
@@ -261,10 +261,10 @@ hash_rehash (struct hash_table* ht)
void
hash_print_stats (struct hash_table const *ht, FILE *out_FILE)
{
- fprintf (out_FILE, _("Load=%ld/%ld=%.0f%%, "), ht->ht_fill, ht->ht_size,
+ fprintf (out_FILE, _("Load=%lu/%lu=%.0f%%, "), ht->ht_fill, ht->ht_size,
100.0 * (double) ht->ht_fill / (double) ht->ht_size);
- fprintf (out_FILE, _("Rehash=%d, "), ht->ht_rehashes);
- fprintf (out_FILE, _("Collisions=%ld/%ld=%.0f%%"), ht->ht_collisions,
ht->ht_lookups,
+ fprintf (out_FILE, _("Rehash=%u, "), ht->ht_rehashes);
+ fprintf (out_FILE, _("Collisions=%lu/%lu=%.0f%%"), ht->ht_collisions,
ht->ht_lookups,
(ht->ht_lookups
? (100.0 * (double) ht->ht_collisions / (double) ht->ht_lookups)
: 0));
diff --git a/libidu/idwrite.c b/libidu/idwrite.c
index 9c1f083..0dcdd20 100644
--- a/libidu/idwrite.c
+++ b/libidu/idwrite.c
@@ -155,7 +155,7 @@ io_write (FILE *output_FILE, void *addr, unsigned int size,
int io_type)
putc (*(unsigned char *)addr, output_FILE);
break;
default:
- error (EXIT_FAILURE, 0, _("unsupported size in io_write (): %d"),
size);
+ error (EXIT_FAILURE, 0, _("unsupported size in io_write (): %u"),
size);
}
}
else if (io_type == IO_TYPE_STR)
diff --git a/libidu/scanners.c b/libidu/scanners.c
index 26047eb..03691ea 100644
--- a/libidu/scanners.c
+++ b/libidu/scanners.c
@@ -752,7 +752,7 @@ next:
if (isprint (c))
fprintf (stderr, _("junk: `%c'"), c);
else
- fprintf (stderr, _("junk: `\\%03o'"), c);
+ fprintf (stderr, _("junk: `\\%03o'"), (unsigned) c);
}
ungetc (c, in_FILE);
*flags |= TOK_LITERAL;
@@ -1021,7 +1021,7 @@ next:
if (isprint (c))
fprintf (stderr, _("junk: `%c'"), c);
else
- fprintf (stderr, _("junk: `\\%03o'"), c);
+ fprintf (stderr, _("junk: `\\%03o'"), (unsigned) c);
goto next;
}
@@ -1224,7 +1224,7 @@ top:
if (isprint (c))
fprintf (stderr, _("junk: `%c'"), c);
else
- fprintf (stderr, _("junk: `\\%03o'"), c);
+ fprintf (stderr, _("junk: `\\%03o'"), (unsigned) c);
goto top;
}
@@ -1494,7 +1494,7 @@ top:
if (isprint (c))
fprintf (stderr, _("junk: `%c'"), c);
else
- fprintf (stderr, _("junk: `\\%03o'"), c);
+ fprintf (stderr, _("junk: `\\%03o'"), (unsigned) c);
goto top;
}
diff --git a/libidu/walker.c b/libidu/walker.c
index 0659237..e332305 100644
--- a/libidu/walker.c
+++ b/libidu/walker.c
@@ -467,7 +467,7 @@ print_member_file (struct member_file *member)
{
char *file_name = alloca (PATH_MAX);
absolute_file_name (file_name, member->mf_link);
- printf ("%ld: %s: %s\n", idh.idh_member_file_table.ht_fill - 1,
+ printf ("%lu: %s: %s\n", idh.idh_member_file_table.ht_fill - 1,
member->mf_lang_args->la_language->lg_name, file_name);
}
@@ -477,7 +477,7 @@ print_member_file (struct member_file *member)
static char **langs_included;
static char **langs_excluded;
-static int
+static int _GL_ATTRIBUTE_PURE
lang_wanted (char const *lang_name)
{
if (langs_excluded)
diff --git a/src/lid.c b/src/lid.c
index b5282d3..7cdc821 100644
--- a/src/lid.c
+++ b/src/lid.c
@@ -456,7 +456,7 @@ main (int argc, char **argv)
if (ambiguous_prefix_length)
{
if (!query_ambiguous_prefix (ambiguous_prefix_length, report_function))
- fprintf (stderr, _("All identifiers are non-ambiguous within the first
%d characters\n"),
+ fprintf (stderr, _("All identifiers are non-ambiguous within the first
%u characters\n"),
ambiguous_prefix_length);
}
else
diff --git a/src/mkid.c b/src/mkid.c
index d9a351e..51a5a35 100644
--- a/src/mkid.c
+++ b/src/mkid.c
@@ -517,7 +517,7 @@ scan_files (struct idhead const *idhp)
if (verbose_flag) {
char offstr[INT_BUFSIZE_BOUND(off_t)];
- printf ("files=%ld, largest=%s, slots=%lu\n",
+ printf ("files=%lu, largest=%s, slots=%lu\n",
idhp->idh_member_file_table.ht_fill,
offtostr(largest_member_file, offstr),
token_table.ht_size);
@@ -645,25 +645,25 @@ scan_member_file_1 (get_token_func_t get_token, void
const *args, FILE *source_F
static void
report_statistics (void)
{
- printf (_("Name=%ld, "), name_tokens);
- printf (_("Number=%ld, "), number_tokens);
- printf (_("String=%ld, "), string_tokens);
- printf (_("Literal=%ld, "), literal_tokens);
- printf (_("Comment=%ld\n"), comment_tokens);
-
- printf (_("Files=%ld, "), idh.idh_files);
- printf (_("Tokens=%ld, "), occurrences);
- printf (_("Bytes=%ld Kb, "), input_chars / 1024);
+ printf (_("Name=%lu, "), name_tokens);
+ printf (_("Number=%lu, "), number_tokens);
+ printf (_("String=%lu, "), string_tokens);
+ printf (_("Literal=%lu, "), literal_tokens);
+ printf (_("Comment=%lu\n"), comment_tokens);
+
+ printf (_("Files=%lu, "), idh.idh_files);
+ printf (_("Tokens=%lu, "), occurrences);
+ printf (_("Bytes=%lu Kb, "), input_chars / 1024);
printf (_("Heap=%llu+%llu Kb, "),
(unsigned long long) ((char *) heap_after_scan
- (char *) heap_after_walk) / 1024,
(unsigned long long) ((char *) heap_after_walk
- (char *) heap_initial) / 1024);
- printf (_("Output=%ld (%ld tok, %ld hit)\n"),
+ printf (_("Output=%lu (%lu tok, %lu hit)\n"),
output_length, tokens_length, hits_length);
hash_print_stats (&token_table, stdout);
- printf (_(", Freq=%ld/%ld=%.2f\n"), occurrences, token_table.ht_fill,
+ printf (_(", Freq=%lu/%lu=%.2f\n"), occurrences, token_table.ht_fill,
(double) occurrences / (double) token_table.ht_fill);
}
@@ -863,7 +863,7 @@ summarize (void)
unsigned long init_size = INIT_TOKENS_SIZE (summary->sum_level);
if (verbose_flag)
- printf (_("level %d: %ld/%ld = %.0f%%\n"),
+ printf (_("level %d: %lu/%lu = %.0f%%\n"),
summary->sum_level, count, init_size,
100.0 * (double) count / (double) init_size);
--
2.14.1.729.g59c0ea183
>From b4f603f45f1a964faa01440327f970c96e45297a Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Tue, 7 Nov 2017 09:31:18 -0800
Subject: [PATCH 2/4] build: address -Wimplicit-fallthrough= warnings
* src/mkid.c (FALLTHROUGH): Define.
(main): Mark two case statements as such.
---
src/mkid.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/src/mkid.c b/src/mkid.c
index 51a5a35..ca9cfb7 100644
--- a/src/mkid.c
+++ b/src/mkid.c
@@ -45,6 +45,14 @@
#include "scanners.h"
#include "iduglobal.h"
+#ifndef FALLTHROUGH
+# if __GNUC__ < 7
+# define FALLTHROUGH ((void) 0)
+# else
+# define FALLTHROUGH __attribute__ ((__fallthrough__))
+# endif
+#endif
+
struct summary
{
struct token **sum_tokens;
@@ -275,8 +283,10 @@ main (int argc, char **argv)
case 'V':
walker_verbose_flag = 1;
+ FALLTHROUGH;
case 'v':
verbose_flag = 1;
+ FALLTHROUGH;
case 's':
statistics_flag = 1;
break;
--
2.14.1.729.g59c0ea183
>From 25632036e479b293a0574dbc6b48930336d79bf2 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Tue, 7 Nov 2017 09:33:33 -0800
Subject: [PATCH 3/4] build: add die.h from coreutils
* src/die.h: New file. From coreutils.
* src/Makefile.am (noinst_HEADERS): Add it.
---
src/Makefile.am | 2 +-
src/die.h | 31 +++++++++++++++++++++++++++++++
2 files changed, 32 insertions(+), 1 deletion(-)
create mode 100644 src/die.h
diff --git a/src/Makefile.am b/src/Makefile.am
index 8aa82dd..4ce8920 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,7 +1,7 @@
bin_PROGRAMS = mkid lid fid fnid xtokid aid eid gid
dist_bin_SCRIPTS = defid
-noinst_HEADERS = lid.h
+noinst_HEADERS = die.h lid.h
aid_SOURCES = lid.c lid-aid.c
eid_SOURCES = lid.c lid-eid.c
gid_SOURCES = lid.c lid-gid.c
diff --git a/src/die.h b/src/die.h
new file mode 100644
index 0000000..8835d80
--- /dev/null
+++ b/src/die.h
@@ -0,0 +1,31 @@
+/* Report an error and exit.
+ Copyright 2016-2017 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
+ 02110-1301, USA. */
+
+#ifndef DIE_H
+# define DIE_H
+
+# include <error.h>
+# include <stdbool.h>
+# include <verify.h>
+
+/* Like 'error (STATUS, ...)', except STATUS must be a nonzero constant.
+ This may pacify the compiler or help it generate better code. */
+# define die(status, ...) \
+ verify_expr (status, (error (status, __VA_ARGS__), assume (false)))
+
+#endif /* DIE_H */
--
2.14.1.729.g59c0ea183
>From a0b22c00854ab6953b035e871a95847786699960 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Tue, 7 Nov 2017 09:41:55 -0800
Subject: [PATCH 4/4] lid: fix invalid fallthrough after failed exec
gcc's -Wimplicit-fallthrough detected a bug: lid would
fall through it's "case 0" after a failed execvp.
* src/lid.c: Include "die.h".
Use "die (EXIT_FAILURE,...", not "error (0,..."
---
src/lid.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/lid.c b/src/lid.c
index 7cdc821..1f419e6 100644
--- a/src/lid.c
+++ b/src/lid.c
@@ -38,6 +38,7 @@
#include <error.h>
#include "closeout.h"
+#include "die.h"
#include "xnls.h"
#include "idfile.h"
#include "iduglobal.h"
@@ -784,7 +785,7 @@ editit:
argv[i] = 0;
execvp (editor_argv[0], argv);
- error (0, errno, _("can't exec `%s'"), editor_argv[0]);
+ die (EXIT_FAILURE, errno, _("can't exec `%s'"), editor_argv[0]);
}
default:
--
2.14.1.729.g59c0ea183
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [bug-idutils] bug#29204: 4 build fixes,
Jim Meyering <=