@@ -85,10 +85,12 @@ static inline void avc_free(void *ptr)
/* this is a macro in order to use the variadic capability. */
#define avc_log(type, format...) \
- if (avc_func_log) \
- avc_func_log(format); \
- else \
- selinux_log(type, format);
+ do { \
+ if (avc_func_log) \
+ avc_func_log(format); \
+ else \
+ selinux_log(type, format); \
+ } while (0)
static inline void avc_suppl_audit(void *ptr, security_class_t class,
char *buf, size_t len)
@@ -137,14 +139,18 @@ static inline void avc_free_lock(void *lock)
#ifdef AVC_CACHE_STATS
#define avc_cache_stats_incr(field) \
- cache_stats.field ++;
+ do { \
+ cache_stats.field ++; \
+ } while (0)
#define avc_cache_stats_add(field, num) \
- cache_stats.field += num;
+ do { \
+ cache_stats.field += num; \
+ } while (0)
#else
-#define avc_cache_stats_incr(field)
-#define avc_cache_stats_add(field, num)
+#define avc_cache_stats_incr(field) do {} while (0)
+#define avc_cache_stats_add(field, num) do {} while (0)
#endif
@@ -128,10 +128,12 @@ extern int myprintf_compat;
extern void __attribute__ ((format(printf, 1, 2)))
(*myprintf) (const char *fmt, ...) ;
-#define COMPAT_LOG(type, fmt...) if (myprintf_compat) \
- myprintf(fmt); \
- else \
- selinux_log(type, fmt);
+#define COMPAT_LOG(type, fmt...) do { \
+ if (myprintf_compat) \
+ myprintf(fmt); \
+ else \
+ selinux_log(type, fmt); \
+ } while (0)
extern int
compat_validate(struct selabel_handle *rec,
@@ -80,7 +80,7 @@ int selinux_mkload_policy(int preservebools __attribute__((unused)))
if (libsepolh) {
usesepol = 1;
dlerror();
-#define DLERR() if ((errormsg = dlerror())) goto dlclose;
+#define DLERR() do { if ((errormsg = dlerror())) goto dlclose; } while (0)
vers_max = dlsym(libsepolh, "sepol_policy_kern_vers_max");
DLERR();
vers_min = dlsym(libsepolh, "sepol_policy_kern_vers_min");
@@ -146,7 +146,7 @@ static int getprocattrcon_raw(char ** context,
default:
errno = ENOENT;
return -1;
- };
+ }
if (prev_context && prev_context != UNSET) {
*context = strdup(prev_context);
@@ -240,7 +240,7 @@ static int setprocattrcon_raw(const char * context,
default:
errno = ENOENT;
return -1;
- };
+ }
if (!context && !*prev_context)
return 0;
@@ -16,6 +16,7 @@
// sha1.c:73:33: error: cast from 'uint8_t *' (aka 'unsigned char *') to 'CHAR64LONG16 *' increases required alignment from 1 to 4 [-Werror,-Wcast-align]
// CHAR64LONG16* block = (CHAR64LONG16*) workspace;
// William Roberts <william.c.roberts@intel.com>
+// - Silence clang's -Wextra-semi-stmt warning - July 2021, Nicolas Iooss <nicolas.iooss@m4x.org>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -49,11 +50,11 @@ typedef union
^block->l[(i+2)&15]^block->l[i&15],1))
// (R0+R1), R2, R3, R4 are the different operations used in SHA1
-#define R0(v,w,x,y,z,i) z += ((w&(x^y))^y) + blk0(i)+ 0x5A827999 + rol(v,5); w=rol(w,30);
-#define R1(v,w,x,y,z,i) z += ((w&(x^y))^y) + blk(i) + 0x5A827999 + rol(v,5); w=rol(w,30);
-#define R2(v,w,x,y,z,i) z += (w^x^y) + blk(i) + 0x6ED9EBA1 + rol(v,5); w=rol(w,30);
-#define R3(v,w,x,y,z,i) z += (((w|x)&y)|(w&x)) + blk(i) + 0x8F1BBCDC + rol(v,5); w=rol(w,30);
-#define R4(v,w,x,y,z,i) z += (w^x^y) + blk(i) + 0xCA62C1D6 + rol(v,5); w=rol(w,30);
+#define R0(v,w,x,y,z,i) do { z += ((w&(x^y))^y) + blk0(i)+ 0x5A827999 + rol(v,5); w=rol(w,30); } while (0)
+#define R1(v,w,x,y,z,i) do { z += ((w&(x^y))^y) + blk(i) + 0x5A827999 + rol(v,5); w=rol(w,30); } while (0)
+#define R2(v,w,x,y,z,i) do { z += (w^x^y) + blk(i) + 0x6ED9EBA1 + rol(v,5); w=rol(w,30); } while (0)
+#define R3(v,w,x,y,z,i) do { z += (((w|x)&y)|(w&x)) + blk(i) + 0x8F1BBCDC + rol(v,5); w=rol(w,30); } while (0)
+#define R4(v,w,x,y,z,i) do { z += (w^x^y) + blk(i) + 0xCA62C1D6 + rol(v,5); w=rol(w,30); } while (0)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -65,7 +65,7 @@ static mode_t string_to_mode(char *s)
return S_IFREG;
default:
return -1;
- };
+ }
return -1;
}
@@ -47,7 +47,7 @@ static mode_t string_to_mode(char *s)
return S_IFSOCK;
case 'f':
return S_IFREG;
- };
+ }
return 0;
}
On Ubuntu 20.04, when building with clang -Werror -Wextra-semi-stmt (which is not the default build configuration), the compiler reports: sha1.c:90:21: error: empty expression statement has no effect; remove unnecessary ';' to silence this warning [-Werror,-Wextra-semi-stmt] R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3); ^ In file included from selinux_restorecon.c:39: ./label_file.h:458:15: error: empty expression statement has no effect; remove unnecessary ';' to silence this warning [-Werror,-Wextra-semi-stmt] lineno); ^ Introduce "do { } while (0)" blocks to silence such warnings. Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org> --- libselinux/src/avc_internal.h | 22 +++++++++++++------- libselinux/src/label_internal.h | 10 +++++---- libselinux/src/load_policy.c | 2 +- libselinux/src/procattr.c | 4 ++-- libselinux/src/sha1.c | 11 +++++----- libselinux/utils/matchpathcon.c | 2 +- libselinux/utils/selabel_lookup_best_match.c | 2 +- 7 files changed, 31 insertions(+), 22 deletions(-)