[apparmor] [PATCH 9/8 :) ] parser Fix const char warnings
Tyler Hicks
tyhicks at canonical.com
Sat Sep 28 00:17:43 UTC 2013
On 2013-09-13 16:52:47, Steve Beattie wrote:
> Finally, a patch of my own. This patch addresses a bunch of the compiler
> string conversion warnings that were introduced with the C++-ification
> patch.
>
> Signed-off-by: Steve Beattie <steve at nxnw.org>
>
> ---
> parser/libapparmor_re/aare_rules.cc | 4 ++--
> parser/libapparmor_re/aare_rules.h | 4 ++--
> parser/parser.h | 14 +++++++-------
> parser/parser_common.c | 6 +++---
> parser/parser_include.c | 10 +++++-----
> parser/parser_include.h | 2 +-
> parser/parser_interface.c | 18 +++++++++---------
> parser/parser_main.c | 8 ++++----
> parser/parser_misc.c | 8 ++++----
> parser/parser_regex.c | 12 +++++++-----
> parser/parser_variable.c | 34 +++++++++++++++++-----------------
> 11 files changed, 61 insertions(+), 59 deletions(-)
>
> Index: b/parser/parser.h
> ===================================================================
> --- a/parser/parser.h
> +++ b/parser/parser.h
> @@ -234,14 +234,14 @@ extern int names_only;
> extern int option;
> extern int current_lineno;
> extern dfaflags_t dfaflags;
> -extern char *progname;
> -extern char *subdomainbase;
> +extern const char *progname;
> +extern const char *subdomainbase;
> extern char *profilename;
> extern char *profile_ns;
> extern char *current_filename;
> extern FILE *ofile;
> extern int read_implies_exec;
> -extern void pwarn(char *fmt, ...) __attribute__((__format__(__printf__, 1, 2)));
> +extern void pwarn(const char *fmt, ...) __attribute__((__format__(__printf__, 1, 2)));
>
> /* from parser_main (cannot be used in tst builds) */
> extern int force_complain;
> @@ -256,7 +256,7 @@ extern void yyerror(const char *msg, ...
> extern int yylex(void);
>
> /* parser_include.c */
> -extern char *basedir;
> +extern const char *basedir;
>
> /* parser_regex.c */
> extern int process_regex(Profile *prof);
> @@ -271,7 +271,7 @@ extern int process_policy_ents(Profile *
>
> /* parser_variable.c */
> extern int process_variables(Profile *prof);
> -extern struct var_string *split_out_var(char *string);
> +extern struct var_string *split_out_var(const char *string);
> extern void free_var_string(struct var_string *var);
>
> /* parser_misc.c */
> @@ -284,8 +284,8 @@ extern void free_cond_entry(struct cond_
> extern void free_cond_list(struct cond_entry *ents);
> extern void print_cond_entry(struct cond_entry *ent);
> extern char *processid(char *string, int len);
We should probably const the string param in processid() while we're at
it.
> -extern char *processquoted(char *string, int len);
> -extern char *processunquoted(char *string, int len);
> +extern char *processquoted(const char *string, int len);
> +extern char *processunquoted(const char *string, int len);
> extern int get_keyword_token(const char *keyword);
> extern int name_to_capability(const char *keyword);
> extern int get_rlimit(const char *name);
<snip>
> Index: b/parser/parser_interface.c
> ===================================================================
> --- a/parser/parser_interface.c
> +++ b/parser/parser_interface.c
> @@ -327,7 +327,7 @@ inline int sd_write64(sd_serialize *p, u
> return 1;
> }
>
> -inline int sd_write_name(sd_serialize *p, char *name)
> +inline int sd_write_name(sd_serialize *p, const char *name)
> {
> long size = 0;
> PDEBUG("Writing name '%s'\n", name);
> @@ -362,7 +362,7 @@ inline int sd_write_blob(sd_serialize *p
>
> #define align64(X) (((size_t) (X) + (size_t) 7) & ~((size_t) 7))
> inline int sd_write_aligned_blob(sd_serialize *p, void *b, int buf_size,
> - char *name)
> + const char *name)
> {
> size_t pad;
> u32 tmp;
> @@ -381,7 +381,7 @@ inline int sd_write_aligned_blob(sd_seri
> return 1;
> }
>
> -static int sd_write_strn(sd_serialize *p, char *b, int size, char *name)
> +static int sd_write_strn(sd_serialize *p, char *b, int size, const char *name)
> {
> u16 tmp;
> if (!sd_write_name(p, name))
> @@ -396,12 +396,12 @@ static int sd_write_strn(sd_serialize *p
> return 1;
> }
>
> -inline int sd_write_string(sd_serialize *p, char *b, char *name)
> +inline int sd_write_string(sd_serialize *p, char *b, const char *name)
> {
> return sd_write_strn(p, b, strlen(b) + 1, name);
> }
>
> -inline int sd_write_struct(sd_serialize *p, char *name)
> +inline int sd_write_struct(sd_serialize *p, const char *name)
> {
> if (!sd_write_name(p, name))
> return 0;
> @@ -417,7 +417,7 @@ inline int sd_write_structend(sd_seriali
> return 1;
> }
>
> -inline int sd_write_array(sd_serialize *p, char *name, int size)
> +inline int sd_write_array(sd_serialize *p, const char *name, int size)
> {
> u16 tmp;
> if (!sd_write_name(p, name))
> @@ -437,7 +437,7 @@ inline int sd_write_arrayend(sd_serializ
> return 1;
> }
>
> -inline int sd_write_list(sd_serialize *p, char *name)
> +inline int sd_write_list(sd_serialize *p, const char *name)
> {
> if (!sd_write_name(p, name))
> return 0;
> @@ -733,7 +733,7 @@ int sd_serialize_profile(int option, Pro
> if (kernel_load) fd = open(filename, O_WRONLY);
> break;
> case OPTION_STDOUT:
> - filename = "stdout";
> + filename = strdup("stdout");
> fd = dup(1);
> break;
> case OPTION_OFILE:
> @@ -754,7 +754,7 @@ int sd_serialize_profile(int option, Pro
>
> error = 0;
>
> - if (option != OPTION_STDOUT && option != OPTION_OFILE)
> + if (option != OPTION_OFILE)
> free(filename);
It is safe to get rid of the if statement and just unconditionally free
filename. It is initialized to NULL and now that OPTION_STDOUT does a
strdup(), all options either assign filename using a memory allocation
function or don't assign anything to it at all.
It is extremely minor and I don't care either way, but I thought I'd
mention it.
Everything else looks good!
Acked-by: Tyler Hicks <tyhicks at canonical.com>
Tyler
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20130927/e9e93de5/attachment.pgp>
More information about the AppArmor
mailing list