Skip to content

Commit

Permalink
libsepol/cil: follow declaration-after-statement
Browse files Browse the repository at this point in the history
Follow the project style of no declaration after statement.

Found by the gcc warning -Wdeclaration-after-statement

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
  • Loading branch information
cgzones authored and jwcart2 committed Jun 24, 2021
1 parent 8f50b45 commit 852c439
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 13 deletions.
5 changes: 3 additions & 2 deletions libsepol/cil/src/cil_binary.c
Expand Up @@ -593,11 +593,11 @@ int cil_typeattribute_to_policydb(policydb_t *pdb, struct cil_typeattribute *cil
int __cil_typeattr_bitmap_init(policydb_t *pdb)
{
int rc = SEPOL_ERR;
uint32_t i;

pdb->type_attr_map = cil_malloc(pdb->p_types.nprim * sizeof(ebitmap_t));
pdb->attr_type_map = cil_malloc(pdb->p_types.nprim * sizeof(ebitmap_t));

uint32_t i = 0;
for (i = 0; i < pdb->p_types.nprim; i++) {
ebitmap_init(&pdb->type_attr_map[i]);
ebitmap_init(&pdb->attr_type_map[i]);
Expand Down Expand Up @@ -2657,6 +2657,7 @@ int __cil_constrain_expr_to_sepol_expr_helper(policydb_t *pdb, const struct cil_
int rc = SEPOL_ERR;
struct cil_list_item *item;
enum cil_flavor flavor;
enum cil_flavor cil_op;
constraint_expr_t *op, *h1, *h2, *t1, *t2;
int is_leaf = CIL_FALSE;

Expand All @@ -2673,7 +2674,7 @@ int __cil_constrain_expr_to_sepol_expr_helper(policydb_t *pdb, const struct cil_
goto exit;
}

enum cil_flavor cil_op = (enum cil_flavor)(uintptr_t)item->data;
cil_op = (enum cil_flavor)(uintptr_t)item->data;
switch (cil_op) {
case CIL_NOT:
op->expr_type = CEXPR_NOT;
Expand Down
5 changes: 3 additions & 2 deletions libsepol/cil/src/cil_build_ast.c
Expand Up @@ -5173,6 +5173,7 @@ int cil_gen_macro(struct cil_db *db, struct cil_tree_node *parse_current, struct
char *key = NULL;
struct cil_macro *macro = NULL;
struct cil_tree_node *macro_content = NULL;
struct cil_tree_node *current_item;
enum cil_syntax syntax[] = {
CIL_SYN_STRING,
CIL_SYN_STRING,
Expand All @@ -5195,7 +5196,7 @@ int cil_gen_macro(struct cil_db *db, struct cil_tree_node *parse_current, struct

key = parse_current->next->data;

struct cil_tree_node *current_item = parse_current->next->next->cl_head;
current_item = parse_current->next->next->cl_head;
while (current_item != NULL) {
enum cil_syntax param_syntax[] = {
CIL_SYN_STRING,
Expand All @@ -5205,6 +5206,7 @@ int cil_gen_macro(struct cil_db *db, struct cil_tree_node *parse_current, struct
int param_syntax_len = sizeof(param_syntax)/sizeof(*param_syntax);
char *kind = NULL;
struct cil_param *param = NULL;
struct cil_list_item *curr_param;

rc =__cil_verify_syntax(current_item->cl_head, param_syntax, param_syntax_len);
if (rc != SEPOL_OK) {
Expand Down Expand Up @@ -5263,7 +5265,6 @@ int cil_gen_macro(struct cil_db *db, struct cil_tree_node *parse_current, struct
}

//walk current list and check for duplicate parameters
struct cil_list_item *curr_param;
cil_list_for_each(curr_param, macro->params) {
if (param->str == ((struct cil_param*)curr_param->data)->str) {
cil_log(CIL_ERR, "Duplicate parameter\n");
Expand Down
3 changes: 2 additions & 1 deletion libsepol/cil/src/cil_fqn.c
Expand Up @@ -78,12 +78,13 @@ static int __cil_fqn_qualify_blocks(__attribute__((unused)) hashtab_key_t k, has
struct cil_tree_node *node = NODE(datum);
int i;
int rc = SEPOL_OK;
int newlen;

if (node->flavor != CIL_BLOCK) {
goto exit;
}

int newlen = fqn_args->len + strlen(datum->name) + 1;
newlen = fqn_args->len + strlen(datum->name) + 1;
if (newlen >= CIL_MAX_NAME_LENGTH) {
cil_log(CIL_INFO, "Fully qualified name for block %s is too long\n", datum->name);
rc = SEPOL_ERR;
Expand Down
7 changes: 4 additions & 3 deletions libsepol/cil/src/cil_list.c
Expand Up @@ -55,15 +55,16 @@ void cil_list_init(struct cil_list **list, enum cil_flavor flavor)

void cil_list_destroy(struct cil_list **list, unsigned destroy_data)
{
struct cil_list_item *item;

if (*list == NULL) {
return;
}

struct cil_list_item *item = (*list)->head;
struct cil_list_item *next = NULL;
item = (*list)->head;
while (item != NULL)
{
next = item->next;
struct cil_list_item *next = item->next;
if (item->flavor == CIL_LIST) {
cil_list_destroy((struct cil_list**)&(item->data), destroy_data);
free(item);
Expand Down
2 changes: 1 addition & 1 deletion libsepol/cil/src/cil_post.c
Expand Up @@ -213,8 +213,8 @@ int cil_post_filecon_compare(const void *a, const void *b)
struct fc_data *a_data = cil_malloc(sizeof(*a_data));
struct fc_data *b_data = cil_malloc(sizeof(*b_data));
char *a_path = cil_malloc(strlen(a_filecon->path_str) + 1);
a_path[0] = '\0';
char *b_path = cil_malloc(strlen(b_filecon->path_str) + 1);
a_path[0] = '\0';
b_path[0] = '\0';
strcat(a_path, a_filecon->path_str);
strcat(b_path, b_filecon->path_str);
Expand Down
6 changes: 3 additions & 3 deletions libsepol/cil/src/cil_resolve_ast.c
Expand Up @@ -3956,10 +3956,10 @@ int __cil_resolve_ast_node_helper(struct cil_tree_node *node, uint32_t *finished
enum cil_log_level lvl = CIL_ERR;

if (optional != NULL) {
lvl = CIL_INFO;

struct cil_optional *opt = (struct cil_optional *)optional->data;
struct cil_tree_node *opt_node = NODE(opt);;
struct cil_tree_node *opt_node = NODE(opt);

lvl = CIL_INFO;
/* disable an optional if something failed to resolve */
opt->enabled = CIL_FALSE;
cil_tree_log(node, lvl, "Failed to resolve %s statement", cil_node_to_string(node));
Expand Down
3 changes: 2 additions & 1 deletion libsepol/cil/src/cil_strpool.c
Expand Up @@ -75,9 +75,10 @@ char *cil_strpool_add(const char *str)

strpool_ref = hashtab_search(cil_strpool_tab, (hashtab_key_t)str);
if (strpool_ref == NULL) {
int rc;
strpool_ref = cil_malloc(sizeof(*strpool_ref));
strpool_ref->str = cil_strdup(str);
int rc = hashtab_insert(cil_strpool_tab, (hashtab_key_t)strpool_ref->str, strpool_ref);
rc = hashtab_insert(cil_strpool_tab, (hashtab_key_t)strpool_ref->str, strpool_ref);
if (rc != SEPOL_OK) {
pthread_mutex_unlock(&cil_strpool_mutex);
cil_log(CIL_ERR, "Failed to allocate memory\n");
Expand Down

0 comments on commit 852c439

Please sign in to comment.