Skip to contentSkip to conversation

libselinux/utils: add noreturn attribute to selinux_check_access's usage

PATCH Applied Nicolas Iooss 2 participants 3 messages May 3, 2017 – May 5, 2017 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 libselinux/utils: add noreturn attribute to selinux_check_access's usage

When building libselinux, clang reports the following warning:

selinux_check_access.c:8:1: error: function 'usage' could be declared with attribute 'noreturn' [-Werror,-Wmissing-noreturn]

While at it, make progname const.

---
 libselinux/utils/selinux_check_access.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libselinux/utils/selinux_check_access.c +1 -1
index 88762b48c5d2..6cea40e9f059 100644
@@ -4,7 +4,7 @@
 #include <unistd.h>
 #include <selinux/selinux.h>
 
-static void usage(char *progname)
+static __attribute__ ((__noreturn__)) void usage(const char *progname)
 {
 	fprintf(stderr, "usage:  %s [-a auditdata] scon tcon class perm\n"
 		"\nWhere:\n\t"
Signature · 1 line
2.12.2
#1 lore raw

PATCH 2/2 libsepol: silence false-positive -Wwrite-strings warning

When compiling with -Wwrite-strings, the compiler complains about calling strs_add with a const char* value for a char* parameter (DEFAULT_OBJECT is defined to "object_r"). Silence this warning by casting the literal string to char*.

---
 libsepol/src/kernel_to_cil.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/src/kernel_to_cil.c +1 -1
index e873ac3a1981..3a1c0be76f45 100644
@@ -2369,7 +2369,7 @@ static int write_user_decl_rules_to_cil(FILE *out, struct policydb *pdb)
 				goto exit;
 			}
 
-			rc = strs_add(role_strs, DEFAULT_OBJECT);
+			rc = strs_add(role_strs, (char *)DEFAULT_OBJECT);
 			if (rc != 0) {
 				strs_destroy(&role_strs);
 				goto exit;
Signature · 1 line
2.12.2
#2 lore raw

Re: [PATCH 2/2] libsepol: silence false-positive -Wwrite-strings warning

Quoted 4 lines · Nicolas Iooss

When compiling with -Wwrite-strings, the compiler complains about calling strs_add with a const char* value for a char* parameter (DEFAULT_OBJECT is defined to "object_r"). Silence this warning by casting the literal string to char*.

Thanks, applied both patches. At some point we should likely fix strs_add() though to take const char *.

Quoted 22 lines

---
 libsepol/src/kernel_to_cil.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/src/kernel_to_cil.c +0 -0
index e873ac3a1981..3a1c0be76f45 100644
@@ -2369,7 +2369,7 @@ static int write_user_decl_rules_to_cil(FILE
 *out, struct policydb *pdb)
  				goto exit;
  			}

libsepol/src/kernel_to_cil.c +1 -1
-			rc = strs_add(role_strs, DEFAULT_OBJECT);
+			rc = strs_add(role_strs, (char

*)DEFAULT_OBJECT);
  if (rc != 0) { strs_destroy(&role_strs); goto exit;