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.
This commit is contained in:
Pádraig Brady committed 2023-05-18 12:13:47 +01:00
1 parent aed3b8190a
commit 800c86d5fa
9 files changed
+12 -9

No files matched your search

+2 -2
View File
@@ -1238,8 +1238,8 @@ copy_reg (char const *src_name, char const *dst_name,
struct stat const *src_sb) struct stat const *src_sb)
{ {
char *buf = NULL; char *buf = NULL;
int dest_desc; int dest_desc IF_LINT ( = -1);
int dest_errno; int dest_errno IF_LINT ( = 0);
int source_desc; int source_desc;
mode_t src_mode = src_sb->st_mode; mode_t src_mode = src_sb->st_mode;
mode_t extra_permissions; mode_t extra_permissions;
+1 -1
View File
@@ -441,7 +441,7 @@ make_dir_parents_private (char const *const_dir, size_t src_offset,
while ((slash = strchr (slash, '/'))) while ((slash = strchr (slash, '/')))
{ {
struct dir_attr *new; struct dir_attr *new IF_LINT ( = NULL);
bool missing_dir; bool missing_dir;
*slash = '\0'; *slash = '\0';
+3
View File
@@ -1125,6 +1125,9 @@ hex_equal (unsigned char const *hex_digest, unsigned char const *bin_buffer)
return cnt == digest_bin_bytes; return cnt == digest_bin_bytes;
} }
#if defined __GNUC__ && (__GNUC__ + (__GNUC_MINOR__ >= 7) > 4)
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
static bool static bool
digest_check (char const *checkfile_name) digest_check (char const *checkfile_name)
{ {
+1 -1
View File
@@ -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. */ bytes. Then, for each new buffer we read, also write an old one. */
bool eof = false; bool eof = false;
size_t n_read; size_t n_read IF_LINT ( = 0);
bool buffered_enough; bool buffered_enough;
size_t i, i_next; size_t i, i_next;
char **b = NULL; char **b = NULL;
+1 -1
View File
@@ -473,7 +473,7 @@ main (int argc, char **argv)
char const *backup_suffix = NULL; char const *backup_suffix = NULL;
char *version_control_string = NULL; char *version_control_string = NULL;
char const *target_directory = NULL; char const *target_directory = NULL;
int destdir_fd; int destdir_fd IF_LINT ( = -1);
bool no_target_directory = false; bool no_target_directory = false;
int n_files; int n_files;
char **file; char **file;
+1 -1
View File
@@ -233,7 +233,7 @@ paste_parallel (size_t nfiles, char **fnamptr)
for (size_t i = 0; i < nfiles && files_open; i++) 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. */ int err; /* Input errno value. */
bool sometodo = false; /* Input chars to process. */ bool sometodo = false; /* Input chars to process. */
+1 -1
View File
@@ -2428,7 +2428,7 @@ static bool
read_line (COLUMN *p) read_line (COLUMN *p)
{ {
int c; int c;
int chars; int chars IF_LINT ( =0);
int last_input_position; int last_input_position;
int j, k; int j, k;
COLUMN *q; COLUMN *q;
+1 -1
View File
@@ -1045,7 +1045,7 @@ pipe_fork (int pipefds[2], size_t tries)
struct tempnode *saved_temphead; struct tempnode *saved_temphead;
int saved_errno; int saved_errno;
double wait_retry = 0.25; double wait_retry = 0.25;
pid_t pid; pid_t pid IF_LINT ( = -1);
struct cs_status cs; struct cs_status cs;
if (pipe2 (pipefds, O_CLOEXEC) < 0) if (pipe2 (pipefds, O_CLOEXEC) < 0)
+1 -1
View File
@@ -228,7 +228,7 @@ tee_files (int nfiles, char **files, bool pipe_check)
{ {
size_t n_outputs = 0; size_t n_outputs = 0;
FILE **descriptors; FILE **descriptors;
bool *out_pollable; bool *out_pollable IF_LINT ( = NULL);
char buffer[BUFSIZ]; char buffer[BUFSIZ];
ssize_t bytes_read = 0; ssize_t bytes_read = 0;
int i; int i;