Does not build with `-O2 -D_FORTIFY_SOURCE=2` compiler options
Debian automatically applies some hardening flags to produce safer binaries.
Among the different default flags1, the combination of -O2
and -D_FORTIFY_SOURCE=2
raises a compilation error since version 1.0.3:
[...]
[55/104] ccache cc -Isubprojects/libinsane/src/14d7ecf@@insane@sha -Isubprojects/libinsane/src -I../subprojects/libinsane/src -Isubprojects/libinsane/include -I../subprojects/libinsane/include -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -Werror -g -DOS_LINUX -DCOMPILER_GCC -O2 -D_FORTIFY_SOURCE=2 -fPIC -pthread -MD -MQ 'subprojects/libinsane/src/14d7ecf@@insane@sha/multiplexer.c.o' -MF 'subprojects/libinsane/src/14d7ecf@@insane@sha/multiplexer.c.o.d' -o 'subprojects/libinsane/src/14d7ecf@@insane@sha/multiplexer.c.o' -c ../subprojects/libinsane/src/multiplexer.c
FAILED: subprojects/libinsane/src/14d7ecf@@insane@sha/multiplexer.c.o
ccache cc -Isubprojects/libinsane/src/14d7ecf@@insane@sha -Isubprojects/libinsane/src -I../subprojects/libinsane/src -Isubprojects/libinsane/include -I../subprojects/libinsane/include -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -Werror -g -DOS_LINUX -DCOMPILER_GCC -O2 -D_FORTIFY_SOURCE=2 -fPIC -pthread -MD -MQ 'subprojects/libinsane/src/14d7ecf@@insane@sha/multiplexer.c.o' -MF 'subprojects/libinsane/src/14d7ecf@@insane@sha/multiplexer.c.o.d' -o 'subprojects/libinsane/src/14d7ecf@@insane@sha/multiplexer.c.o' -c ../subprojects/libinsane/src/multiplexer.c
../subprojects/libinsane/src/multiplexer.c: In function ‘build_base_name’:
../subprojects/libinsane/src/multiplexer.c:66:4: error: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Werror=unused-result]
66 | asprintf(
| ^~~~~~~~~
67 | &n_base_name, "%s:%s", base_name,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
68 | input_implementations[i]->base_name
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
69 | );
| ~
cc1: all warnings being treated as errors
[...]
To reproduce:
mkdir build && cd build
CFLAGS='-O2 -D_FORTIFY_SOURCE=2' meson --werror --warnlevel 2 --prefix=/usr/local ..
ninja -v
I'm not sure which are the specific options that trigger this error but an easy fix would be something like that:
nb_bytes_written = asprintf(
&n_base_name, "%s:%s", base_name,
input_implementations[i]->base_name
);
if (nb_bytes_written == -1); {
lis_error("Could not allocate name string");
}
In that case the compiler detects returned value is used.
Another possible fix is to add (on the packaging side) the -Wno-unused-result
flag which disable the unused return values warnings.
It depends on whether you prefer to fix it in the library code or not.
CFLAGS=-g -O2 -fdebug-prefix-map=/build/debian/libinsane=. -fstack-protector-strong -Wformat -Werror=format-security
CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2
CXXFLAGS=-g -O2 -fdebug-prefix-map=/build/debian/libinsane=. -fstack-protector-strong -Wformat -Werror=format-security
FCFLAGS=-g -O2 -fdebug-prefix-map=/build/debian/libinsane=. -fstack-protector-strong
FFLAGS=-g -O2 -fdebug-prefix-map=/build/debian/libinsane=. -fstack-protector-strong
GCJFLAGS=-g -O2 -fdebug-prefix-map=/build/debian/libinsane=. -fstack-protector-strong
LDFLAGS=-Wl,-z,relro
OBJCFLAGS=-g -O2 -fdebug-prefix-map=/build/debian/libinsane=. -fstack-protector-strong -Wformat -Werror=format-security
OBJCXXFLAGS=-g -O2 -fdebug-prefix-map=/build/debian/libinsane=. -fstack-protector-strong -Wformat -Werror=format-security
-
the full list for this package is the following:
↩
Edited by Jerome Flesch