diff options
| author | Pádraig Brady <P@draigBrady.com> | 2023-05-18 10:38:11 +0100 |
|---|---|---|
| committer | Pádraig Brady <P@draigBrady.com> | 2023-05-18 12:13:47 +0100 |
| commit | 800c86d5fa6ed32026e33d9db56739b0c696c40e (patch) | |
| tree | 588d1729df9adcdda3fbb5a701fef66ce75c3ae8 | |
| parent | build: gnulib: avoid false -Wstringop-overflow warning (diff) | |
| download | coreutils-800c86d5fa6ed32026e33d9db56739b0c696c40e.tar.gz coreutils-800c86d5fa6ed32026e33d9db56739b0c696c40e.zip | |
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.
| -rw-r--r-- | src/copy.c | 4 | ||||
| -rw-r--r-- | src/cp.c | 2 | ||||
| -rw-r--r-- | src/digest.c | 3 | ||||
| -rw-r--r-- | src/head.c | 2 | ||||
| -rw-r--r-- | src/ln.c | 2 | ||||
| -rw-r--r-- | src/paste.c | 2 | ||||
| -rw-r--r-- | src/pr.c | 2 | ||||
| -rw-r--r-- | src/sort.c | 2 | ||||
| -rw-r--r-- | src/tee.c | 2 |
9 files changed, 12 insertions, 9 deletions
diff --git a/src/copy.c b/src/copy.c index 0dd059d2e..6b2cf3b29 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; @@ -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 ab32968db..6d9cc2a5b 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 c9d3b0d05..f576a2200 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; @@ -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 5c194d8fe..468ef3ab0 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. */ @@ -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 8ca7a88c4..5aadc797b 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) @@ -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; |
