Blame SOURCES/0068-libsepol-cil-follow-declaration-after-statement.patch

71cd55
From 852c4398a9a227e0eb4de42d45c0c2845ed92bc7 Mon Sep 17 00:00:00 2001
71cd55
From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgzones@googlemail.com>
71cd55
Date: Tue, 8 Jun 2021 17:58:57 +0200
71cd55
Subject: [PATCH] libsepol/cil: follow declaration-after-statement
71cd55
MIME-Version: 1.0
71cd55
Content-Type: text/plain; charset=UTF-8
71cd55
Content-Transfer-Encoding: 8bit
71cd55
71cd55
Follow the project style of no declaration after statement.
71cd55
71cd55
Found by the gcc warning -Wdeclaration-after-statement
71cd55
71cd55
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
71cd55
Acked-by: James Carter <jwcart2@gmail.com>
71cd55
---
71cd55
 libsepol/cil/src/cil_binary.c      | 5 +++--
71cd55
 libsepol/cil/src/cil_build_ast.c   | 5 +++--
71cd55
 libsepol/cil/src/cil_fqn.c         | 3 ++-
71cd55
 libsepol/cil/src/cil_list.c        | 7 ++++---
71cd55
 libsepol/cil/src/cil_post.c        | 2 +-
71cd55
 libsepol/cil/src/cil_resolve_ast.c | 6 +++---
71cd55
 libsepol/cil/src/cil_strpool.c     | 3 ++-
71cd55
 7 files changed, 18 insertions(+), 13 deletions(-)
71cd55
71cd55
diff --git a/libsepol/cil/src/cil_binary.c b/libsepol/cil/src/cil_binary.c
71cd55
index 18532aad9801..85094b01ef9d 100644
71cd55
--- a/libsepol/cil/src/cil_binary.c
71cd55
+++ b/libsepol/cil/src/cil_binary.c
71cd55
@@ -593,11 +593,11 @@ exit:
71cd55
 int __cil_typeattr_bitmap_init(policydb_t *pdb)
