Re: [patch] Misc warnings found by clang.

From: Dimitry Andric <dimitry_at_andric.com>
Date: Tue, 15 Jun 2010 10:37:21 +0200
On 2010-06-15 00:08, Max Laier wrote:
> I'm not sure about the intention behind the len assignements in libugidfw - 
> might be just a leftover - but if the idea is to teach a model that "we 
> generally care about the return value of snprintf()", a void cast might be the 
> more protable solution.

These specific snprintf() calls all occur just before returning an
error, so checking the return value is quite useless (unless one wanted
to output some sort of overflow warning right there).

Moreover, all calls to snprintf() in lib/libugidfw/ugidfw.c that do
check the return value are incorrect in two ways:
- The return value is stored in a size_t, while snprintf() returns an
  int.  Thus all the checks "ret < 0" become bogus.
- The idiom used everywhere is:
    len = snprintf(cur, left, ...);
    if (len < 0 || len > left)
            goto truncated;
  which is wrong; the second check should be "len >= left" instead.

Please review the attached patch which fixes those problems too.

Received on Tue Jun 15 2010 - 06:37:14 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:04 UTC