Re: [RFC/PATCH 9/9] constant: add -Wconstant-size warning

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Nov 19, 2018 at 08:54:38PM +0000, Ramsay Jones wrote:
> From 8764999aa78415e217fd3106a8c8518a5b40c20c Mon Sep 17 00:00:00 2001
> From: Ramsay Jones <ramsay@xxxxxxxxxxxxxxxxxxxx>
> Date: Sun, 18 Nov 2018 23:52:23 +0000
> Subject: [PATCH 9/9] constant: add -Wconstant-size warning

Since the problem is not really a problem of size, nor a problem of
type, but a mismatch between the real type of the constant and the
type indicated by its suffix (or the lack of a suffix), I propose
to call this warning -Wconstant-suffix.

> diff --git a/sparse.1 b/sparse.1
> index 3e13523..26299b3 100644
> --- a/sparse.1
> +++ b/sparse.1
> @@ -101,6 +101,16 @@ Sparse issues these warnings by default.  To turn them off, use
>  \fB\-Wno\-cast\-truncate\fR.
>  .
>  .TP
> +.B \-Wconstant-size
> +Warn if an integer constant is larger than the maximum representable value
> +of the type indicated by the type suffix (if any). For example, on a 64-bit
> +system, the constant 0xfffff00000000000U is larger than can be represented
> +by an int and so requires an unsigned long type suffix. (So, in this case,
> +the warning could be suppressed by using the UL type suffix).

I don't 100% agree with the use of 'requires'. The type of the constant is
determinated by its value, no suffix is required (but the lack of an 'L'
in the suffix may make believe that the type is 'unsigned int' or may
force you to count the zeroes, ...).
I propose to reword the example by something like:
    +Warn if an integer constant is larger than the maximum representable value
    +of the type indicated by its type suffix (if any). For example, on a
    +system where ints are 32-bit and longs 64-bit, the constant \fB0x100000000U\fR
    +is larger than can be represented by an \fBunsigned int\fR but fits in an
    +\fBunsigned long\fR. So its type is \fBunsigned long\fR but this is not
    +indicated by its suffix. In this case, the warning could be suppressed by
    +using the suffix \fBUL\fR: \fB0x100000000UL\fR.

Another solution would be to simply remove the example.

What do you think about it?


Best regards,
-- Luc



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux