[PROPOSED] Fix unlikely conversion bug in zic
* zic.c (puttzcode): Arg is zic_t, not int_fast32_t. This fixes a portability bug on platforms where int_fast32_t is a 32-bit ones’ complement or signed-magnitude integer, and where the argument is -2**31 before conversion to int_fast32_t. Although I don’t know of any such platforms, the C standard allows them. --- zic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zic.c b/zic.c index d8bdbb96..548c1c5f 100644 --- a/zic.c +++ b/zic.c @@ -2216,7 +2216,7 @@ convert64(uint_fast64_t val, char *buf) } static void -puttzcode(const int_fast32_t val, FILE *const fp) +puttzcode(zic_t val, FILE *fp) { char buf[4]; -- 2.37.2
It's not relevant yet, but the C23 standard requires 2's-complement arithmetic. In document N2912 (available from the committee website https://open-std.org/jtc1/sc22/wg14/ under 'documents'), which is the June 2022 draft of the standard, section 6.2.6.2 Integer types says: NOTE 2 The sign representation defined in this document is called two’s
complement. Previous revisions of this document additionally allowed other sign representations.
So, in a decade or two, we will be able to ignore systems which do not use 2's-complement arithmetic. If you were ruthless, you could probably ignore 1's-complement and sign-magnitude systems now — this is very largely recognizing the status quo. There probably are a few mainframe antiques around with the alternatives, but not many. On Fri, Nov 4, 2022 at 9:01 PM Paul Eggert via tz <tz@iana.org> wrote:
* zic.c (puttzcode): Arg is zic_t, not int_fast32_t. This fixes a portability bug on platforms where int_fast32_t is a 32-bit ones’ complement or signed-magnitude integer, and where the argument is -2**31 before conversion to int_fast32_t. Although I don’t know of any such platforms, the C standard allows them. ---
-- Jonathan Leffler <jonathan.leffler@gmail.com> #include <disclaimer.h> Guardian of DBD::Informix - v2018.1031 - http://dbi.perl.org "Blessed are we who can laugh at ourselves, for we shall never cease to be amused."
participants (2)
-
Jonathan Leffler -
Paul Eggert