[patch] clears -Wall warnings

Denys Vlasenko vda.linux at googlemail.com
Mon May 19 03:26:15 PDT 2008


On Monday 19 May 2008 02:06, Cristian Ionescu-Idbohrn wrote:
> On Mon, 19 May 2008, Denys Vlasenko wrote:
> 
> > -                       get_terminal_width_height(0, &output_width, NULL);
> > +                       get_terminal_width_height(0, &output_width, (unsigned *)NULL);
> >
> > This cast is not needed.
> 
> Alright.  But as it doesn't seem to do any damage, is it bad if it shows
> up?


> > I applied as much of this patch as needed for -Wall to not complain,
> > and enabled -Wall in standard build. In fact, it was already enabled,
> > but we also had -Wno-pointer-sign, which hid pointer warnings.
> > Now it is removed.
> 
> Groovy ;-)
> 
> > I do not think adding -W options which will make it necessary to have
> > changes like this:
> >
> > -               col = snprintf(line_buf, scr_width,
> > +               col = snprintf(line_buf, (size_t)scr_width,
> >
> > is useful.
> 
> In what way do you mean?
> Is it doing any danage?
> Increases size?

Type casts are brute-force way to shut up the compiler.
If subsequent code changes will turn this into an actual error
(imagine that scr_width is a *function name* after a code edit),
code without type cast would not compile, whereas code with one
will.

IOW: type casts remove all benefits you have from using a strongly
typed language.

> Are we interested in the -Wconversion compiler option?  It warns about
> things like this:
> 
>   archival/libunarchive/get_header_tar.c:300: warning: conversion to
>   'size_t' from 'off_t' may alter its value
> 
> and this:
> 
>   include/xatonum.h: In function 'xatou32':
>   include/xatonum.h:109: warning: conversion to 'uint32_t' from 'int' may
>   change the sign of the result

Both seem to be false positives.
--
vda


More information about the busybox mailing list