The first bug in that output:
cc1: warning: function may return address of local variable
[-Wreturn-local-addr]
lib/careadlinkat.c:73:8: note: declared here
73 | char stack_buf[1024];
| ^~~~~~~~~
This is a false alarm. I installed the attached patch to pacify GCC (if you
build with GCC_LINT).
But perhaps I jumped the gun here - the workaround is reasonably awful, so
perhaps it'd be better to disable -Wreturn-local-addr instead, at least for this
compilation unit.
lib/diffseq.h:432:36: warning: 'bxbest' may be used uninitialized in this
function [-Wmaybe-uninitialized]
432 | part->ymid = bxybest - bxbest;
| ~~~~~~~~^~~~~~~~
This false alarm is because the program was built without GCC_LINT being
defined. If you build with -DGCC_LINT the false alarm should go away. (Maybe
some others will go away too, at least careadlinkat is like this now....) This
is what Emacs etc. do. Perhaps this should be moved to the manywarnings module?
Speaking of which, manywarnings.m4 should be updated for GCC 10, mostly for the
-fanalyze warnings. I installed the second attached patch to do that.
>From 26f82c14e89f71ab1c2e6a811981ecc742b044e5 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Sat, 9 May 2020 18:01:59 -0700
Subject: [PATCH 1/2] careadlinkat: pacify -Wreturn-local-addr
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* lib/careadlinkat.c (careadlinkat) [GCC_LINT]:
Pacify gcc 10’s -Wreturn-local-addr option.
Simplify some of the later code.
---
ChangeLog | 5 +++++
lib/careadlinkat.c | 29 +++++++++++++++++++----------
2 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index c35cfee97..b6d070599 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2020-05-09 Paul Eggert <[email protected]>
+ careadlinkat: pacify -Wreturn-local-addr
+ * lib/careadlinkat.c (careadlinkat) [GCC_LINT]:
+ Pacify gcc 10’s -Wreturn-local-addr option.
+ Simplify some of the later code.
+
attribute: remove ATTRIBUTE_DEPRECATED
* lib/attribute.h: Improve recently-added comments, mostly
by shortening them (use active voice, etc.).
diff --git a/lib/careadlinkat.c b/lib/careadlinkat.c
index 1effdb784..e1f8305e9 100644
--- a/lib/careadlinkat.c
+++ b/lib/careadlinkat.c
@@ -70,19 +70,28 @@ careadlinkat (int fd, char const *filename,
size_t buf_size;
size_t buf_size_max =
SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX;
- char stack_buf[1024];
+
+#if defined GCC_LINT || defined lint
+ /* Pacify preadlinkat without creating a pointer to the stack
+ that gcc -Wreturn-local-addr would cry wolf about. */
+ static char initial_buf[1];
+ enum { initial_buf_size = 0 }; /* 0 so that initial_buf never changes. */
+#else
+ char initial_buf[1024];
+ enum { initial_buf_size = sizeof initial_buf };
+#endif
if (! alloc)
alloc = &stdlib_allocator;
if (! buffer_size)
{
- /* Allocate the initial buffer on the stack. This way, in the
- common case of a symlink of small size, we get away with a
+ /* Allocate the initial buffer. This way, in the common case of
+ a symlink of small size without GCC_LINT, we get away with a
single small malloc() instead of a big malloc() followed by a
shrinking realloc(). */
- buffer = stack_buf;
- buffer_size = sizeof stack_buf;
+ buffer = initial_buf;
+ buffer_size = initial_buf_size;
}
buf = buffer;
@@ -115,21 +124,21 @@ careadlinkat (int fd, char const *filename,
{
buf[link_size++] = '\0';
- if (buf == stack_buf)
+ if (buf == initial_buf)
{
char *b = (char *) alloc->allocate (link_size);
buf_size = link_size;
if (! b)
break;
- memcpy (b, buf, link_size);
- buf = b;
+ return memcpy (b, buf, link_size);
}
- else if (link_size < buf_size && buf != buffer && alloc->reallocate)
+
+ if (link_size < buf_size && buf != buffer && alloc->reallocate)
{
/* Shrink BUF before returning it. */
char *b = (char *) alloc->reallocate (buf, link_size);
if (b)
- buf = b;
+ return b;
}
return buf;
--
2.17.1
>From da2a958f184bfeb1d3491b53eed6473241d9268c Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Sat, 9 May 2020 18:07:38 -0700
Subject: [PATCH 2/2] manywarnings: port to GCC 10.1
* build-aux/gcc-warning.spec:
* m4/manywarnings.m4 (gl_MANYWARN_ALL_GCC(C)):
Add GCC 10.1.0 warnings.
---
ChangeLog | 5 +++++
build-aux/gcc-warning.spec | 14 ++++++++++++--
m4/manywarnings.m4 | 24 +++++++++++++++++++++++-
3 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index b6d070599..b31bbb185 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2020-05-09 Paul Eggert <[email protected]>
+ manywarnings: port to GCC 10.1
+ * build-aux/gcc-warning.spec:
+ * m4/manywarnings.m4 (gl_MANYWARN_ALL_GCC(C)):
+ Add GCC 10.1.0 warnings.
+
careadlinkat: pacify -Wreturn-local-addr
* lib/careadlinkat.c (careadlinkat) [GCC_LINT]:
Pacify gcc 10’s -Wreturn-local-addr option.
diff --git a/build-aux/gcc-warning.spec b/build-aux/gcc-warning.spec
index 723d287af..89a0bc734 100644
--- a/build-aux/gcc-warning.spec
+++ b/build-aux/gcc-warning.spec
@@ -8,12 +8,11 @@
-Waliasing fortran
-Walign-commons fortran
-Waligned-new=[none|global|all] c++
--Walloc-size-larger-than= handled specially by gl_MANYWARN_ALL_GCC
+-Walloc-size-larger-than=<bytes> handled specially by gl_MANYWARN_ALL_GCC
-Walloc-zero Gnulib fixes this problem
-Walloca we like alloca in small doses
-Walloca-larger-than=<number> FIXME: choose something sane?
-Wampersand fortran
--Wargument-mismatch fortran
-Warray-bounds covered by -Warray-bounds=
-Warray-bounds=<0,2> handled specially by gl_MANYWARN_ALL_GCC
-Warray-temporaries fortran
@@ -26,6 +25,8 @@
-Wc++14-compat c++
-Wc++17-compat c++
-Wc++1z-compat c++
+-Wc++20-compat c++
+-Wc++2a-compat c++
-Wc-binding-type fortran
-Wc11-c2x-compat c compatibility
-Wc90-c99-compat c compatibility
@@ -38,6 +39,7 @@
-Wchkp deprecated
-Wclass-conversion c++ and objc++
-Wclass-memaccess c++
+-Wcomma-subscript c++ and objc++
-Wcompare-reals fortran
-Wconditionally-supported c++ and objc++
-Wconversion FIXME maybe? too much noise; encourages bad changes
@@ -67,6 +69,7 @@
-Wimplicit-fallthrough=<0,5> handled specially by gl_MANYWARN_ALL_GCC
-Wimplicit-interface fortran
-Wimplicit-procedure fortran
+-Winaccessible-base c++ and objc++
-Winherited-variadic-ctor c++
-Winit-list-lifetime c++ and objc++
-Winteger-division fortran
@@ -80,12 +83,16 @@
-Wliteral-suffix c++ and objc++
-Wlong-long obsolescent
-Wlto-type-mismatch c++ and objc++
+-Wmismatched-tags c++ and objc++
-Wmissing-format-attribute obsolescent
-Wmissing-noreturn obsolescent
-Wmultiple-inheritance c++ and objc++
-Wnamespaces c++
-Wno-alloc-size-larger-than see -Walloc-size-larger-than
-Wno-alloca-larger-than see -Walloca-larger-than
+-Wno-frame-larger-than see -Wframe-larger-than
+-Wno-larger-than see -Wlarger-than
+-Wno-stack-usage see -Wstack-usage
-Wno-vla-larger-than see -Wvla-larger-than
-Wnoexcept c++
-Wnoexcept-type c++
@@ -96,6 +103,7 @@
-Wold-style-cast c++ and objc++
-Woverloaded-virtual c++
-Woverride-init-side-effects c++ and objc++
+-Woverwrite-recursive fortran
-Wpadded FIXME maybe? warns about "stabil" member in /usr/include/bits/timex.h
-Wpedantic FIXME: too strict?
-Wpessimizing-move c++ and objc++
@@ -110,6 +118,7 @@
-Wrealloc-lhs-all fortran
-Wredundant-decls FIXME maybe? many _gl_cxxalias_dummy FPs
-Wredundant-move c++ and objc++
+-Wredundant-tags c++ and objc++
-Wregister c++ and objc++
-Wreorder c++ and objc++
-Wselector objc and objc++
@@ -158,6 +167,7 @@
-Wvirtual-inheritance c++
-Wvirtual-move-assign c++
-Wvla-larger-than=<number> handled specially by gl_MANYWARN_ALL_GCC
+-Wvolatile c++ and objc++
-Wzero-as-null-pointer-constant c++ and objc++
-Wzerotrip fortran
-frequire-return-statement go
diff --git a/m4/manywarnings.m4 b/m4/manywarnings.m4
index 783620da3..719bafb29 100644
--- a/m4/manywarnings.m4
+++ b/m4/manywarnings.m4
@@ -1,4 +1,4 @@
-# manywarnings.m4 serial 18
+# manywarnings.m4 serial 19
dnl Copyright (C) 2008-2020 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -117,6 +117,23 @@ m4_defun([gl_MANYWARN_ALL_GCC(C)],
-Waddress-of-packed-member \
-Waggressive-loop-optimizations \
-Wall \
+ -Wanalyzer-double-fclose \
+ -Wanalyzer-double-free \
+ -Wanalyzer-exposure-through-output-file \
+ -Wanalyzer-file-leak \
+ -Wanalyzer-free-of-non-heap \
+ -Wanalyzer-malloc-leak \
+ -Wanalyzer-null-argument \
+ -Wanalyzer-null-dereference \
+ -Wanalyzer-possible-null-argument \
+ -Wanalyzer-possible-null-dereference \
+ -Wanalyzer-stale-setjmp-buffer \
+ -Wanalyzer-tainted-array-index \
+ -Wanalyzer-too-complex \
+ -Wanalyzer-unsafe-call-within-signal-handler \
+ -Wanalyzer-use-after-free \
+ -Wanalyzer-use-of-pointer-in-stale-stack-frame \
+ -Warith-conversion \
-Wattribute-warning \
-Wattributes \
-Wbad-function-cast \
@@ -150,9 +167,11 @@ m4_defun([gl_MANYWARN_ALL_GCC(C)],
-Wempty-body \
-Wendif-labels \
-Wenum-compare \
+ -Wenum-conversion \
-Wexpansion-to-defined \
-Wextra \
-Wformat-contains-nul \
+ -Wformat-diag \
-Wformat-extra-args \
-Wformat-nonliteral \
-Wformat-security \
@@ -231,6 +250,7 @@ m4_defun([gl_MANYWARN_ALL_GCC(C)],
-Wstrict-aliasing \
-Wstrict-overflow \
-Wstrict-prototypes \
+ -Wstring-compare \
-Wstringop-truncation \
-Wsuggest-attribute=cold \
-Wsuggest-attribute=const \
@@ -242,6 +262,7 @@ m4_defun([gl_MANYWARN_ALL_GCC(C)],
-Wsuggest-final-types \
-Wswitch \
-Wswitch-bool \
+ -Wswitch-outside-range \
-Wswitch-unreachable \
-Wsync-nand \
-Wsystem-headers \
@@ -269,6 +290,7 @@ m4_defun([gl_MANYWARN_ALL_GCC(C)],
-Wvla \
-Wvolatile-register-var \
-Wwrite-strings \
+ -Wzero-length-bounds \
\
; do
gl_manywarn_set="$gl_manywarn_set $gl_manywarn_item"
--
2.17.1