bug-make
[Top][All Lists]
Advanced

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

Re: [PATCH] Fix src/function.c build failure on gcc-12.


From: Edward Welbourne
Subject: Re: [PATCH] Fix src/function.c build failure on gcc-12.
Date: Mon, 21 Feb 2022 08:59:33 +0000

Sergei Trofimovich (19 February 2022 00:48) reports:
> Upcoming gcc-12 detects possible buffer overflow for 1 byte:
[snip]
> Unlikely numbers like '-1234567890' including null terminator take 12
> bytes of storage.

and that's assuming a 32-bit int; the signed range is from -2,147,483,647
to 2,147,483,648.  However, may I suggest the following (which I know I
included in the GPL'd cfengine sources at some point):

  #define DECIMAL_SIGNED_BUFFER_SIZE(bytes) (3 + (53 * (bytes)) / 22)
  #define DECIMAL_UNSIGNED_BUFFER_SIZE(bytes) (2 + (53 * (bytes)) / 22)

and then pass sizeof(int) to the appropriate one of those everywhere
that needs a buffer size (or contribution thereto) for the
representation of an integral type as a decimal string ?  For the
rationale behind the numbers, see
https://github.com/ediosyncratic/study.py/blob/master/maths/buffersize.py
(which comes with assertions confirming the correctness).

Then you won't have to update all your buffer-sizes for systems with
different sizes of standard integral types,

        Eddy.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]