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

John Johansen john.johansen at canonical.com
Tue Jan 3 19:50:32 UTC 2012


On 01/03/2012 11:17 AM, Steve Beattie wrote:
> On Tue, Dec 27, 2011 at 06:49:33PM -0800, John Johansen wrote:
>> Signed-off-by: John Johansen<john.johansen at canonical.com>
>> ---
>>   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 f409f87..59df46c 100644
>> --- a/parser/parser_common.c
>> +++ b/parser/parser_common.c
>> @@ -54,17 +54,16 @@ void pwarn(char *fmt, ...)
>>   {
>>           va_list arg;
>>           char *newfmt;
>> -        int rc;
>>
>>           if (conf_quiet || names_only || option == OPTION_REMOVE)
>>                   return;
>>
>> -        rc = asprintf(&newfmt, _("Warning from %s (%s%sline %d): %s"),
>> -                      profilename ? profilename : "stdin",
>> -                      current_filename ? current_filename : "",
>> -                      current_filename ? " " : "",
>> -                      current_lineno,
>> -                      fmt);
>> +        asprintf(&newfmt, _("Warning from %s (%s%sline %d): %s"),
>> +		 profilename ? profilename : "stdin",
>> +		 current_filename ? current_filename : "",
>> +		 current_filename ? " " : "",
>> +		 current_lineno,
>> +		 fmt);
>>           if (!newfmt)
>>                   return;
>>
>
> 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>
---
  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




More information about the AppArmor mailing list