Skip to contentSkip to conversation

checkpolicy: use calloc() so no need to do memset() afterwards

PATCH In review Kalevi Kolttonen 1 participant 2 messages May 1 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checkpolicy: use calloc() so no need to do memset() afterwards

---
 checkpolicy/checkpolicy.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
checkpolicy/checkpolicy.c +1 -3
index b808e4d0..dd8774e1 100644
@@ -235,13 +235,11 @@ static int identify_equiv_types(void)
 	 * Create a list of access vector rules for each type
 	 * from the access vector table.
 	 */
-	type_rules = malloc(sizeof(struct avtab_node) * policydb.p_types.nprim);
+	type_rules = calloc(sizeof(struct avtab_node) * policydb.p_types.nprim);
 	if (!type_rules) {
 		fprintf(stderr, "out of memory\n");
 		exit(1);
 	}
-	memset(type_rules, 0,
-	       sizeof(struct avtab_node) * policydb.p_types.nprim);
 	if (avtab_map(&policydb.te_avtab, create_type_rules, type_rules))
 		exit(1);
 
Signature · 1 line
2.54.0
#1 lore raw

checkpolicy/checkpolicy.c static int identify_equiv_types(void) · line 238

Quoted 2 lines · Kalevi Kolttonen
checkpolicy/checkpolicy.c +1 -1
-	type_rules = malloc(sizeof(struct avtab_node) * policydb.p_types.nprim);
+	type_rules = calloc(sizeof(struct avtab_node) * policydb.p_types.nprim);

Please ignore this trash and my other message too. I did not remember that calloc()'s signature differs from malloc()'s.

I just sent v2 combining these two patches into one, with the correct calloc() signature.

br,
KK