[apparmor] [PATCH 3/5] Remove unused rc variable from pwarn

Steve Beattie steve at nxnw.org
Tue Jan 3 19:59:13 UTC 2012


On Tue, Jan 03, 2012 at 11:50:32AM -0800, John Johansen wrote:
> On 01/03/2012 11:17 AM, Steve Beattie wrote:
> >I suspect the reason the rc variable got added was to avoid the unused
> >result warning on the asprintf call that results:
> >
> >   parser_common.c: In function ‘pwarn’:
> >   parser_common.c:61:17: warning: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Wunused-result]
> >
> 
> err yes, sorry the patch for that seems to have not been included, see below
> 
> ---
> 
> From 4fd7804333d4a6386858bfd6d75aaed94aa9d6f2 Mon Sep 17 00:00:00 2001
> From: John Johansen <john.johansen at canonical.com>
> Date: Tue, 3 Jan 2012 11:43:21 -0800
> Subject: [PATCH] Remove asprintf warning and fix invalid test
> 
> asprintf is marked with warn_unused_result and its return value should
> not be ignored, even casting to (void) will not remove this warning.
> 
> The current code ignored the result and used the value of newfmt to
> make a decision.  This is however not correct in that according to the
> asprintf man page newfmt is undefined if asprintf returns an error.
> 
> Fix the warning and error by using the return value of asprintf
> 
> Signed-off-by: John Johansen <john.johansen at canonical.com>

Acked-By: Steve Beattie <sbeattie at ubuntu.com>

Thanks!

> ---
>  parser/parser_common.c |   13 ++++++-------
>  1 files changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/parser/parser_common.c b/parser/parser_common.c
> index 59df46c..df78a10 100644
> --- a/parser/parser_common.c
> +++ b/parser/parser_common.c
> @@ -58,13 +58,12 @@ void pwarn(char *fmt, ...)
>          if (conf_quiet || names_only || option == OPTION_REMOVE)
>                  return;
> -        asprintf(&newfmt, _("Warning from %s (%s%sline %d): %s"),
> -		 profilename ? profilename : "stdin",
> -		 current_filename ? current_filename : "",
> -		 current_filename ? " " : "",
> -		 current_lineno,
> -		 fmt);
> -        if (!newfmt)
> +        if (asprintf(&newfmt, _("Warning from %s (%s%sline %d): %s"),
> +		     profilename ? profilename : "stdin",
> +		     current_filename ? current_filename : "",
> +		     current_filename ? " " : "",
> +		     current_lineno,
> +		     fmt) == -1)
>                  return;
>          va_start(arg, fmt);
> -- 
> 1.7.7.3

-- 
Steve Beattie
<sbeattie at ubuntu.com>
http://NxNW.org/~steve/
-------------- 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/20120103/a08fadcc/attachment.pgp>


More information about the AppArmor mailing list