71cd55
 {
71cd55
 	int rc = SEPOL_ERR;
71cd55
+	uint32_t i;
71cd55
 
71cd55
 	pdb->type_attr_map = cil_malloc(pdb->p_types.nprim * sizeof(ebitmap_t));
71cd55
 	pdb->attr_type_map = cil_malloc(pdb->p_types.nprim * sizeof(ebitmap_t));
71cd55
 
71cd55
-	uint32_t i = 0;
71cd55
 	for (i = 0; i < pdb->p_types.nprim; i++) {
71cd55
 		ebitmap_init(&pdb->type_attr_map[i]);
71cd55
 		ebitmap_init(&pdb->attr_type_map[i]);
71cd55
@@ -2657,6 +2657,7 @@ int __cil_constrain_expr_to_sepol_expr_helper(policydb_t *pdb, const struct cil_
71cd55
 	int rc = SEPOL_ERR;
71cd55
 	struct cil_list_item *item;
71cd55
 	enum cil_flavor flavor;
71cd55
+	enum cil_flavor cil_op;
71cd55
 	constraint_expr_t *op, *h1, *h2, *t1, *t2;
71cd55
 	int is_leaf = CIL_FALSE;
71cd55
 
71cd55
@@ -2673,7 +2674,7 @@ int __cil_constrain_expr_to_sepol_expr_helper(policydb_t *pdb, const struct cil_
71cd55
 		goto exit;
71cd55
 	}
71cd55
 
71cd55
-	enum cil_flavor cil_op = (enum cil_flavor)(uintptr_t)item->data;
71cd55
+	cil_op = (enum cil_flavor)(uintptr_t)item->data;
71cd55
 	switch (cil_op) {
71cd55
 	case CIL_NOT:
71cd55
 		op->expr_type = CEXPR_NOT;
71cd55
diff --git a/libsepol/cil/src/cil_build_ast.c b/libsepol/cil/src/cil_build_ast.c
71cd55
index 96c97263d8c8..908b0336d1dd 100644
71cd55
--- a/libsepol/cil/src/cil_build_ast.c
71cd55
+++ b/libsepol/cil/src/cil_build_ast.c
71cd55
@@ -5173,6 +5173,7 @@ int cil_gen_macro(struct cil_db *db, struct cil_tree_node *parse_current, struct
71cd55
 	char *key = NULL;
71cd55
 	struct cil_macro *macro = NULL;
71cd55
 	struct cil_tree_node *macro_content = NULL;
71cd55
+	struct cil_tree_node *current_item;
71cd55
 	enum cil_syntax syntax[] = {
71cd55
 		CIL_SYN_STRING,
71cd55
 		CIL_SYN_STRING,
71cd55
@@ -5195,7 +5196,7 @@ int cil_gen_macro(struct cil_db *db, struct cil_tree_node *parse_current, struct
71cd55
 
71cd55
 	key = parse_current->next->data;
71cd55
 
71cd55
-	struct cil_tree_node *current_item = parse_current->next->next->cl_head;
71cd55
+	current_item = parse_current->next->next->cl_head;
71cd55
 	while (current_item != NULL) {
71cd55
 		enum cil_syntax param_syntax[] = {
71cd55
 			CIL_SYN_STRING,
71cd55
@@ -5205,6 +5206,7 @@ int cil_gen_macro(struct cil_db *db, struct cil_tree_node *parse_current, struct
71cd55
 		int param_syntax_len = sizeof(param_syntax)/sizeof(*param_syntax);
71cd55
 		char *kind = NULL;
71cd55
 		struct cil_param *param = NULL;
71cd55
+		struct cil_list_item *curr_param;
71cd55
 
71cd55
 		rc =__cil_verify_syntax(current_item->cl_head, param_syntax, param_syntax_len);
71cd55
 		if (rc != SEPOL_OK) {
71cd55
@@ -5263,7 +5265,6 @@ int cil_gen_macro(struct cil_db *db, struct cil_tree_node *parse_current, struct
71cd55
 		}
71cd55
 
71cd55
 		//walk current list and check for duplicate parameters
71cd55
-		struct cil_list_item *curr_param;
71cd55
 		cil_list_for_each(curr_param, macro->params) {
71cd55
 			if (param->str == ((struct cil_param*)curr_param->data)->str) {
71cd55
 				cil_log(CIL_ERR, "Duplicate parameter\n");
71cd55
diff --git a/libsepol/cil/src/cil_fqn.c b/libsepol/cil/src/cil_fqn.c
71cd55
index 097222a83da9..46db069b254a 100644
71cd55
--- a/libsepol/cil/src/cil_fqn.c
71cd55
+++ b/libsepol/cil/src/cil_fqn.c
71cd55
@@ -78,12 +78,13 @@ static int __cil_fqn_qualify_blocks(__attribute__((unused)) hashtab_key_t k, has
71cd55
 	struct cil_tree_node *node = NODE(datum);
71cd55
 	int i;
71cd55
 	int rc = SEPOL_OK;
71cd55
+	int newlen;
71cd55
 
71cd55
 	if (node->flavor != CIL_BLOCK) {
71cd55
 		goto exit;
71cd55
 	}
71cd55
 
71cd55
-	int newlen = fqn_args->len + strlen(datum->name) + 1;
71cd55
+	newlen = fqn_args->len + strlen(datum->name) + 1;
71cd55
 	if (newlen >= CIL_MAX_NAME_LENGTH) {
71cd55
 		cil_log(CIL_INFO, "Fully qualified name for block %s is too long\n", datum->name);
71cd55
 		rc = SEPOL_ERR;
71cd55
diff --git a/libsepol/cil/src/cil_list.c b/libsepol/cil/src/cil_list.c
71cd55
index 4e7843cb01ef..8a426f1f5950 100644
71cd55
--- a/libsepol/cil/src/cil_list.c
71cd55
+++ b/libsepol/cil/src/cil_list.c
71cd55
@@ -55,15 +55,16 @@ void cil_list_init(struct cil_list **list, enum cil_flavor flavor)
71cd55
 
71cd55
 void cil_list_destroy(struct cil_list **list, unsigned destroy_data)
71cd55
 {
71cd55
+	struct cil_list_item *item;
71cd55
+
71cd55
 	if (*list == NULL) {
71cd55
 		return;
71cd55
 	}
71cd55
 
71cd55
-	struct cil_list_item *item = (*list)->head;
71cd55
-	struct cil_list_item *next = NULL;
71cd55
+	item = (*list)->head;
71cd55
 	while (item != NULL)
71cd55
 	{
71cd55
-		next = item->next;
71cd55
+		struct cil_list_item *next = item->next;
71cd55
 		if (item->flavor == CIL_LIST) {
71cd55
 			cil_list_destroy((struct cil_list**)&(item->data), destroy_data);
71cd55
 			free(item);
71cd55
diff --git a/libsepol/cil/src/cil_post.c b/libsepol/cil/src/cil_post.c
71cd55
index 05842b644807..7bca0834ad39 100644
71cd55
--- a/libsepol/cil/src/cil_post.c
71cd55
+++ b/libsepol/cil/src/cil_post.c
71cd55
@@ -213,8 +213,8 @@ int cil_post_filecon_compare(const void *a, const void *b)
71cd55
 	struct fc_data *a_data = cil_malloc(sizeof(*a_data));
71cd55
 	struct fc_data *b_data = cil_malloc(sizeof(*b_data));
71cd55
 	char *a_path = cil_malloc(strlen(a_filecon->path_str) + 1);
71cd55
-	a_path[0] = '\0';
71cd55
 	char *b_path = cil_malloc(strlen(b_filecon->path_str) + 1);
71cd55
+	a_path[0] = '\0';
71cd55
 	b_path[0] = '\0';
71cd55
 	strcat(a_path, a_filecon->path_str);
71cd55
 	strcat(b_path, b_filecon->path_str);
71cd55
diff --git a/libsepol/cil/src/cil_resolve_ast.c b/libsepol/cil/src/cil_resolve_ast.c
71cd55
index 92a4d29700e9..b5199bad35e2 100644
71cd55
--- a/libsepol/cil/src/cil_resolve_ast.c
71cd55
+++ b/libsepol/cil/src/cil_resolve_ast.c
71cd55
@@ -3956,10 +3956,10 @@ int __cil_resolve_ast_node_helper(struct cil_tree_node *node, uint32_t *finished
71cd55
 		enum cil_log_level lvl = CIL_ERR;
71cd55
 
71cd55
 		if (optional != NULL) {
71cd55
-			lvl = CIL_INFO;
71cd55
-
71cd55
 			struct cil_optional *opt = (struct cil_optional *)optional->data;
71cd55
-			struct cil_tree_node *opt_node = NODE(opt);;
71cd55
+			struct cil_tree_node *opt_node = NODE(opt);
71cd55
+
71cd55
+			lvl = CIL_INFO;
71cd55
 			/* disable an optional if something failed to resolve */
71cd55
 			opt->enabled = CIL_FALSE;
71cd55
 			cil_tree_log(node, lvl, "Failed to resolve %s statement", cil_node_to_string(node));
71cd55
diff --git a/libsepol/cil/src/cil_strpool.c b/libsepol/cil/src/cil_strpool.c
71cd55
index 2598bbf3d80e..70bca3630220 100644
71cd55
--- a/libsepol/cil/src/cil_strpool.c
71cd55
+++ b/libsepol/cil/src/cil_strpool.c
71cd55
@@ -75,9 +75,10 @@ char *cil_strpool_add(const char *str)
71cd55
 
71cd55
 	strpool_ref = hashtab_search(cil_strpool_tab, (hashtab_key_t)str);
71cd55
 	if (strpool_ref == NULL) {
71cd55
+		int rc;
71cd55
 		strpool_ref = cil_malloc(sizeof(*strpool_ref));
71cd55
 		strpool_ref->str = cil_strdup(str);
71cd55
-		int rc = hashtab_insert(cil_strpool_tab, (hashtab_key_t)strpool_ref->str, strpool_ref);
71cd55
+		rc = hashtab_insert(cil_strpool_tab, (hashtab_key_t)strpool_ref->str, strpool_ref);
71cd55
 		if (rc != SEPOL_OK) {
71cd55
 			pthread_mutex_unlock(&cil_strpool_mutex);
71cd55
 			cil_log(CIL_ERR, "Failed to allocate memory\n");
71cd55
-- 
71cd55
2.32.0
71cd55