Skip to content

Commit

Permalink
libsepol: silence -Wextra-semi-stmt warning
Browse files Browse the repository at this point in the history
On Ubuntu 20.04, when building with clang -Werror -Wextra-semi-stmt
(which is not the default build configuration), the compiler reports:

  ../cil/src/cil_binary.c:4293:22: error: empty expression statement
  has no effect; remove unnecessary ';' to silence this warning
  [-Werror,-Wextra-semi-stmt]
          mix(k->target_class);
                              ^
  ../cil/src/cil_binary.c:4294:21: error: empty expression statement
  has no effect; remove unnecessary ';' to silence this warning
  [-Werror,-Wextra-semi-stmt]
          mix(k->target_type);
                             ^
  ../cil/src/cil_binary.c:4295:21: error: empty expression statement
  has no effect; remove unnecessary ';' to silence this warning
  [-Werror,-Wextra-semi-stmt]
          mix(k->source_type);
                             ^
  ../cil/src/cil_binary.c:4296:19: error: empty expression statement
  has no effect; remove unnecessary ';' to silence this warning
  [-Werror,-Wextra-semi-stmt]
          mix(k->specified);
                           ^

Use a do { ... } while (0) construction to silence this warning.

Moreover the same warning appears when using two semicolons to end a
statement. Remove such occurrences, like what was already done in commit
8111856 ("libsepol: drop repeated semicolons").

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
  • Loading branch information
fishilico authored and jwcart2 committed Jul 6, 2021
1 parent fd705df commit 9d85aa6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions libsepol/cil/src/cil_binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -4277,15 +4277,15 @@ static unsigned int avrulex_hash(__attribute__((unused)) hashtab_t h, const_hash

uint32_t hash = 0;

#define mix(input) { \
#define mix(input) do { \
uint32_t v = input; \
v *= c1; \
v = (v << r1) | (v >> (32 - r1)); \
v *= c2; \
hash ^= v; \
hash = (hash << r2) | (hash >> (32 - r2)); \
hash = hash * m + n; \
}
} while (0)

mix(k->target_class);
mix(k->target_type);
Expand Down
2 changes: 1 addition & 1 deletion libsepol/cil/src/cil_resolve_ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -2825,7 +2825,7 @@ static int cil_build_call_args(struct cil_tree_node *call_node, struct cil_call
return SEPOL_OK;
} else {
cil_tree_log(call_node, CIL_ERR, "Unexpected arguments");
return SEPOL_ERR;;
return SEPOL_ERR;
}
}
if (call->args_tree == NULL) {
Expand Down
4 changes: 2 additions & 2 deletions libsepol/src/avtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ static inline int avtab_hash(struct avtab_key *keyp, uint32_t mask)

uint32_t hash = 0;

#define mix(input) { \
#define mix(input) do { \
uint32_t v = input; \
v *= c1; \
v = (v << r1) | (v >> (32 - r1)); \
v *= c2; \
hash ^= v; \
hash = (hash << r2) | (hash >> (32 - r2)); \
hash = hash * m + n; \
}
} while (0)

mix(keyp->target_class);
mix(keyp->target_type);
Expand Down
18 changes: 11 additions & 7 deletions libsepol/tests/libsepol-tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@
int mls;

#define DECLARE_SUITE(name) \
suite = CU_add_suite(#name, name##_test_init, name##_test_cleanup); \
if (NULL == suite) { \
CU_cleanup_registry(); \
return CU_get_error(); } \
if (name##_add_tests(suite)) { \
CU_cleanup_registry(); \
return CU_get_error(); }
do { \
suite = CU_add_suite(#name, name##_test_init, name##_test_cleanup); \
if (NULL == suite) { \
CU_cleanup_registry(); \
return CU_get_error(); \
} \
if (name##_add_tests(suite)) { \
CU_cleanup_registry(); \
return CU_get_error(); \
} \
} while (0)

static void usage(char *progname)
{
Expand Down

0 comments on commit 9d85aa6

Please sign in to comment.