git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 7/7] vcs-svn: fix clang-analyzer warning

From
David Michael Barr <davidbarr@google.com>
Date
May 31, 2012, 11:34 UTC
Message-ID
<CAFfmPPPmnS4f4+JVhLFqcNM+taj4VO6ZVMv8RCoEiQqKHGy_1g@mail.gmail.com>
In-Reply-To
<20120524143337.GB3732@burratino>
On Fri, May 25, 2012 at 12:33 AM, Jonathan Nieder <jrnieder@gmail.com> wrote:
Show 56 quoted lines
> David Barr wrote:
>
>> vcs-svn/svndiff.c:278:3: warning: expression result unused [-Wunused-value]
>>                 error("invalid delta: incorrect postimage length");
>>                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> In file included from vcs-svn/svndiff.c:6:
>> vcs-svn/compat-util.h:18:61: note: instantiated from:
>> #define error(...) (fprintf(stderr, "error: " __VA_ARGS__), -1)
>>                                                             ^~
>
> Yuck.  Would you be ok with an inline variadic function?
>
>  static inline int error(const char *fmt, ...)
>  {
>        va_list ap;
>
>        fprintf(stderr, "error: ");
>
>        va_start(ap, fmt);
>        vfprintf(stderr, fmt, ap)
>        va_end(ap);
>
>        fprintf(stderr, "\n");
>
>        return -1;
>  }
>
> The error() macro above also seems to leave out a newline.
>
>> --- a/vcs-svn/svndiff.c
>> +++ b/vcs-svn/svndiff.c
>> @@ -258,6 +258,7 @@ static int apply_window_in_core(struct window *ctx)
> [...]
>> @@ -275,16 +276,15 @@ static int apply_one_window(struct line_buffer *delta, off_t *delta_len,
>>       if (apply_window_in_core(&ctx))
>>               goto error_out;
>>       if (ctx.out.len != out_len) {
>> -             error("invalid delta: incorrect postimage length");
>> +             rv = error("invalid delta: incorrect postimage length");
>>               goto error_out;
>>       }
>>       if (write_strbuf(&ctx.out, out))
>>               goto error_out;
>> -     window_release(&ctx);
>> -     return 0;
>> +     rv = 0;
>>  error_out:
>>       window_release(&ctx);
>> -     return -1;
>> +     return rv;
>
> That said, if this change is justified by saying that it avoids having
> to repeat the cleanup code, it already looks like a good change.  The
> commit message could mention that the original motivation and a
> side-benefit is to help the standalone version that has a slightly
> crazier definition of error().
I'll rework the commit message and requeue.

-- David Barr.

Previous: Jonathan Nieder
Message 14 of 14 in “vcs-svn: housekeeping”
  1. 0/7 vcs-svn: housekeepingDavid Barr, May 24, 2012
  2. 1/7 vcs-svn: prefer constcmp to prefixcmpDavid Barr, May 24, 2012
  3. 2/7 vcs-svn: prefer strstr over memmemDavid Barr, May 24, 2012
  4. 3/7 vcs-svn: fix signedness warningsDavid Barr, May 24, 2012
  5. Jonathan NiederMay 24, 2012
  6. David Michael BarrMay 31, 2012
  7. 4/7 vcs-svn: drop no-op reset methodsDavid Barr, May 24, 2012
  8. 5/7 vcs-svn: fix cppcheck warningDavid Barr, May 24, 2012
  9. Jonathan NiederMay 24, 2012
  10. David Michael BarrMay 31, 2012
  11. 6/7 vcs-svn: fix clang-analyzer errorDavid Barr, May 24, 2012
  12. 7/7 vcs-svn: fix clang-analyzer warningDavid Barr, May 24, 2012
  13. Jonathan NiederMay 24, 2012
  14. David Michael BarrMay 31, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.