Treat literal strings as constant

Literal strings are located in read-only memory and should be "const
char*".  "gcc -Wwrite-strings" warns when using non-const literal
strings with messages like:

    libqpol/policy_parse.y: In function 'yyparse':
    libqpol/policy_parse.y:381:21: warning: passing argument 1 of
    'insert_id' discards 'const' qualifier from pointer target type
         { if (insert_id("T",0)) return -1; }
                     ^

Fix these warnings by using "const char*" instead of "char*" for some
function parameters.

This makes gcc report other warnings about hashtab_search (from
libsepol).  This function incorrectly defines its second parameter as
"char *const key" instead of "const char* key" (this fact is hidden
behind hashtab_key_t typedef).
This commit is contained in:
Nicolas Iooss 2014-11-01 14:23:30 +01:00 committed by Chris PeBenito
parent 2994d1ca1d
commit edca1ac4c7
6 changed files with 11 additions and 11 deletions

View File

@ -1253,7 +1253,7 @@ static int is_scope_in_stack(scope_datum_t * scope, scope_stack_t * stack)
return is_scope_in_stack(scope, stack->parent);
}
int is_id_in_scope(uint32_t symbol_type, hashtab_key_t id)
int is_id_in_scope(uint32_t symbol_type, const char *id)
{
scope_datum_t *scope =
(scope_datum_t *) hashtab_search(policydbp->scope[symbol_type].
@ -1300,7 +1300,7 @@ static int is_perm_in_stack(uint32_t perm_value, uint32_t class_value,
return is_perm_in_stack(perm_value, class_value, stack->parent);
}
int is_perm_in_scope(hashtab_key_t perm_id, hashtab_key_t class_id)
int is_perm_in_scope(hashtab_key_t perm_id, const char *class_id)
{
class_datum_t *cladatum =
(class_datum_t *) hashtab_search(policydbp->p_classes.table,

View File

@ -76,12 +76,12 @@ int require_cat(int pass);
/* Check if an identifier is within the scope of the current
* declaration or any of its parents. Return 1 if it is, 0 if not.
* If the identifier is not known at all then return 1 (truth). */
int is_id_in_scope(uint32_t symbol_type, hashtab_key_t id);
int is_id_in_scope(uint32_t symbol_type, const char * id);
/* Check if a particular permission is within the scope of the current
* declaration or any of its parents. Return 1 if it is, 0 if not.
* If the identifier is not known at all then return 1 (truth). */
int is_perm_in_scope(hashtab_key_t perm_id, hashtab_key_t class_id);
int is_perm_in_scope(hashtab_key_t perm_id, const char * class_id);
/* Search the current avrules block for a conditional with the same
* expression as 'cond'. If the conditional does not exist then

View File

@ -177,7 +177,7 @@ static void qpol_handle_default_callback(void *varg __attribute__ ((unused)), co
fprintf(stderr, "\n");
}
static int read_source_policy(qpol_policy_t * qpolicy, char *progname, int options)
static int read_source_policy(qpol_policy_t * qpolicy, const char *progname, int options)
{
int load_rules = 1;
if (options & QPOL_POLICY_OPTION_NO_RULES)

View File

@ -87,7 +87,7 @@ extern int yyerror(const char *msg);
#define ERRORMSG_LEN 255
static char errormsg[ERRORMSG_LEN + 1] = {0};
static int id_has_dot(char *id);
static int id_has_dot(const char *id);
static int parse_security_context(context_struct_t *c);
/* initialize all of the state variables for the scanner/parser */
@ -167,7 +167,7 @@ int insert_separator(int push)
return 0;
}
int insert_id(char *id, int push)
int insert_id(const char *id, int push)
{
char *newid = 0;
int error;
@ -193,7 +193,7 @@ int insert_id(char *id, int push)
/* If the identifier has a dot within it and that its first character
is not a dot then return 1, else return 0. */
static int id_has_dot(char *id)
static int id_has_dot(const char *id)
{
if (strchr(id, '.') >= id + 1) {
return 1;
@ -1380,7 +1380,7 @@ int define_typeattribute(void)
return 0;
}
static int define_typebounds_helper(char *bounds_id, char *type_id)
static int define_typebounds_helper(const char *bounds_id, const char *type_id)
{
type_datum_t *bounds, *type;

View File

@ -77,7 +77,7 @@ int define_typebounds(void);
int define_type(int alias);
int define_user(void);
int define_validatetrans(constraint_expr_t *expr);
int insert_id(char *id,int push);
int insert_id(const char *id,int push);
int insert_separator(int push);
role_datum_t *define_role_dom(role_datum_t *r);
role_datum_t *merge_roles_dom(role_datum_t *r1,role_datum_t *r2);

View File

@ -367,7 +367,7 @@ static int qpol_policy_fill_attr_holes(qpol_policy_t * policy)
return STATUS_ERR;
}
static char *sidnames[] = {
static const char *const sidnames[] = {
"undefined",
"kernel",
"security",