checkpolicy: use calloc() so no need to do memset()
PATCH v2 1/1 checkpolicy: use calloc() so no need to do memset()
Signed-off-by Kalevi Kolttonen <[email protected]>
--- checkpolicy/checkpolicy.c | 4 +--- checkpolicy/module_compiler.c | 3 +-- 2 files changed, 2 insertions(+), 5 deletions(-)
checkpolicy/checkpolicy.c +1 -3
@@ -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 (1 ,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 );
checkpolicy/module_compiler.c +1 -2
@@ -842,12 +842,11 @@ int require_class(int pass)return -1 ; } allocated =1 ; -if ((perm =malloc (sizeof (*perm))) ==NULL ) { +if ((perm =calloc (1 ,sizeof (*perm))) ==NULL ) {yyerror ("Out of memory!" );free (perm_id);return -1 ; } -memset (perm,0 ,sizeof (*perm)); ret =hashtab_insert (datum->permissions.table, perm_id, perm);
Signature · 1 line
2.54.0
Quoted 12 lines · Kalevi Kolttonen
Signed-off-by Kalevi Kolttonen <[email protected]>--- checkpolicy/checkpolicy.c | 4 +--- checkpolicy/module_compiler.c | 3 +-- 2 files changed, 2 insertions(+), 5 deletions(-)checkpolicy/checkpolicy.c +0
-0
checkpolicy/checkpolicy.c static int identify_equiv_types(void) · line 238
Quoted 5 lines
checkpolicy/checkpolicy.c +1
-1@@ -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 (1 ,sizeof (struct avtab_node ) * policydb.p_types.nprim);
p_types.nprim is the number of types, so that is the value that should be used as the number of elements rather than 1.
Thanks,
Jim
Quoted 31 lines
checkpolicy/checkpolicy.c +0
-2if (!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 );checkpolicy/module_compiler.c +1
-3@@ -842,12 +842,11 @@ int require_class(int pass)return -1 ; } allocated =1 ; -if ((perm =malloc (sizeof (*perm))) ==NULL ) { +if ((perm =calloc (1 ,sizeof (*perm))) ==NULL ) {yyerror ("Out of memory!" );free (perm_id);return -1 ; } -memset (perm,0 ,sizeof (*perm)); ret =hashtab_insert (datum->permissions.table, perm_id, perm); --2.54.0
Quoted 2 lines · James Carter
p_types.nprim is the number of types, so that is the value that should be used as the number of elements rather than 1.
Yes, thanks, it is cleaner that way. I will send fixed v3.
br,
KK