libselinux: silent -Wsign-compare warnings
PATCH 1/3 libselinux: silent -Wsign-compare warnings
When building libselinux with gcc and many warning flags, the build fails with the following errors:
selinux_restorecon.c: In function ‘selinux_restorecon’:
selinux_restorecon.c:784:36: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
if (!flags.ignore_digest && size == fc_digest_len &&
^~
selabel_digest.c: In function ‘main’:
selabel_digest.c:162:16: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
for (i = 0; i < digest_len; i++)
^
selabel_digest.c:173:17: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
for (i = 0; i < num_specfiles; i++) {
^
clang reports the precise type information of the variables:
selinux_restorecon.c:784:36: error: comparison of integers of
different signs: 'ssize_t' (aka 'long') and 'size_t' (aka 'unsigned
long') [-Werror,-Wsign-compare]
if (!flags.ignore_digest && size == fc_digest_len &&
~~~~ ^ ~~~~~~~~~~~~~
selabel_digest.c:162:16: error: comparison of integers of different
signs: 'int' and 'size_t' (aka 'unsigned long')
[-Werror,-Wsign-compare]
for (i = 0; i < digest_len; i++)
~ ^ ~~~~~~~~~~
selabel_digest.c:173:17: error: comparison of integers of different
signs: 'int' and 'size_t' (aka 'unsigned long')
[-Werror,-Wsign-compare]
for (i = 0; i < num_specfiles; i++) {
~ ^ ~~~~~~~~~~~~~Silent the warnings by using size_t where appropriate.
--- libselinux/src/selinux_restorecon.c | 2 +- libselinux/utils/selabel_digest.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
libselinux/src/selinux_restorecon.c +1 -1
@@ -781,7 +781,7 @@ int selinux_restorecon(const char *pathname_orig, size =getxattr (pathname,RESTORECON_LAST , xattr_value, fc_digest_len); -if (!flags.ignore_digest && size == fc_digest_len && +if (!flags.ignore_digest && (size_t )size == fc_digest_len &&memcmp (fc_digest, xattr_value, fc_digest_len) ==0 ) { selinux_log(SELINUX_INFO,
libselinux/utils/selabel_digest.c +2 -2
@@ -59,11 +59,11 @@ static int run_check_digest(char *cmd, char *selabel_digest)int main (int argc,char **argv) { -int backend =0 , rc, opt, i, validate =0 ; +int backend =0 , rc, opt, validate =0 ;char *baseonly =NULL , *file =NULL , *digest = (char *)1 ;char **specfiles =NULL ;unsigned char *sha1_digest =NULL ; -size_t num_specfiles; +size_t i, num_specfiles;char cmd_buf[4096 ];char *cmd_ptr;
Signature · 1 line
2.10.0
PATCH 2/3 libsemanage/tests: do not force using gcc
Allow using other compilers such as clang. Without this, the build fails when $(CFLAGS) contains clang-specific flags:
gcc: error: unrecognized command line option '-Weverything'
--- libsemanage/tests/Makefile | 1 - 1 file changed, 1 deletion(-)
libsemanage/tests/Makefile +0 -1
@@ -10,7 +10,6 @@ LIBS = ../src/libsemanage.a ../../libselinux/src/libselinux.a ../../libsepol/src ########################################################################### EXECUTABLE = libsemanage-tests -CC = gcc CFLAGS += -g -O0 -Wall -W -Wundef -Wmissing-noreturn -Wmissing-format-attribute -Wno-unused-parameter INCLUDE = -I$(TESTSRC) -I$(TESTSRC)/../include LDFLAGS += -lcunit -lustr -lbz2 -laudit
Signature · 1 line
2.10.0
PATCH 3/3 policycoreutils: Remove LDFLAGS from CFLAGS
In reply to Nicolas IoossMixing LDFLAGS in CFLAGS can lead to compiler errors. For example in policycoreutils/sandbox:
$ make CC=clang LDFLAGS='-Wl,-as-needed,-no-undefined'
clang -Wl,-as-needed,-no-undefined -I/usr/include
-DPACKAGE="\"policycoreutils\"" -Wall -Werror -Wextra -W -c -o
seunshare.o seunshare.c
clang-3.8: error: -Wl,-as-needed,-no-undefined: 'linker' input
unused--- policycoreutils/newrole/Makefile | 2 +- policycoreutils/sandbox/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
policycoreutils/newrole/Makefile +1 -1
@@ -22,7 +22,7 @@ VERSION = $(shell cat ../VERSION) CFLAGS ?= -Werror -Wall -W EXTRA_OBJS = -override CFLAGS += -DVERSION=\"$(VERSION)\" $(LDFLAGS) -I$(PREFIX)/include -DUSE_NLS -DLOCALEDIR="\"$(LOCALEDIR)\"" -DPACKAGE="\"policycoreutils\"" +override CFLAGS += -DVERSION=\"$(VERSION)\" -I$(PREFIX)/include -DUSE_NLS -DLOCALEDIR="\"$(LOCALEDIR)\"" -DPACKAGE="\"policycoreutils\"" LDLIBS += -lselinux -L$(PREFIX)/lib ifeq ($(PAMH), /usr/include/security/pam_appl.h) override CFLAGS += -DUSE_PAM
policycoreutils/sandbox/Makefile +1 -1
@@ -9,7 +9,7 @@ SBINDIR ?= $(PREFIX)/sbin MANDIR ?= $(PREFIX)/share/man LOCALEDIR ?= /usr/share/locale SHAREDIR ?= $(PREFIX)/share/sandbox -override CFLAGS += $(LDFLAGS) -I$(PREFIX)/include -DPACKAGE="\"policycoreutils\"" -Wall -Werror -Wextra -W +override CFLAGS += -I$(PREFIX)/include -DPACKAGE="\"policycoreutils\"" -Wall -Werror -Wextra -W LDLIBS += -lselinux -lcap-ng -L$(LIBDIR) SEUNSHARE_OBJS = seunshare.o
Signature · 1 line
2.10.0
Stephen Smalley
AppliedRe: [PATCH 3/3] policycoreutils: Remove LDFLAGS from CFLAGS
Quoted 11 lines · Nicolas Iooss
Mixing LDFLAGS in CFLAGS can lead to compiler errors. For example in policycoreutils/sandbox:
$ make CC=clang LDFLAGS='-Wl,-as-needed,-no-undefined' clang -Wl,-as-needed,-no-undefined -I/usr/include -DPACKAGE="\"policycoreutils\"" -Wall -Werror -Wextra -W -c -o seunshare.o seunshare.c clang-3.8: error: -Wl,-as-needed,-no-undefined: 'linker' input unusedSigned-off-by Nicolas Iooss <[email protected]>
Thanks, applied all 3.
Quoted 32 lines
--- policycoreutils/newrole/Makefile | 2 +- policycoreutils/sandbox/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)policycoreutils/newrole/Makefile +1
-1@@ -22,7 +22,7 @@ VERSION = $(shell cat ../VERSION) CFLAGS ?= -Werror -Wall -W EXTRA_OBJS = -override CFLAGS += -DVERSION=\"$(VERSION)\" $(LDFLAGS) -I$(PREFIX)/include -DUSE_NLS -DLOCALEDIR="\"$(LOCALEDIR)\"" -DPACKAGE="\"policycoreutils\"" +override CFLAGS += -DVERSION=\"$(VERSION)\" -I$(PREFIX)/include -DUSE_NLS -DLOCALEDIR="\"$(LOCALEDIR)\"" -DPACKAGE="\"policycoreutils\"" LDLIBS += -lselinux -L$(PREFIX)/lib ifeq ($(PAMH), /usr/include/security/pam_appl.h) override CFLAGS += -DUSE_PAMpolicycoreutils/sandbox/Makefile +1
-1@@ -9,7 +9,7 @@ SBINDIR ?= $(PREFIX)/sbin MANDIR ?= $(PREFIX)/share/man LOCALEDIR ?= /usr/share/locale SHAREDIR ?= $(PREFIX)/share/sandbox -override CFLAGS += $(LDFLAGS) -I$(PREFIX)/include -DPACKAGE="\"policycoreutils\"" -Wall -Werror -Wextra -W +override CFLAGS += -I$(PREFIX)/include -DPACKAGE="\"policycoreutils\"" -Wall -Werror -Wextra -W LDLIBS += -lselinux -lcap-ng -L$(LIBDIR) SEUNSHARE_OBJS = seunshare.o