compile with -Dlint to enable optional initialization and cleanup code
Upstream suggests to build with -Dlint for static analyzers: https://lists.gnu.org/archive/html/coreutils/2018-06/msg00110.html ... and even for production binary RPMs: https://lists.gnu.org/archive/html/bug-gnulib/2020-05/msg00130.html There is currently no measurable performance drop or other known downside.
This commit is contained in:
parent
bce50ab523
commit
1f6e0df263
@ -1,364 +0,0 @@
|
||||
From e6df4c3b75bbaf464fc5475a4bdc392ab500670b Mon Sep 17 00:00:00 2001
|
||||
From: Kamil Dudka <kdudka@redhat.com>
|
||||
Date: Thu, 5 Mar 2020 17:37:12 +0100
|
||||
Subject: [PATCH] do not use IF_LINT for initialization of scalar variables
|
||||
|
||||
It triggers false positives in compilers and static analyzers
|
||||
for no real benefit.
|
||||
---
|
||||
src/chcon.c | 2 +-
|
||||
src/chmod.c | 4 ++--
|
||||
src/copy.c | 4 ++--
|
||||
src/cp.c | 2 +-
|
||||
src/cut.c | 2 +-
|
||||
src/df.c | 2 +-
|
||||
src/expand.c | 2 +-
|
||||
src/expr.c | 2 +-
|
||||
src/ls.c | 2 +-
|
||||
src/md5sum.c | 4 ++--
|
||||
src/od.c | 4 ++--
|
||||
src/paste.c | 4 ++--
|
||||
src/pr.c | 2 +-
|
||||
src/shred.c | 4 ++--
|
||||
src/sort.c | 14 +++++++-------
|
||||
src/split.c | 2 +-
|
||||
src/truncate.c | 2 +-
|
||||
src/unexpand.c | 4 ++--
|
||||
src/uniq.c | 4 ++--
|
||||
src/who.c | 2 +-
|
||||
20 files changed, 34 insertions(+), 34 deletions(-)
|
||||
|
||||
diff --git a/src/chcon.c b/src/chcon.c
|
||||
index 724ec9b..c1cf4c4 100644
|
||||
--- a/src/chcon.c
|
||||
+++ b/src/chcon.c
|
||||
@@ -142,7 +142,7 @@ static int
|
||||
change_file_context (int fd, char const *file)
|
||||
{
|
||||
char *file_context = NULL;
|
||||
- context_t context IF_LINT (= 0);
|
||||
+ context_t context = 0;
|
||||
char const * context_string;
|
||||
int errors = 0;
|
||||
|
||||
diff --git a/src/chmod.c b/src/chmod.c
|
||||
index ec91534..a71a43c 100644
|
||||
--- a/src/chmod.c
|
||||
+++ b/src/chmod.c
|
||||
@@ -190,8 +190,8 @@ process_file (FTS *fts, FTSENT *ent)
|
||||
char const *file_full_name = ent->fts_path;
|
||||
char const *file = ent->fts_accpath;
|
||||
const struct stat *file_stats = ent->fts_statp;
|
||||
- mode_t old_mode IF_LINT ( = 0);
|
||||
- mode_t new_mode IF_LINT ( = 0);
|
||||
+ mode_t old_mode = 0;
|
||||
+ mode_t new_mode = 0;
|
||||
bool ok = true;
|
||||
bool chmod_succeeded = false;
|
||||
|
||||
diff --git a/src/copy.c b/src/copy.c
|
||||
index 6e5efc7..bb80038 100644
|
||||
--- a/src/copy.c
|
||||
+++ b/src/copy.c
|
||||
@@ -1889,8 +1889,8 @@ copy_internal (char const *src_name, char const *dst_name,
|
||||
{
|
||||
struct stat src_sb;
|
||||
struct stat dst_sb;
|
||||
- mode_t src_mode IF_LINT ( = 0);
|
||||
- mode_t dst_mode IF_LINT ( = 0);
|
||||
+ mode_t src_mode = 0;
|
||||
+ mode_t dst_mode = 0;
|
||||
mode_t dst_mode_bits;
|
||||
mode_t omitted_permissions;
|
||||
bool restore_dst_mode = false;
|
||||
diff --git a/src/cp.c b/src/cp.c
|
||||
index 0193df8..609adcf 100644
|
||||
--- a/src/cp.c
|
||||
+++ b/src/cp.c
|
||||
@@ -403,7 +403,7 @@ make_dir_parents_private (char const *const_dir, size_t src_offset,
|
||||
slash++;
|
||||
while ((slash = strchr (slash, '/')))
|
||||
{
|
||||
- struct dir_attr *new IF_LINT ( = NULL);
|
||||
+ struct dir_attr *new = NULL;
|
||||
bool missing_dir;
|
||||
|
||||
*slash = '\0';
|
||||
diff --git a/src/cut.c b/src/cut.c
|
||||
index 35ab5fc..685ba8d 100644
|
||||
--- a/src/cut.c
|
||||
+++ b/src/cut.c
|
||||
@@ -835,7 +835,7 @@ main (int argc, char **argv)
|
||||
int optc;
|
||||
bool ok;
|
||||
bool delim_specified = false;
|
||||
- char *spec_list_string IF_LINT ( = NULL);
|
||||
+ char *spec_list_string = NULL;
|
||||
char mbdelim[MB_LEN_MAX + 1];
|
||||
|
||||
initialize_main (&argc, &argv);
|
||||
diff --git a/src/df.c b/src/df.c
|
||||
index 7e01839..8af1d14 100644
|
||||
--- a/src/df.c
|
||||
+++ b/src/df.c
|
||||
@@ -1588,7 +1588,7 @@ field names are: 'source', 'fstype', 'itotal', 'iused', 'iavail', 'ipcent',\n\
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
- struct stat *stats IF_LINT ( = 0);
|
||||
+ struct stat *stats = 0;
|
||||
|
||||
initialize_main (&argc, &argv);
|
||||
set_program_name (argv[0]);
|
||||
diff --git a/src/expand.c b/src/expand.c
|
||||
index bf61aff..cc9d4cd 100644
|
||||
--- a/src/expand.c
|
||||
+++ b/src/expand.c
|
||||
@@ -190,7 +190,7 @@ expand (void)
|
||||
{
|
||||
/* Column the next input tab stop is on. */
|
||||
uintmax_t next_tab_column;
|
||||
- bool last_tab IF_LINT (=0);
|
||||
+ bool last_tab = 0;
|
||||
|
||||
next_tab_column = get_next_tab_column (column, &tab_index,
|
||||
&last_tab);
|
||||
diff --git a/src/expr.c b/src/expr.c
|
||||
index e134872..a49d37c 100644
|
||||
--- a/src/expr.c
|
||||
+++ b/src/expr.c
|
||||
@@ -690,7 +690,7 @@ trace (fxn)
|
||||
static VALUE *
|
||||
docolon (VALUE *sv, VALUE *pv)
|
||||
{
|
||||
- VALUE *v IF_LINT ( = NULL);
|
||||
+ VALUE *v = NULL;
|
||||
const char *errmsg;
|
||||
struct re_pattern_buffer re_buffer;
|
||||
char fastmap[UCHAR_MAX + 1];
|
||||
diff --git a/src/ls.c b/src/ls.c
|
||||
index 64ecf40..cc61400 100644
|
||||
--- a/src/ls.c
|
||||
+++ b/src/ls.c
|
||||
@@ -4429,7 +4429,7 @@ quote_name_buf (char **inbuf, size_t bufsize, char *name,
|
||||
int needs_general_quoting, size_t *width, bool *pad)
|
||||
{
|
||||
char *buf = *inbuf;
|
||||
- size_t displayed_width IF_LINT ( = 0);
|
||||
+ size_t displayed_width = 0;
|
||||
size_t len = 0;
|
||||
bool quoted;
|
||||
|
||||
diff --git a/src/md5sum.c b/src/md5sum.c
|
||||
index 447a005..91b9a9e 100644
|
||||
--- a/src/md5sum.c
|
||||
+++ b/src/md5sum.c
|
||||
@@ -687,9 +687,9 @@ digest_check (const char *checkfile_name)
|
||||
line_chars_allocated = 0;
|
||||
do
|
||||
{
|
||||
- char *filename IF_LINT ( = NULL);
|
||||
+ char *filename = NULL;
|
||||
int binary;
|
||||
- unsigned char *hex_digest IF_LINT ( = NULL);
|
||||
+ unsigned char *hex_digest = NULL;
|
||||
ssize_t line_length;
|
||||
|
||||
++line_number;
|
||||
diff --git a/src/od.c b/src/od.c
|
||||
index 200bc16..7482bb5 100644
|
||||
--- a/src/od.c
|
||||
+++ b/src/od.c
|
||||
@@ -1570,7 +1570,7 @@ main (int argc, char **argv)
|
||||
int n_files;
|
||||
size_t i;
|
||||
int l_c_m;
|
||||
- size_t desired_width IF_LINT ( = 0);
|
||||
+ size_t desired_width = 0;
|
||||
bool modern = false;
|
||||
bool width_specified = false;
|
||||
bool ok = true;
|
||||
@@ -1579,7 +1579,7 @@ main (int argc, char **argv)
|
||||
|
||||
/* The old-style 'pseudo starting address' to be printed in parentheses
|
||||
after any true address. */
|
||||
- uintmax_t pseudo_start IF_LINT ( = 0);
|
||||
+ uintmax_t pseudo_start = 0;
|
||||
|
||||
initialize_main (&argc, &argv);
|
||||
set_program_name (argv[0]);
|
||||
diff --git a/src/paste.c b/src/paste.c
|
||||
index 9f401c9..6dd3a4e 100644
|
||||
--- a/src/paste.c
|
||||
+++ b/src/paste.c
|
||||
@@ -234,8 +234,8 @@ paste_parallel (size_t nfiles, char **fnamptr)
|
||||
|
||||
for (size_t i = 0; i < nfiles && files_open; i++)
|
||||
{
|
||||
- int chr IF_LINT ( = 0); /* Input character. */
|
||||
- int err IF_LINT ( = 0); /* Input errno value. */
|
||||
+ int chr = 0; /* Input character. */
|
||||
+ int err = 0; /* Input errno value. */
|
||||
bool sometodo = false; /* Input chars to process. */
|
||||
|
||||
if (fileptr[i])
|
||||
diff --git a/src/pr.c b/src/pr.c
|
||||
index 6374a7f..3ac3c03 100644
|
||||
--- a/src/pr.c
|
||||
+++ b/src/pr.c
|
||||
@@ -2606,7 +2606,7 @@ static bool
|
||||
read_line (COLUMN *p)
|
||||
{
|
||||
int c;
|
||||
- int chars IF_LINT ( = 0);
|
||||
+ int chars = 0;
|
||||
int last_input_position;
|
||||
int j, k;
|
||||
COLUMN *q;
|
||||
diff --git a/src/shred.c b/src/shred.c
|
||||
index fbbeddf..e9a6414 100644
|
||||
--- a/src/shred.c
|
||||
+++ b/src/shred.c
|
||||
@@ -399,7 +399,7 @@ dopass (int fd, struct stat const *st, char const *qname, off_t *sizep,
|
||||
{
|
||||
off_t size = *sizep;
|
||||
off_t offset; /* Current file position */
|
||||
- time_t thresh IF_LINT ( = 0); /* Time to maybe print next status update */
|
||||
+ time_t thresh = 0; /* Time to maybe print next status update */
|
||||
time_t now = 0; /* Current time */
|
||||
size_t lim; /* Amount of data to try writing */
|
||||
size_t soff; /* Offset into buffer for next write */
|
||||
@@ -424,7 +424,7 @@ dopass (int fd, struct stat const *st, char const *qname, off_t *sizep,
|
||||
|
||||
/* Printable previous offset into the file */
|
||||
char previous_offset_buf[LONGEST_HUMAN_READABLE + 1];
|
||||
- char const *previous_human_offset IF_LINT ( = 0);
|
||||
+ char const *previous_human_offset = 0;
|
||||
|
||||
/* As a performance tweak, avoid direct I/O for small sizes,
|
||||
as it's just a performance rather then security consideration,
|
||||
diff --git a/src/sort.c b/src/sort.c
|
||||
index 8e1533e..cb494f4 100644
|
||||
--- a/src/sort.c
|
||||
+++ b/src/sort.c
|
||||
@@ -1114,7 +1114,7 @@ pipe_fork (int pipefds[2], size_t tries)
|
||||
struct tempnode *saved_temphead;
|
||||
int saved_errno;
|
||||
double wait_retry = 0.25;
|
||||
- pid_t pid IF_LINT ( = -1);
|
||||
+ pid_t pid = -1;
|
||||
struct cs_status cs;
|
||||
|
||||
if (pipe2 (pipefds, O_CLOEXEC) < 0)
|
||||
@@ -2999,9 +2999,9 @@ keycompare_uni (const struct line *a, const struct line *b)
|
||||
size_t tlena;
|
||||
size_t tlenb;
|
||||
|
||||
- char enda IF_LINT (= 0);
|
||||
- char endb IF_LINT (= 0);
|
||||
- void *allocated IF_LINT (= NULL);
|
||||
+ char enda = 0;
|
||||
+ char endb = 0;
|
||||
+ void *allocated = NULL;
|
||||
char stackbuf[4000];
|
||||
|
||||
if (ignore || translate)
|
||||
@@ -3267,8 +3267,8 @@ keycompare_mb (const struct line *a, const struct line *b)
|
||||
size_t lena = lima <= texta ? 0 : lima - texta;
|
||||
size_t lenb = limb <= textb ? 0 : limb - textb;
|
||||
|
||||
- char enda IF_LINT (= 0);
|
||||
- char endb IF_LINT (= 0);
|
||||
+ char enda = 0;
|
||||
+ char endb = 0;
|
||||
|
||||
char const *translate = key->translate;
|
||||
bool const *ignore = key->ignore;
|
||||
@@ -4551,7 +4551,7 @@ sort (char *const *files, size_t nfiles, char const *output_file,
|
||||
size_t nthreads)
|
||||
{
|
||||
struct buffer buf;
|
||||
- IF_LINT (buf.buf = NULL);
|
||||
+ buf.buf = NULL;
|
||||
size_t ntemps = 0;
|
||||
bool output_file_created = false;
|
||||
|
||||
diff --git a/src/split.c b/src/split.c
|
||||
index 09e610b..aefa4a7 100644
|
||||
--- a/src/split.c
|
||||
+++ b/src/split.c
|
||||
@@ -1132,7 +1132,7 @@ lines_rr (uintmax_t k, uintmax_t n, char *buf, size_t bufsize)
|
||||
bool wrote = false;
|
||||
bool file_limit;
|
||||
size_t i_file;
|
||||
- of_t *files IF_LINT (= NULL);
|
||||
+ of_t *files = NULL;
|
||||
uintmax_t line_no;
|
||||
|
||||
if (k)
|
||||
diff --git a/src/truncate.c b/src/truncate.c
|
||||
index 91d9674..76e224f 100644
|
||||
--- a/src/truncate.c
|
||||
+++ b/src/truncate.c
|
||||
@@ -203,7 +203,7 @@ main (int argc, char **argv)
|
||||
{
|
||||
bool got_size = false;
|
||||
bool errors = false;
|
||||
- off_t size IF_LINT ( = 0);
|
||||
+ off_t size = 0;
|
||||
off_t rsize = -1;
|
||||
rel_mode_t rel_mode = rm_abs;
|
||||
int c, fd = -1, oflags;
|
||||
diff --git a/src/unexpand.c b/src/unexpand.c
|
||||
index 7d5dd64..b0e0ab3 100644
|
||||
--- a/src/unexpand.c
|
||||
+++ b/src/unexpand.c
|
||||
@@ -225,7 +225,7 @@ unexpand (void)
|
||||
|
||||
if (blank)
|
||||
{
|
||||
- bool last_tab IF_LINT (=0);
|
||||
+ bool last_tab = 0;
|
||||
|
||||
next_tab_column = get_next_tab_column (column, &tab_index,
|
||||
&last_tab);
|
||||
@@ -320,7 +320,7 @@ int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
bool have_tabval = false;
|
||||
- uintmax_t tabval IF_LINT ( = 0);
|
||||
+ uintmax_t tabval = 0;
|
||||
int c;
|
||||
|
||||
/* If true, cancel the effect of any -a (explicit or implicit in -t),
|
||||
diff --git a/src/uniq.c b/src/uniq.c
|
||||
index ba3c4ce..fa0fc5c 100644
|
||||
--- a/src/uniq.c
|
||||
+++ b/src/uniq.c
|
||||
@@ -456,8 +456,8 @@ check_file (const char *infile, const char *outfile, char delimiter)
|
||||
*/
|
||||
if (output_unique && output_first_repeated && countmode == count_none)
|
||||
{
|
||||
- char *prevfield IF_LINT ( = NULL);
|
||||
- size_t prevlen IF_LINT ( = 0);
|
||||
+ char *prevfield = NULL;
|
||||
+ size_t prevlen = 0;
|
||||
bool first_group_printed = false;
|
||||
|
||||
while (!feof (stdin))
|
||||
diff --git a/src/who.c b/src/who.c
|
||||
index abf3bc7..401ad0f 100644
|
||||
--- a/src/who.c
|
||||
+++ b/src/who.c
|
||||
@@ -568,7 +568,7 @@ print_heading (void)
|
||||
static void
|
||||
scan_entries (size_t n, const STRUCT_UTMP *utmp_buf)
|
||||
{
|
||||
- char *ttyname_b IF_LINT ( = NULL);
|
||||
+ char *ttyname_b = NULL;
|
||||
time_t boottime = TYPE_MINIMUM (time_t);
|
||||
|
||||
if (include_heading)
|
||||
--
|
||||
2.21.1
|
||||
|
@ -1,7 +1,7 @@
|
||||
Summary: A set of basic GNU tools commonly used in shell scripts
|
||||
Name: coreutils
|
||||
Version: 8.32
|
||||
Release: 5%{?dist}
|
||||
Release: 6%{?dist}
|
||||
License: GPLv3+
|
||||
Url: https://www.gnu.org/software/coreutils/
|
||||
Source0: https://ftp.gnu.org/gnu/%{name}/%{name}-%{version}.tar.xz
|
||||
@ -63,9 +63,6 @@ Patch908: coreutils-getgrouplist.patch
|
||||
#(upstream did some SELinux implementation unlike with RedHat patch)
|
||||
Patch950: coreutils-selinux.patch
|
||||
|
||||
# do not use IF_LINT for initialization of scalar variables
|
||||
Patch951: coreutils-8.32-if-lint.patch
|
||||
|
||||
Conflicts: filesystem < 3
|
||||
# To avoid clobbering installs
|
||||
Conflicts: coreutils-single
|
||||
@ -165,6 +162,13 @@ autoreconf -fiv
|
||||
%build
|
||||
export CFLAGS="$RPM_OPT_FLAGS -fno-strict-aliasing -fpic"
|
||||
|
||||
# Upstream suggests to build with -Dlint for static analyzers:
|
||||
# https://lists.gnu.org/archive/html/coreutils/2018-06/msg00110.html
|
||||
# ... and even for production binary RPMs:
|
||||
# https://lists.gnu.org/archive/html/bug-gnulib/2020-05/msg00130.html
|
||||
# There is currently no measurable performance drop or other known downside.
|
||||
CFLAGS="$CFLAGS -Dlint"
|
||||
|
||||
# make mknod work again in chroot without /proc being mounted (#1811038)
|
||||
export ac_cv_func_lchmod="no"
|
||||
|
||||
@ -262,6 +266,9 @@ rm -f $RPM_BUILD_ROOT%{_infodir}/dir
|
||||
%license COPYING
|
||||
|
||||
%changelog
|
||||
* Fri May 15 2020 Kamil Dudka <kdudka@redhat.com> - 8.32-6
|
||||
- compile with -Dlint to enable optional initialization and cleanup code
|
||||
|
||||
* Thu Apr 23 2020 Kamil Dudka <kdudka@redhat.com> - 8.32-5
|
||||
- du: simplify leaf optimization for XFS (#1823247)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user