On Mon, 15.10.12 21:05, Sami Kerola ([email protected]) wrote:

> Found with 'cppcheck --enable=all --inconclusive --std=posix' while
> working with util-linux, which has a copy of this file.
> 
> [misc-utils/sd-daemon.c:91]: (style) Checking if unsigned variable 'l' is \
> less than zero.
> [misc-utils/sd-daemon.c:254]: (warning) Comparison of a boolean \
> expression with an integer.
> [misc-utils/sd-daemon.c:363]: (style) Checking if unsigned variable \
> 'length' is less than zero.
> [misc-utils/sd-daemon.c:366]: (style) Checking if unsigned variable \
> 'length' is less than zero.

Umm. Honestly it really appears to be as if cppcheck could need some
updating here, not this file... All four lines are correct... The <=
comparisons clarify the intention of the checks, independently of the
used type, and the boolean warning of cppcheck is outright wrong, as
both the left hand and the right hand side are boolean expressions...
> 
> CC: Dave Reisner <[email protected]>
> References: http://www.spinics.net/lists/util-linux-ng/msg07031.html
> Signed-off-by: Sami Kerola <[email protected]>
> ---
>  src/libsystemd-daemon/sd-daemon.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/src/libsystemd-daemon/sd-daemon.c 
> b/src/libsystemd-daemon/sd-daemon.c
> index 863ac75..03cde39 100644
> --- a/src/libsystemd-daemon/sd-daemon.c
> +++ b/src/libsystemd-daemon/sd-daemon.c
> @@ -88,7 +88,7 @@ _sd_export_ int sd_listen_fds(int unset_environment) {
>                  goto finish;
>          }
>  
> -        if (!p || *p || l <= 0) {
> +        if (!p || *p || l == 0) {
>                  r = -EINVAL;
>                  goto finish;
>          }
> @@ -249,7 +249,7 @@ static int sd_is_socket_internal(int fd, int type, int 
> listening) {
>                  if (l != sizeof(accepting))
>                          return -EINVAL;
>  
> -                if (!accepting != !listening)
> +                if ((!accepting) != (!listening))
>                          return 0;
>          }
>  
> @@ -358,10 +358,10 @@ _sd_export_ int sd_is_socket_unix(int fd, int type, int 
> listening, const char *p
>                  return 0;
>  
>          if (path) {
> -                if (length <= 0)
> +                if (length == 0)
>                          length = strlen(path);
>  
> -                if (length <= 0)
> +                if (length == 0)
>                          /* Unnamed socket */
>                          return l == offsetof(struct sockaddr_un, sun_path);
>  


Lennart

-- 
Lennart Poettering - Red Hat, Inc.
_______________________________________________
systemd-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to