Improve libqpol yyerror/yywarn prototypes

* Add printf format specifier for yyerror2 to be able to use
  "gcc -Wformat-security"
* Constify message string to avoid gcc warnings about casting string
  literals to non-const char*.
This commit is contained in:
Nicolas Iooss 2014-11-01 14:23:02 +01:00 committed by Chris PeBenito
parent 7aace4d52a
commit 35722ab22d
4 changed files with 11 additions and 9 deletions

View File

@ -47,8 +47,9 @@ typedef struct scope_stack {
extern policydb_t *policydbp;
extern queue_t id_queue;
extern int yyerror(char *msg);
extern void yyerror2(char *fmt, ...);
extern int yyerror(const char *msg);
__attribute__ ((format(printf, 1, 2)))
extern void yyerror2(const char *fmt, ...);
static int push_stack(int stack_type, ...);
static void pop_stack(void);

View File

@ -81,8 +81,8 @@ extern unsigned long policydb_lineno;
extern unsigned long source_lineno;
extern unsigned int policydb_errors;
extern int yywarn(char *msg);
extern int yyerror(char *msg);
extern int yywarn(const char *msg);
extern int yyerror(const char *msg);
#define ERRORMSG_LEN 255
static char errormsg[ERRORMSG_LEN + 1] = {0};
@ -104,7 +104,8 @@ void init_parser(int pass_number, int do_rules)
num_rules = 0;
}
void yyerror2(char *fmt, ...)
__attribute__ ((format(printf, 1, 2)))
void yyerror2(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);

View File

@ -76,8 +76,8 @@ extern unsigned int pass;
extern char yytext[];
extern int yylex(void);
extern int yywarn(char *msg);
extern int yyerror(char *msg);
extern int yywarn(const char *msg);
extern int yyerror(const char *msg);
typedef int (* require_func_t)();

View File

@ -47,7 +47,7 @@ typedef int (* require_func_t)();
static char linebuf[2][255];
static unsigned int lno = 0;
int yywarn(char *msg);
int yywarn(const char *msg);
void set_source_file(const char *name);
@ -310,7 +310,7 @@ int yyerror(char *msg)
return -1;
}
int yywarn(char *msg)
int yywarn(const char *msg)
{
if (source_file[0])
fprintf(stderr, "%s:%ld:",