bug-gnulib
[Top][All Lists]
Advanced

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

Re: [Bug-gnulib] linebreak.c proposed patches for size-calculation overf


From: Bruno Haible
Subject: Re: [Bug-gnulib] linebreak.c proposed patches for size-calculation overflows
Date: Mon, 10 Nov 2003 21:37:38 +0100
User-agent: KMail/1.5

Paul Eggert wrote:
> This patch causes xsize.h to conflict with xalloc.h, because xalloc.h
> now uses SIZE_MAX in a preprocessor context.

Oh well. I'll add a configure-time determination of SIZE_MAX and PTRDIFF_MAX
tomorrow. And then noone will complain any more that it's not ISO C 99
compliant :-)

> +#  define xalloc_oversized(n, s) ((size_t) -1 / (s) <= (n))

I think this expression is wrong, and should better be written as

                                    ((size_t) -2 / (s) < (n))

For example, take n = (SIZE_MAX - 1) / 2 and s = 2 (or vice versa).
Since n * s == (SIZE_MAX - 1) is in bounds, xalloc_oversized(n, s)
must evaluate to false.

Bruno





reply via email to

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