From: Pádraig Brady
Date: Thu, 18 May 2023 09:38:11 +0000 (+0100) Subject: build: avoid false -Wmaybe-uninitialized warnings X-Git-Tag: v9.4~130 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=800c86d5fa6ed32026e33d9db56739b0c696c40e;p=thirdparty%2Fcoreutils.git build: avoid false -Wmaybe-uninitialized warnings Allow easily building a debug build for example with: make CFLAGS='-O0 -ggdb' False -Wmaybe-uninitialized warnings hit in different places depending on the compiler passes used. These changes were tested with gcc 10.2.1, 12.2.1, and 13.1.1 like: for o in g s z fast 0 1 2 3; do make clean && make -j$(nproc) CFLAGS="-O$o" || break done * src/digest.c: Disable -Wmaybe-uninitialized that gives false positive here at -O0. * src/ln.c: Avoid -Wmaybe-uninitialized that gives false positive here at -O1. * src/pr.c: Likewise. * src/sort.c: Likewise. * src/tee.c: Avoid -Wmaybe-uninitialized that gives false positive here at -O3 on gcc 13.1.1 at least. * src/cp.c: Avoid -Wmaybe-uninitialized that gives false positive here at -Os on gcc 13.1.1 at least. * src/copy.c: Avoid -Wmaybe-uninitialized that gives false positive here at -Og on gcc 13.1.1 at least. * src/head.c: Likewise. * src/paste.c: Likewise. --- diff --git a/src/copy.c b/src/copy.c index 0dd059d2e4..6b2cf3b29a 100644 --- a/src/copy.c +++ b/src/copy.c @@ -1238,8 +1238,8 @@ copy_reg (char const *src_name, char const *dst_name, struct stat const *src_sb) { char *buf = NULL; - int dest_desc; - int dest_errno; + int dest_desc IF_LINT ( = -1); + int dest_errno IF_LINT ( = 0); int source_desc; mode_t src_mode = src_sb->st_mode; mode_t extra_permissions; diff --git a/src/cp.c b/src/cp.c index 619eb8260a..c952eb397a 100644 --- a/src/cp.c +++ b/src/cp.c @@ -441,7 +441,7 @@ make_dir_parents_private (char const *const_dir, size_t src_offset, while ((slash = strchr (slash, '/'))) { - struct dir_attr *new; + struct dir_attr *new IF_LINT ( = NULL); bool missing_dir; *slash = '\0'; diff --git a/src/digest.c b/src/digest.c index ab32968db7..6d9cc2a5b4 100644 --- a/src/digest.c +++ b/src/digest.c @@ -1125,6 +1125,9 @@ hex_equal (unsigned char const *hex_digest, unsigned char const *bin_buffer) return cnt == digest_bin_bytes; } +#if defined __GNUC__ && (__GNUC__ + (__GNUC_MINOR__ >= 7) > 4) +# pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif static bool digest_check (char const *checkfile_name) { diff --git a/src/head.c b/src/head.c index c9d3b0d050..f576a2200c 100644 --- a/src/head.c +++ b/src/head.c @@ -351,7 +351,7 @@ elide_tail_bytes_pipe (char const *filename, int fd, uintmax_t n_elide_0, bytes. Then, for each new buffer we read, also write an old one. */ bool eof = false; - size_t n_read; + size_t n_read IF_LINT ( = 0); bool buffered_enough; size_t i, i_next; char **b = NULL; diff --git a/src/ln.c b/src/ln.c index 1c3307cac9..bfdac0cd9c 100644 --- a/src/ln.c +++ b/src/ln.c @@ -473,7 +473,7 @@ main (int argc, char **argv) char const *backup_suffix = NULL; char *version_control_string = NULL; char const *target_directory = NULL; - int destdir_fd; + int destdir_fd IF_LINT ( = -1); bool no_target_directory = false; int n_files; char **file; diff --git a/src/paste.c b/src/paste.c index 5c194d8fe2..468ef3ab03 100644 --- a/src/paste.c +++ b/src/paste.c @@ -233,7 +233,7 @@ paste_parallel (size_t nfiles, char **fnamptr) for (size_t i = 0; i < nfiles && files_open; i++) { - int chr; /* Input character. */ + int chr IF_LINT ( = -1); /* Input character. */ int err; /* Input errno value. */ bool sometodo = false; /* Input chars to process. */ diff --git a/src/pr.c b/src/pr.c index 1c32e8c81d..6be5b1f33a 100644 --- a/src/pr.c +++ b/src/pr.c @@ -2428,7 +2428,7 @@ static bool read_line (COLUMN *p) { int c; - int chars; + int chars IF_LINT ( =0); int last_input_position; int j, k; COLUMN *q; diff --git a/src/sort.c b/src/sort.c index 8ca7a88c48..5aadc797b7 100644 --- a/src/sort.c +++ b/src/sort.c @@ -1045,7 +1045,7 @@ pipe_fork (int pipefds[2], size_t tries) struct tempnode *saved_temphead; int saved_errno; double wait_retry = 0.25; - pid_t pid; + pid_t pid IF_LINT ( = -1); struct cs_status cs; if (pipe2 (pipefds, O_CLOEXEC) < 0) diff --git a/src/tee.c b/src/tee.c index a1c0578162..27e83619e9 100644 --- a/src/tee.c +++ b/src/tee.c @@ -228,7 +228,7 @@ tee_files (int nfiles, char **files, bool pipe_check) { size_t n_outputs = 0; FILE **descriptors; - bool *out_pollable; + bool *out_pollable IF_LINT ( = NULL); char buffer[BUFSIZ]; ssize_t bytes_read = 0; int i;