Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

God doesn't play dice. -- Albert Einstein


devel / comp.lang.c / *rubeyes*: realloc(ptr, 0) is UB?

SubjectAuthor
* *rubeyes*: realloc(ptr, 0) is UB?Kaz Kylheku
+* Re: *rubeyes*: realloc(ptr, 0) is UB?Lawrence D'Oliveiro
|`* Re: *rubeyes*: realloc(ptr, 0) is UB?Kaz Kylheku
| `* Re: *rubeyes*: realloc(ptr, 0) is UB?Lawrence D'Oliveiro
|  `* Re: *rubeyes*: realloc(ptr, 0) is UB?Kaz Kylheku
|   `- Re: *rubeyes*: realloc(ptr, 0) is UB?Lawrence D'Oliveiro
+* Re: *rubeyes*: realloc(ptr, 0) is UB?David Brown
|`* Re: *rubeyes*: realloc(ptr, 0) is UB?Kaz Kylheku
| `- Re: *rubeyes*: realloc(ptr, 0) is UB?BGB
+* Re: *rubeyes*: realloc(ptr, 0) is UB?Scott Lurndal
|+* Re: *rubeyes*: realloc(ptr, 0) is UB?Kaz Kylheku
||`* Re: *rubeyes*: realloc(ptr, 0) is UB?Scott Lurndal
|| +- Re: *rubeyes*: realloc(ptr, 0) is UB?Kaz Kylheku
|| `* Re: *rubeyes*: realloc(ptr, 0) is UB?Tim Rentsch
||  `* Re: *rubeyes*: realloc(ptr, 0) is UB?Scott Lurndal
||   +* Re: *rubeyes*: realloc(ptr, 0) is UB?James Kuyper
||   |`* Re: *rubeyes*: realloc(ptr, 0) is UB?Kaz Kylheku
||   | `* Re: *rubeyes*: realloc(ptr, 0) is UB?James Kuyper
||   |  `* Re: *rubeyes*: realloc(ptr, 0) is UB?Kaz Kylheku
||   |   +- Re: *rubeyes*: realloc(ptr, 0) is UB?Chris M. Thomasson
||   |   `* Re: *rubeyes*: realloc(ptr, 0) is UB?Keith Thompson
||   |    +* Re: *rubeyes*: realloc(ptr, 0) is UB?Kaz Kylheku
||   |    |`* Re: *rubeyes*: realloc(ptr, 0) is UB?Tim Rentsch
||   |    | `* Re: *rubeyes*: realloc(ptr, 0) is UB?Richard Kettlewell
||   |    |  +- Re: *rubeyes*: realloc(ptr, 0) is UB?Kaz Kylheku
||   |    |  `* Re: *rubeyes*: realloc(ptr, 0) is UB?Tim Rentsch
||   |    |   `* Re: *rubeyes*: realloc(ptr, 0) is UB?Richard Kettlewell
||   |    |    `* Re: *rubeyes*: realloc(ptr, 0) is UB?Tim Rentsch
||   |    |     +* Re: *rubeyes*: realloc(ptr, 0) is UB?Kaz Kylheku
||   |    |     |`- Re: *rubeyes*: realloc(ptr, 0) is UB?Tim Rentsch
||   |    |     `* Re: *rubeyes*: realloc(ptr, 0) is UB?Richard Kettlewell
||   |    |      `* Re: *rubeyes*: realloc(ptr, 0) is UB?Tim Rentsch
||   |    |       `* Re: *rubeyes*: realloc(ptr, 0) is UB?Richard Kettlewell
||   |    |        `- Re: *rubeyes*: realloc(ptr, 0) is UB?Tim Rentsch
||   |    +* Re: *rubeyes*: realloc(ptr, 0) is UB?Lawrence D'Oliveiro
||   |    |+* Re: *rubeyes*: realloc(ptr, 0) is UB?Kaz Kylheku
||   |    ||`* Re: *rubeyes*: realloc(ptr, 0) is UB?Tim Rentsch
||   |    || `* Re: *rubeyes*: realloc(ptr, 0) is UB?Kaz Kylheku
||   |    ||  `* Re: *rubeyes*: realloc(ptr, 0) is UB?Tim Rentsch
||   |    ||   `* Re: *rubeyes*: realloc(ptr, 0) is UB?Kaz Kylheku
||   |    ||    +* Re: *rubeyes*: realloc(ptr, 0) is UB?Keith Thompson
||   |    ||    |`* Re: *rubeyes*: realloc(ptr, 0) is UB?Chris M. Thomasson
||   |    ||    | `* Re: *rubeyes*: realloc(ptr, 0) is UB?Keith Thompson
||   |    ||    |  `* Re: *rubeyes*: realloc(ptr, 0) is UB?David Brown
||   |    ||    |   `- Re: *rubeyes*: realloc(ptr, 0) is UB?Chris M. Thomasson
||   |    ||    +* Re: *rubeyes*: realloc(ptr, 0) is UB?Tim Rentsch
||   |    ||    |`* Re: *rubeyes*: realloc(ptr, 0) is UB?Kaz Kylheku
||   |    ||    | `- Re: *rubeyes*: realloc(ptr, 0) is UB?Tim Rentsch
||   |    ||    `- Re: *rubeyes*: realloc(ptr, 0) is UB?James Kuyper
||   |    |`* Re: *rubeyes*: realloc(ptr, 0) is UB?Keith Thompson
||   |    | +* Re: *rubeyes*: realloc(ptr, 0) is UB?Kaz Kylheku
||   |    | |+* Re: *rubeyes*: realloc(ptr, 0) is UB?Keith Thompson
||   |    | ||`- Re: *rubeyes*: realloc(ptr, 0) is UB?Tim Rentsch
||   |    | |+* Re: *rubeyes*: realloc(ptr, 0) is UB?bart
||   |    | ||+- Re: *rubeyes*: realloc(ptr, 0) is UB?Tim Rentsch
||   |    | ||+* Re: *rubeyes*: realloc(ptr, 0) is UB?Chris M. Thomasson
||   |    | |||+* Re: *rubeyes*: realloc(ptr, 0) is UB?bart
||   |    | ||||+* Re: *rubeyes*: realloc(ptr, 0) is UB?David Brown
||   |    | |||||+* Re: *rubeyes*: realloc(ptr, 0) is UB?Kaz Kylheku
||   |    | ||||||`- Re: *rubeyes*: realloc(ptr, 0) is UB?David Brown
||   |    | |||||+* Re: *rubeyes*: realloc(ptr, 0) is UB?Keith Thompson
||   |    | ||||||+* Re: *rubeyes*: realloc(ptr, 0) is UB?Kaz Kylheku
||   |    | |||||||`* Re: *rubeyes*: realloc(ptr, 0) is UB?bart
||   |    | ||||||| `- Re: *rubeyes*: realloc(ptr, 0) is UB?Malcolm McLean
||   |    | ||||||`* Re: *rubeyes*: realloc(ptr, 0) is UB?David Brown
||   |    | |||||| `* Re: *rubeyes*: realloc(ptr, 0) is UB?Lawrence D'Oliveiro
||   |    | ||||||  `- Re: *rubeyes*: realloc(ptr, 0) is UB?David Brown
||   |    | |||||+- Re: *rubeyes*: realloc(ptr, 0) is UB?bart
||   |    | |||||`* Re: *rubeyes*: realloc(ptr, 0) is UB?Chris M. Thomasson
||   |    | ||||| `- Re: *rubeyes*: realloc(ptr, 0) is UB?Chris M. Thomasson
||   |    | ||||+* Re: *rubeyes*: realloc(ptr, 0) is UB?Kaz Kylheku
||   |    | |||||`- Re: *rubeyes*: realloc(ptr, 0) is UB?Chris M. Thomasson
||   |    | ||||`* Re: *rubeyes*: realloc(ptr, 0) is UB?Chris M. Thomasson
||   |    | |||| +* Re: *rubeyes*: realloc(ptr, 0) is UB?Malcolm McLean
||   |    | |||| |`- Re: *rubeyes*: realloc(ptr, 0) is UB?Chris M. Thomasson
||   |    | |||| `* Re: *rubeyes*: realloc(ptr, 0) is UB?bart
||   |    | ||||  +- Re: *rubeyes*: realloc(ptr, 0) is UB?bart
||   |    | ||||  `- Re: *rubeyes*: realloc(ptr, 0) is UB?Lawrence D'Oliveiro
||   |    | |||`- Re: *rubeyes*: realloc(ptr, 0) is UB?Lew Pitcher
||   |    | ||`* Re: *rubeyes*: realloc(ptr, 0) is UB?Richard Kettlewell
||   |    | || `* Re: *rubeyes*: realloc(ptr, 0) is UB?bart
||   |    | ||  +* Re: *rubeyes*: realloc(ptr, 0) is UB?Kaz Kylheku
||   |    | ||  |+- Re: *rubeyes*: realloc(ptr, 0) is UB?Kalevi Kolttonen
||   |    | ||  |+* Re: *rubeyes*: realloc(ptr, 0) is UB?bart
||   |    | ||  ||`* Re: *rubeyes*: realloc(ptr, 0) is UB?Chris M. Thomasson
||   |    | ||  || `- Re: *rubeyes*: realloc(ptr, 0) is UB?Chris M. Thomasson
||   |    | ||  |`* Re: *rubeyes*: realloc(ptr, 0) is UB?Scott Lurndal
||   |    | ||  | `- Re: *rubeyes*: realloc(ptr, 0) is UB?Chris M. Thomasson
||   |    | ||  `- Re: *rubeyes*: realloc(ptr, 0) is UB?Richard Kettlewell
||   |    | |`* Re: *rubeyes*: realloc(ptr, 0) is UB?Tim Rentsch
||   |    | | `* Re: *rubeyes*: realloc(ptr, 0) is UB?Malcolm McLean
||   |    | |  +- Re: *rubeyes*: realloc(ptr, 0) is UB?Keith Thompson
||   |    | |  +- Re: *rubeyes*: realloc(ptr, 0) is UB?Keith Thompson
||   |    | |  +* Re: *rubeyes*: realloc(ptr, 0) is UB?Scott Lurndal
||   |    | |  |`- Re: *rubeyes*: realloc(ptr, 0) is UB?Lawrence D'Oliveiro
||   |    | |  +- Re: *rubeyes*: realloc(ptr, 0) is UB?Spiros Bousbouras
||   |    | |  `- Re: *rubeyes*: realloc(ptr, 0) is UB?Tim Rentsch
||   |    | `- Re: *rubeyes*: realloc(ptr, 0) is UB?Tim Rentsch
||   |    +* Re: *rubeyes*: realloc(ptr, 0) is UB?Keith Thompson
||   |    |+* Re: *rubeyes*: realloc(ptr, 0) is UB?Lawrence D'Oliveiro
||   |    ||`* Re: *rubeyes*: realloc(ptr, 0) is UB?Kaz Kylheku
||   |    |`* Re: *rubeyes*: realloc(ptr, 0) is UB?Tim Rentsch
||   |    `- Re: *rubeyes*: realloc(ptr, 0) is UB?Tim Rentsch
||   `- Re: *rubeyes*: realloc(ptr, 0) is UB?Tim Rentsch
|`* Re: *rubeyes*: realloc(ptr, 0) is UB?Tim Rentsch
+* Re: *rubeyes*: realloc(ptr, 0) is UB?Blue-Maned_Hawk
`- Re: *rubeyes*: realloc(ptr, 0) is UB?Tim Rentsch

Pages:1234567
*rubeyes*: realloc(ptr, 0) is UB?

<20240116162506.143@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31048&group=comp.lang.c#31048

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: *rubeyes*: realloc(ptr, 0) is UB?
Date: Wed, 17 Jan 2024 00:32:10 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <20240116162506.143@kylheku.com>
Injection-Date: Wed, 17 Jan 2024 00:32:10 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="30353e714807d76ba68823a6307c7dd8";
logging-data="1766877"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1++PrJwHy4vq4RHuL7RimnJgYx9c0Nu5Ho="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:gWTlPgKH6OZ2OxoiD8ro/697dCU=
 by: Kaz Kylheku - Wed, 17 Jan 2024 00:32 UTC

I'm looking at the C99 and N3096 (April 2023) definitions of realloc
side by side.

N3096 says

"Otherwise, if ptr does not match a pointer earlier returned by a memory
management function, or if the space has been deallocated by a call to
the free or realloc function, or if the size is zero, the behavior is
undefined."

Yikes! In C99 there is nothing about the size being zero:

"Otherwise, if ptr does not match a pointer earlier returned by the
calloc, malloc, or realloc function, or if the space has been
deallocated by a call to the free or realloc function, the behavior is
undefined."

Nothing about "or if the size is zero".

Yikes; when did this criminal stupidity get perpetrated?

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: *rubeyes*: realloc(ptr, 0) is UB?

<uo7c5h$1miqe$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31055&group=comp.lang.c#31055

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo...@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.c
Subject: Re: *rubeyes*: realloc(ptr, 0) is UB?
Date: Wed, 17 Jan 2024 01:57:06 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <uo7c5h$1miqe$2@dont-email.me>
References: <20240116162506.143@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 17 Jan 2024 01:57:06 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="71e924a53864396a82a319f1f0d5bb71";
logging-data="1788750"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/iNm+RRQr/JPJRMBrojFTt"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:GL9LGK9tE7UwY8w9kbwZ3u10TO0=
 by: Lawrence D'Oliv - Wed, 17 Jan 2024 01:57 UTC

On Wed, 17 Jan 2024 00:32:10 -0000 (UTC), Kaz Kylheku wrote:

> Nothing about "or if the size is zero".

From <https://manpages.debian.org/3/realloc.en.html>:

If size is equal to zero, and ptr is not NULL, then the call is
equivalent to free(ptr) (but see "Nonportable behavior" for
portability issues).

And from the referenced section:

The behavior of these functions when the requested size is zero is
glibc specific; other implementations may return NULL without setting
errno, and portable POSIX programs should tolerate such behavior.

Re: *rubeyes*: realloc(ptr, 0) is UB?

<20240116182230.987@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31057&group=comp.lang.c#31057

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: *rubeyes*: realloc(ptr, 0) is UB?
Date: Wed, 17 Jan 2024 02:32:41 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 52
Message-ID: <20240116182230.987@kylheku.com>
References: <20240116162506.143@kylheku.com> <uo7c5h$1miqe$2@dont-email.me>
Injection-Date: Wed, 17 Jan 2024 02:32:41 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="30353e714807d76ba68823a6307c7dd8";
logging-data="1799567"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/MOOYHMbGrdK3/S/2vzzIROJdAPE4CORk="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:ARymzoCdBG4ZrT4zc8t7d4RekR8=
 by: Kaz Kylheku - Wed, 17 Jan 2024 02:32 UTC

On 2024-01-17, Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
> On Wed, 17 Jan 2024 00:32:10 -0000 (UTC), Kaz Kylheku wrote:
>
>> Nothing about "or if the size is zero".
>
> From <https://manpages.debian.org/3/realloc.en.html>:
>
> If size is equal to zero, and ptr is not NULL, then the call is
> equivalent to free(ptr) (but see "Nonportable behavior" for
> portability issues).

That is just garbage documentation though. No case in realloc
is equivalent to just free(ptr) and nothing else.

> And from the referenced section:
>
> The behavior of these functions when the requested size is zero is
> glibc specific; other implementations may return NULL without setting
> errno, and portable POSIX programs should tolerate such behavior.

None of those choices is simply "undefined behavior". This is just the
old concept that implementations may have malloc(0) returning null, or
else allocate a unique pointer that can be liberated via free.

Previously, realloc(ptr, 0) behaved like free(ptr) followed by
returning the result of malloc(0).

What we see in N3096 is that this resize to zero is undefined behavior,
while malloc(0) remains well-defined.

Thus applications which previously relied on that case of realloc
now have to do this:

void *classic_realloc(void *ptr, size_t size)
{
// Handle zero size case as was required in C99,
// thereby avoiding undefined behavior.

if (size == 0) {
free(ptr);
return malloc(0);
}

// Pass other cases to realloc.
return realloc(ptr, size);
}

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: *rubeyes*: realloc(ptr, 0) is UB?

<uo7g86$1r072$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31061&group=comp.lang.c#31061

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.neodome.net!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo...@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.c
Subject: Re: *rubeyes*: realloc(ptr, 0) is UB?
Date: Wed, 17 Jan 2024 03:06:46 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 5
Message-ID: <uo7g86$1r072$1@dont-email.me>
References: <20240116162506.143@kylheku.com> <uo7c5h$1miqe$2@dont-email.me>
<20240116182230.987@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 17 Jan 2024 03:06:46 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="71e924a53864396a82a319f1f0d5bb71";
logging-data="1933538"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18QRGUPUUHEi9gwRa7cc2yf"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:zKaRe0OoKhzCD+4OISmbLmKbvW8=
 by: Lawrence D'Oliv - Wed, 17 Jan 2024 03:06 UTC

On Wed, 17 Jan 2024 02:32:41 -0000 (UTC), Kaz Kylheku wrote:

> That is just garbage documentation though.

You’re talking about what the C spec says, I’m talking about POSIX.

Re: *rubeyes*: realloc(ptr, 0) is UB?

<20240116190759.413@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31062&group=comp.lang.c#31062

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: *rubeyes*: realloc(ptr, 0) is UB?
Date: Wed, 17 Jan 2024 03:08:22 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <20240116190759.413@kylheku.com>
References: <20240116162506.143@kylheku.com> <uo7c5h$1miqe$2@dont-email.me>
<20240116182230.987@kylheku.com> <uo7g86$1r072$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 17 Jan 2024 03:08:22 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="30353e714807d76ba68823a6307c7dd8";
logging-data="1933942"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18qTeaoomGy0Oblukfr1RPpkVtZWaxWjEs="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:OTgCydi1L/LT8GK/cvU6DLrLgyA=
 by: Kaz Kylheku - Wed, 17 Jan 2024 03:08 UTC

On 2024-01-17, Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
> On Wed, 17 Jan 2024 02:32:41 -0000 (UTC), Kaz Kylheku wrote:
>
>> That is just garbage documentation though.
>
> You’re talking about what the C spec says, I’m talking about POSIX.

Oh, I'm sorry, am I in the wrong newsgroup?

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: *rubeyes*: realloc(ptr, 0) is UB?

<uo7hru$1r6rk$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31064&group=comp.lang.c#31064

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo...@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.c
Subject: Re: *rubeyes*: realloc(ptr, 0) is UB?
Date: Wed, 17 Jan 2024 03:34:22 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 5
Message-ID: <uo7hru$1r6rk$1@dont-email.me>
References: <20240116162506.143@kylheku.com> <uo7c5h$1miqe$2@dont-email.me>
<20240116182230.987@kylheku.com> <uo7g86$1r072$1@dont-email.me>
<20240116190759.413@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 17 Jan 2024 03:34:22 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="71e924a53864396a82a319f1f0d5bb71";
logging-data="1940340"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19iu8fBD1Bf1ZgpJpG4B8T3"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:Kj4em9RO0IfiTPCUVVDDvpa7/UQ=
 by: Lawrence D'Oliv - Wed, 17 Jan 2024 03:34 UTC

On Wed, 17 Jan 2024 03:08:22 -0000 (UTC), Kaz Kylheku wrote:

> Oh, I'm sorry, am I in the wrong newsgroup?

No need to apologize, just leave quietly.

Re: *rubeyes*: realloc(ptr, 0) is UB?

<uo8ake$1v1eq$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31079&group=comp.lang.c#31079

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: *rubeyes*: realloc(ptr, 0) is UB?
Date: Wed, 17 Jan 2024 11:37:02 +0100
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <uo8ake$1v1eq$2@dont-email.me>
References: <20240116162506.143@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 17 Jan 2024 10:37:02 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e5d003c4907c1c313df779ab33f575b8";
logging-data="2065882"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX188PmhBZcWRu5gOSAmXK3cHOaNiP8ZPUz4="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:xfAhn2xbLL/ew0UoR5bEo7e4pFc=
In-Reply-To: <20240116162506.143@kylheku.com>
Content-Language: en-GB
 by: David Brown - Wed, 17 Jan 2024 10:37 UTC

On 17/01/2024 01:32, Kaz Kylheku wrote:
> I'm looking at the C99 and N3096 (April 2023) definitions of realloc
> side by side.
>
> N3096 says
>
> "Otherwise, if ptr does not match a pointer earlier returned by a memory
> management function, or if the space has been deallocated by a call to
> the free or realloc function, or if the size is zero, the behavior is
> undefined."
>
> Yikes! In C99 there is nothing about the size being zero:
>
> "Otherwise, if ptr does not match a pointer earlier returned by the
> calloc, malloc, or realloc function, or if the space has been
> deallocated by a call to the free or realloc function, the behavior is
> undefined."
>
> Nothing about "or if the size is zero".
>
> Yikes; when did this criminal stupidity get perpetrated?
>

Nothing stops a particular library implementation from giving this all a
defined behaviour. It was already "implementation defined" - if you
want to be able to use malloc or realloc with size 0, then you need to
know exactly how your library says it will behave or your code will risk
serious problems.

While I don't know why this change was made, and I agree it sounds a
strange change to make, I cannot see how any code would be affected by
it. Either your code is non-portable and relies on specific behaviour
(documented by your particular library, or additional standards such as
POSIX), or it has portability issues that could lead to failures if it
is used with a library that doesn't match your guessed behaviour - the C
standards making this UB does not change anything.

All this means, in my eyes, is that developers are being encouraged to
take responsibility for size zero allocations in their own code - make
an active choice about how they will deal with it (if it can occur in
their code). After all, there is no single appropriate choice of
behaviour for malloc or realloc of zero size - the best way to handle it
will depend on the user program.

Re: *rubeyes*: realloc(ptr, 0) is UB?

<QdTpN.168167$vFZa.62153@fx13.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31104&group=comp.lang.c#31104

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.furie.org.uk!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx13.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: *rubeyes*: realloc(ptr, 0) is UB?
Newsgroups: comp.lang.c
References: <20240116162506.143@kylheku.com>
Lines: 27
Message-ID: <QdTpN.168167$vFZa.62153@fx13.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Wed, 17 Jan 2024 16:27:28 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Wed, 17 Jan 2024 16:27:28 GMT
X-Received-Bytes: 1643
 by: Scott Lurndal - Wed, 17 Jan 2024 16:27 UTC

Kaz Kylheku <433-929-6894@kylheku.com> writes:
>I'm looking at the C99 and N3096 (April 2023) definitions of realloc
>side by side.
>
>N3096 says
>
>"Otherwise, if ptr does not match a pointer earlier returned by a memory
>management function, or if the space has been deallocated by a call to
>the free or realloc function, or if the size is zero, the behavior is
>undefined."
>
>Yikes! In C99 there is nothing about the size being zero:
>
>"Otherwise, if ptr does not match a pointer earlier returned by the
>calloc, malloc, or realloc function, or if the space has been
>deallocated by a call to the free or realloc function, the behavior is
>undefined."
>
>Nothing about "or if the size is zero".
>
>Yikes; when did this criminal stupidity get perpetrated?

I'm not sure what stupidity you are referring to, but IIRC, there was
some recent standardization activity relating to realloc
when size == 0 because there were differences in the behavior
between different implementations. Making the behavior
undefined was the only rational choice.

Re: *rubeyes*: realloc(ptr, 0) is UB?

<20240117093322.69@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31108&group=comp.lang.c#31108

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: *rubeyes*: realloc(ptr, 0) is UB?
Date: Wed, 17 Jan 2024 17:47:46 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 75
Message-ID: <20240117093322.69@kylheku.com>
References: <20240116162506.143@kylheku.com> <uo8ake$1v1eq$2@dont-email.me>
Injection-Date: Wed, 17 Jan 2024 17:47:46 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="30353e714807d76ba68823a6307c7dd8";
logging-data="2256923"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+e2DVFDkq4CcyJD+F0CKlPifa5LbB6isk="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:TVhfZcSPEw3K9+sy6VTG7OE+I9c=
 by: Kaz Kylheku - Wed, 17 Jan 2024 17:47 UTC

On 2024-01-17, David Brown <david.brown@hesbynett.no> wrote:
> On 17/01/2024 01:32, Kaz Kylheku wrote:
>> Yikes; when did this criminal stupidity get perpetrated?
>>
>
> Nothing stops a particular library implementation from giving this all a
> defined behaviour.

Nothings stops getchar() from being locally defined as an extension;
let's make it undefined behavior!

An entire language can be defined by an implementation, with no
standard.

People use plenty of these and tech marches on.

> It was already "implementation defined" - if you
> want to be able to use malloc or realloc with size 0, then you need to
> know exactly how your library says it will behave or your code will risk
> serious problems.

No, not serious. Very minor problems in a rare combination of
circumstances.

It's possible that realloc(ptr, 0) will return null, and this null
indicates that the reallocation failed due to OOM, meaning that ptr is
still valid.

This situation is indistinguishable from ptr having been freed,
and the null just being the result of a working zero size allocation.

(Implementations can easily resolve the ambiguity internally and
guarantee that realloc(ptr, 0) will free the object, and not
leak ptr.)

> While I don't know why this change was made, and I agree it sounds a
> strange change to make, I cannot see how any code would be affected by
> it. Either your code is non-portable and relies on specific behaviour
> (documented by your particular library, or additional standards such as
> POSIX), or it has portability issues that could lead to failures if it
> is used with a library that doesn't match your guessed behaviour - the C
> standards making this UB does not change anything.

It isn't nonportable. Dynamic array management code can resize an object
down to zero (as an alternative to freeing it). There is no problem with
this (other than the possible ambiguity under OOM conditions). In the
abstract semantics, the old object is freed, and you get a new one as if
from malloc(0).

Code can easily be written not to care whether malloc(0) returns null
or non-null.

> All this means, in my eyes, is that developers are being encouraged to
> take responsibility for size zero allocations in their own code - make

Working code that relies on zero size allocations already (even if
that isn't the best alternative in that code) won't fix itself to become
defined again.

> an active choice about how they will deal with it (if it can occur in
> their code). After all, there is no single appropriate choice of
> behaviour for malloc or realloc of zero size - the best way to handle it
> will depend on the user program.

A malloc of zero size is still defined; only realloc to zero size is
no longer defined. If you pretend that the remark about size zero isn't
there in the description of realloc, the rest of the description of
realloc still says that the old object will be freed, and the new one
will come as if from a malloc request for that size.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: *rubeyes*: realloc(ptr, 0) is UB?

<20240117094759.508@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31110&group=comp.lang.c#31110

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: *rubeyes*: realloc(ptr, 0) is UB?
Date: Wed, 17 Jan 2024 17:57:46 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 57
Message-ID: <20240117094759.508@kylheku.com>
References: <20240116162506.143@kylheku.com>
<QdTpN.168167$vFZa.62153@fx13.iad>
Injection-Date: Wed, 17 Jan 2024 17:57:46 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="30353e714807d76ba68823a6307c7dd8";
logging-data="2256923"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX185aLo5ZoqTdXd2drxJgIIpL5YBnaebVEo="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:f8uOSRnPcuNosUjpD2RNW9jT5Nk=
 by: Kaz Kylheku - Wed, 17 Jan 2024 17:57 UTC

On 2024-01-17, Scott Lurndal <scott@slp53.sl.home> wrote:
> Kaz Kylheku <433-929-6894@kylheku.com> writes:
>>Yikes; when did this criminal stupidity get perpetrated?
>
> I'm not sure what stupidity you are referring to, but IIRC, there was
> some recent standardization activity relating to realloc
> when size == 0 because there were differences in the behavior
> between different implementations. Making the behavior
> undefined was the only rational choice.

No, the rational choice is letting those implementations be
nonconforming, until they fix their shit.

You cannot claw back decades-old defined behaviors in a major
language standard because some players are getting it wrong
in some way.

I now have to do things like this in all the code I work on:

void *sane_realloc(void *ptr, size_t size)
{
if (size == 0) {
free(ptr);
return malloc(0); // don't care if that didn't work
}
return realloc(ptr, size);
}
or, if I don't suspect realloc-to-zero is being used:

void *sane_realloc(void *ptr, size_t size)
{
assert (size != 0);
return realloc(ptr, size);
}

and this is code that will never even run on those rogue implementations
whose botchery lead to the poor decision of the language being damaged.

Any implementation of realloc whatsoever could just do this internally:

void *realloc(void *ptr, size_t size)
{
if (size == 0) {
__free(ptr);
return __malloc(0);
}
// call our internal __realloc implementation that
// we suspect doesn't handle zero.
return __realloc(ptr, size);
}

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: *rubeyes*: realloc(ptr, 0) is UB?

<uo96sl$25d7o$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31117&group=comp.lang.c#31117

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: cr88...@gmail.com (BGB)
Newsgroups: comp.lang.c
Subject: Re: *rubeyes*: realloc(ptr, 0) is UB?
Date: Wed, 17 Jan 2024 12:39:15 -0600
Organization: A noiseless patient Spider
Lines: 112
Message-ID: <uo96sl$25d7o$1@dont-email.me>
References: <20240116162506.143@kylheku.com> <uo8ake$1v1eq$2@dont-email.me>
<20240117093322.69@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 17 Jan 2024 18:39:17 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="72d83e3faebee0d2e852c46a42e91189";
logging-data="2274552"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/HyZTmPPbsVbOv5QZjw69X"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:rS40WeKuPrxxNY6Q/T0V+F9GoG8=
In-Reply-To: <20240117093322.69@kylheku.com>
Content-Language: en-US
 by: BGB - Wed, 17 Jan 2024 18:39 UTC

On 1/17/2024 11:47 AM, Kaz Kylheku wrote:
> On 2024-01-17, David Brown <david.brown@hesbynett.no> wrote:
>> On 17/01/2024 01:32, Kaz Kylheku wrote:
>>> Yikes; when did this criminal stupidity get perpetrated?
>>>
>>
>> Nothing stops a particular library implementation from giving this all a
>> defined behaviour.
>
> Nothings stops getchar() from being locally defined as an extension;
> let's make it undefined behavior!
>
> An entire language can be defined by an implementation, with no
> standard.
>
> People use plenty of these and tech marches on.
>

And then Clang goes and decides to make any use of these functions cause
the whole control-flow path to be pruned from existence or something...
Since, after all, it is UB...

( Partly satire, but wouldn't exactly be surprised... )

>> It was already "implementation defined" - if you
>> want to be able to use malloc or realloc with size 0, then you need to
>> know exactly how your library says it will behave or your code will risk
>> serious problems.
>
> No, not serious. Very minor problems in a rare combination of
> circumstances.
>
> It's possible that realloc(ptr, 0) will return null, and this null
> indicates that the reallocation failed due to OOM, meaning that ptr is
> still valid.
>
> This situation is indistinguishable from ptr having been freed,
> and the null just being the result of a working zero size allocation.
>
> (Implementations can easily resolve the ambiguity internally and
> guarantee that realloc(ptr, 0) will free the object, and not
> leak ptr.)
>

Yeah, find something sensible to do and do it.
Knowing modern compilers, declaring anything as UB throws a big wrench
into things.

>> While I don't know why this change was made, and I agree it sounds a
>> strange change to make, I cannot see how any code would be affected by
>> it. Either your code is non-portable and relies on specific behaviour
>> (documented by your particular library, or additional standards such as
>> POSIX), or it has portability issues that could lead to failures if it
>> is used with a library that doesn't match your guessed behaviour - the C
>> standards making this UB does not change anything.
>
> It isn't nonportable. Dynamic array management code can resize an object
> down to zero (as an alternative to freeing it). There is no problem with
> this (other than the possible ambiguity under OOM conditions). In the
> abstract semantics, the old object is freed, and you get a new one as if
> from malloc(0).
>
> Code can easily be written not to care whether malloc(0) returns null
> or non-null.
>

Yes.

>> All this means, in my eyes, is that developers are being encouraged to
>> take responsibility for size zero allocations in their own code - make
>
> Working code that relies on zero size allocations already (even if
> that isn't the best alternative in that code) won't fix itself to become
> defined again.
>
>> an active choice about how they will deal with it (if it can occur in
>> their code). After all, there is no single appropriate choice of
>> behaviour for malloc or realloc of zero size - the best way to handle it
>> will depend on the user program.
>
> A malloc of zero size is still defined; only realloc to zero size is
> no longer defined. If you pretend that the remark about size zero isn't
> there in the description of realloc, the rest of the description of
> realloc still says that the old object will be freed, and the new one
> will come as if from a malloc request for that size.
>

Agreed.

My personal preference is that behaviors be kept "sensible" when possible.

At least in my own compiler, I generally try for sensible behaviors.
But, within the limit that the compiler may also be buggy...

Finding and fixing bugs is a priority, but as I see it, things like
optimization concerns (or esoteric edge cases) should not be
justification for deviating from otherwise sensible behavior (and
instead limited to cases that would not otherwise be visible to the
program in question).

Granted, I would also prefer it if compilers were not allowed to make
optimizations which may change the visible behavior of a program (at
least within "sane" limits) but, alas... ( Say, we put the burden of
proof on the compiler that an optimization does not change the visible
output or behavior of the program. ).

Re: *rubeyes*: realloc(ptr, 0) is UB?

<9iYpN.354613$83n7.275953@fx18.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31136&group=comp.lang.c#31136

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!rocksolid2!news.neodome.net!tncsrv06.tnetconsulting.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!feeder.usenetexpress.com!tr1.iad1.usenetexpress.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx18.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: *rubeyes*: realloc(ptr, 0) is UB?
Newsgroups: comp.lang.c
References: <20240116162506.143@kylheku.com> <QdTpN.168167$vFZa.62153@fx13.iad> <20240117094759.508@kylheku.com>
Lines: 41
Message-ID: <9iYpN.354613$83n7.275953@fx18.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Wed, 17 Jan 2024 22:13:25 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Wed, 17 Jan 2024 22:13:25 GMT
X-Received-Bytes: 2039
 by: Scott Lurndal - Wed, 17 Jan 2024 22:13 UTC

Kaz Kylheku <433-929-6894@kylheku.com> writes:
>On 2024-01-17, Scott Lurndal <scott@slp53.sl.home> wrote:
>> Kaz Kylheku <433-929-6894@kylheku.com> writes:
>>>Yikes; when did this criminal stupidity get perpetrated?
>>
>> I'm not sure what stupidity you are referring to, but IIRC, there was
>> some recent standardization activity relating to realloc
>> when size == 0 because there were differences in the behavior
>> between different implementations. Making the behavior
>> undefined was the only rational choice.
>
>No, the rational choice is letting those implementations be
>nonconforming, until they fix their shit.
>
>You cannot claw back decades-old defined behaviors in a major

Nobody is clawing anything back. No compiler is going to
change its behavior because undefined behavior is now
called undefined behavior.

Everything that's been done for decades will still work just
fine.

Realloc with a length zero - never - made any sense anyway.

>language standard because some players are getting it wrong
>in some way.
>
>I now have to do things like this in all the code I work on:
>
> void *sane_realloc(void *ptr, size_t size)
> {
> if (size == 0) {
> free(ptr);
> return malloc(0); // don't care if that didn't work
> }
> return realloc(ptr, size);
> }

You can also just never call sane_realloc with a size of zero.

Re: *rubeyes*: realloc(ptr, 0) is UB?

<20240117142105.501@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31139&group=comp.lang.c#31139

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!rocksolid2!news.neodome.net!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: *rubeyes*: realloc(ptr, 0) is UB?
Date: Wed, 17 Jan 2024 22:31:12 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 80
Message-ID: <20240117142105.501@kylheku.com>
References: <20240116162506.143@kylheku.com>
<QdTpN.168167$vFZa.62153@fx13.iad> <20240117094759.508@kylheku.com>
<9iYpN.354613$83n7.275953@fx18.iad>
Injection-Date: Wed, 17 Jan 2024 22:31:12 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="30353e714807d76ba68823a6307c7dd8";
logging-data="2345878"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/XyJ2Al1oEM0j6d373czzvdJNzIcKFIG4="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:kx1//it/rbdv2fwFb/Kx5dywq+U=
 by: Kaz Kylheku - Wed, 17 Jan 2024 22:31 UTC

On 2024-01-17, Scott Lurndal <scott@slp53.sl.home> wrote:
> Kaz Kylheku <433-929-6894@kylheku.com> writes:
>>On 2024-01-17, Scott Lurndal <scott@slp53.sl.home> wrote:
>>> Kaz Kylheku <433-929-6894@kylheku.com> writes:
>>>>Yikes; when did this criminal stupidity get perpetrated?
>>>
>>> I'm not sure what stupidity you are referring to, but IIRC, there was
>>> some recent standardization activity relating to realloc
>>> when size == 0 because there were differences in the behavior
>>> between different implementations. Making the behavior
>>> undefined was the only rational choice.
>>
>>No, the rational choice is letting those implementations be
>>nonconforming, until they fix their shit.
>>
>>You cannot claw back decades-old defined behaviors in a major
>
> Nobody is clawing anything back. No compiler is going to
> change its behavior because undefined behavior is now
> called undefined behavior.

What? The behavior was defined in the absence of the new piece of text
saying that the behavior of realloc is arbitrarily undefined when size
is zero.

> Everything that's been done for decades will still work just
> fine.

Even if nothing changes in the library implementation of realloc, a
highly optimizing compiler can now treat everything after a realloc(ptr,
0) as unreachable code:

void f(void *p)
{
realloc(p, 0);
}

This function can be compiled the same as:

void f(void *p)
{
__builtin_unreachable();
}

This is not something that the library people can keep fully working by
simply not messing with realloc.

> Realloc with a length zero - never - made any sense anyway.

Yes it does; in a dynamic vector type, you can tell the thing to resize
to zero size. If that API is implemented with realloc, it now has
undefined behavior according to n3096.

>>language standard because some players are getting it wrong
>>in some way.
>>
>>I now have to do things like this in all the code I work on:
>>
>> void *sane_realloc(void *ptr, size_t size)
>> {
>> if (size == 0) {
>> free(ptr);
>> return malloc(0); // don't care if that didn't work
>> }
>> return realloc(ptr, size);
>> }
>
> You can also just never call sane_realloc with a size of zero.

That could be more work. You have to identify what does that,
if anything, and fix it.

If your project already has a wrapper for realloc, it's easy
to fix it there.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: *rubeyes*: realloc(ptr, 0) is UB?

<pan$eed53$d5a25673$c4eed852$f5f44c0@invalid.invalid>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31140&group=comp.lang.c#31140

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!bluemanedhawk.eternal-september.org!.POSTED!not-for-mail
From: bluemane...@invalid.invalid (Blue-Maned_Hawk)
Newsgroups: comp.lang.c
Subject: Re: *rubeyes*: realloc(ptr, 0) is UB?
Date: Wed, 17 Jan 2024 23:03:35 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <pan$eed53$d5a25673$c4eed852$f5f44c0@invalid.invalid>
References: <20240116162506.143@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 17 Jan 2024 23:03:35 -0000 (UTC)
Injection-Info: bluemanedhawk.eternal-september.org; posting-host="bc35e6cc09fac6db0005cbef7406e9b1";
logging-data="2342153"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/hfLGDIQ7plcX55Nyokg6ShaYHyzaho+g="
User-Agent: Pan/0.154 (Izium; 517acf4)
Cancel-Lock: sha1:af37yIGGUhZCOrJX1crOS1WefLQ=
Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAIAAADYYG7QAAACh0lEQVRYw71Z21bD
MAzzevbfkr4cHjrSXJyL044+MDa6WLEl2SkvkrZ1AbAvXO+bUGSCPYnsuIVGMpm
ZLnjX718GhAKNsp8lON2F9VrhELwIgJlBepkZjA78rVK+FkmNhEJK76UsJlz8+E
rJsjrpYouhLo/SC6qPHgakFOR8wV9+8rCfO/I/oVnmUZUp42/LW2XkLj9TCFNM9
jp5g2EmHZgpYZjCOkYU7sXVogRylJqpdggoFLG1g09Flah/7kErCxzR9HgXPYsq
0glb9cxjIz2Vsk9AmAoCSxECpD713joMKjQqLAtmMqJmXjdVvlMnMQCVITotJd1
z+fh1f1NNo+vuc1KnhWUmY7t03vydTud9BbXCtN3L2PL3bK7JCNG0GHzuZxafyB
fxevCxpm1vrwZltqw6SILCcdoCE6PGQC8wZWDA9Or7Qp5s3lAZezys0nDazs9S9
R0TjwEiksRxLkNPC1NMMWPs1bj0Ei0Yuo+JVtFLuzP1NRJ16qXWN8DhhtmS4PDg
O6mqRxs4bEJrYt087mSIow/1VzW2oFlMQuiuIy/KsUagvhdw6hSjJGlIavbLF8x
j3X47bccLcUSi0dkWh1nUZNhANT1tHKUXrNxNLbd9KPb9wDDVrKwmPQMOPQ1oy6
k5I1DwzDeRJd3jVIhDAUxq3ngzJG4CCkNXZxZVMcjefoK2J0gUY2S3rxz/RuTFx
2zHd9U+obimJXMG4edsk/2j5pTU5G1MmzbRLxkfq5EiT1GGsidvMGzi+1goGb2l
GCrN+nGnV8xj3q3JLRDVPL96vUc7Z4aJ3TN1mVqWAMJMfG+Jxh6TQqP+92iZkCU
xtglds1AB6r0aiSHKcnFck+p/c/0CbacFLQcajGcAAAAASUVORK5CYII=
X-Face: Llanfair­pwllgwyngyllÃ
ƒ‚Ã
ƒƒ‚­gogery­chwyrnÃ
ƒƒ
? ?‚­drobwll­llan
Ã
? ?ƒƒ‚­tysilio­go
g
o­goch
 by: Blue-Maned_Hawk - Wed, 17 Jan 2024 23:03 UTC

It looks to me like it was always undefined behavior, but it just wasn't
explicitly stated as such in C99. Undefined behavior does not require the
specification to explictly state that the behavior is not defined; it just
has to provide no definition for it.

--
Blue-Maned_Hawk│shortens to
Hawk│/
blu.mɛin.dÊ°ak/
│he/him/his/himself/Mr.
blue-maned_hawk.srht.site
Atlanta makes it against the law to tie a giraffe to a street lamp or
telephone pole.

Re: *rubeyes*: realloc(ptr, 0) is UB?

<20240117160615.197@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31146&group=comp.lang.c#31146

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: *rubeyes*: realloc(ptr, 0) is UB?
Date: Thu, 18 Jan 2024 00:10:58 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <20240117160615.197@kylheku.com>
References: <20240116162506.143@kylheku.com>
<pan$eed53$d5a25673$c4eed852$f5f44c0@invalid.invalid>
Injection-Date: Thu, 18 Jan 2024 00:10:58 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d2d938dda3e1a6a4011b6cb72d132af7";
logging-data="2370459"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Z4RO3vNIp8arIoS3mSZgT4cfavFYYNUs="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:ark+eowfgXCT8KBHbHdEjNABW5U=
 by: Kaz Kylheku - Thu, 18 Jan 2024 00:10 UTC

On 2024-01-17, Blue-Maned_Hawk <bluemanedhawk@invalid.invalid> wrote:
> It looks to me like it was always undefined behavior, but it just wasn't
> explicitly stated as such in C99.

That is incorrect. A behavior for the following can be readily inferred
from C99:

void *p = malloc(42);
void *q = realloc(p, 0);

The p object is freed, and a new object q is obtained as if by
malloc(0). q may be null, or else a pointer to a unique object
that can be freed.

q and p could possibly point to the same address; just like in
a non-zero-sized realloc call.

> Undefined behavior does not require the
> specification to explictly state that the behavior is not defined; it just
> has to provide no definition for it.

A definition is provided by virtue of the size 0 not being special in
any way in realloc. It's defined because the behavior for size 1 is
defined, as for size 2, ...

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: *rubeyes*: realloc(ptr, 0) is UB?

<86cytzl8yd.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31151&group=comp.lang.c#31151

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: *rubeyes*: realloc(ptr, 0) is UB?
Date: Wed, 17 Jan 2024 17:35:38 -0800
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <86cytzl8yd.fsf@linuxsc.com>
References: <20240116162506.143@kylheku.com> <pan$eed53$d5a25673$c4eed852$f5f44c0@invalid.invalid>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="977c44247f598dd571c1b364bfd8c85e";
logging-data="2385981"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+YYuhIPiU27WzG764hsb2qyUrmnY8N1dI="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:PoOpBG63CVsbjXSDbV8H74hDgKk=
sha1:DuqQ3BN/77dZ+3RlN2LLLGkC9rM=
 by: Tim Rentsch - Thu, 18 Jan 2024 01:35 UTC

Blue-Maned_Hawk <bluemanedhawk@invalid.invalid> writes:

> It looks to me like it was always undefined behavior, but it just wasn't
> explicitly stated as such in C99. Undefined behavior does not require the
> specification to explictly state that the behavior is not defined; it just
> has to provide no definition for it.

You are mistaken. The C99 standard, and also the C11 standard,
plainly state that such requests give implementation-defined
behavior:

If the size of the space requested is zero, the behavior is
implementation-defined: either a null pointer is returned,
or the behavior is as if the size were some nonzero value,
except that the returned pointer shall not be used to access
an object.

Re: *rubeyes*: realloc(ptr, 0) is UB?

<868r4nl8t1.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31152&group=comp.lang.c#31152

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: *rubeyes*: realloc(ptr, 0) is UB?
Date: Wed, 17 Jan 2024 17:38:50 -0800
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <868r4nl8t1.fsf@linuxsc.com>
References: <20240116162506.143@kylheku.com> <pan$eed53$d5a25673$c4eed852$f5f44c0@invalid.invalid> <20240117160615.197@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="977c44247f598dd571c1b364bfd8c85e";
logging-data="2385981"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+d6byukRMGG+4O5FsrXXauhJpHr9ieQV8="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:h+lIWQJMDcI541qstqll1BGtcI8=
sha1:YumsfJwaFTE/EqF6vxnyGDPjxJw=
 by: Tim Rentsch - Thu, 18 Jan 2024 01:38 UTC

Kaz Kylheku <433-929-6894@kylheku.com> writes:

> On 2024-01-17, Blue-Maned_Hawk <bluemanedhawk@invalid.invalid> wrote:
>
>> It looks to me like it was always undefined behavior, but it just wasn't
>> explicitly stated as such in C99.
>
> That is incorrect. A behavior for the following can be readily inferred
> from C99:
>
> void *p = malloc(42);
> void *q = realloc(p, 0);
>
> The p object is freed, and a new object q is obtained as if by
> malloc(0). q may be null, or else a pointer to a unique object
> that can be freed.
>
> q and p could possibly point to the same address; just like in
> a non-zero-sized realloc call.
>
>> Undefined behavior does not require the
>> specification to explictly state that the behavior is not defined; it just
>> has to provide no definition for it.
>
> A definition is provided by virtue of the size 0 not being special in
> any way in realloc. It's defined because the behavior for size 1 is
> defined, as for size 2, ...

Actually, a size of 0 is specifically stated as implementation-defined
behavior, in section 7.20.3, paragraph 1 (in N1256), which applies to
all the memory allocation functions, realloc() included.

Re: *rubeyes*: realloc(ptr, 0) is UB?

<864jfbl8ht.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31153&group=comp.lang.c#31153

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!newsfeed.endofthelinebbs.com!news.hispagatos.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: *rubeyes*: realloc(ptr, 0) is UB?
Date: Wed, 17 Jan 2024 17:45:34 -0800
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <864jfbl8ht.fsf@linuxsc.com>
References: <20240116162506.143@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="977c44247f598dd571c1b364bfd8c85e";
logging-data="2385981"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18CoXfs0a+qerTLHgxhy8I5hIVTHy37ShY="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:X3airWBX6WLX6tH9q/RdNGXuCa0=
sha1:Ws0AOstdhkbW/AphKFz5VRYQfSA=
 by: Tim Rentsch - Thu, 18 Jan 2024 01:45 UTC

Kaz Kylheku <433-929-6894@kylheku.com> writes:

> I'm looking at the C99 and N3096 (April 2023) definitions of realloc
> side by side.
>
> N3096 says
>
> "Otherwise, if ptr does not match a pointer earlier returned by a memory
> management function, or if the space has been deallocated by a call to
> the free or realloc function, or if the size is zero, the behavior is
> undefined."
>
> Yikes! In C99 there is nothing about the size being zero:
>
> "Otherwise, if ptr does not match a pointer earlier returned by the
> calloc, malloc, or realloc function, or if the space has been
> deallocated by a call to the free or realloc function, the behavior is
> undefined."
>
> Nothing about "or if the size is zero".
>
> Yikes; when did this criminal stupidity get perpetrated?

I guess you missed the thread from a little while back when
this change was discussed.

During that conversation, I was in complete agreement with
your reaction as stated above. Moreover nothing that has
come to light in the meantime that gives me any reason to
think otherwise.

Re: *rubeyes*: realloc(ptr, 0) is UB?

<86zfx3jtv9.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31154&group=comp.lang.c#31154

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: *rubeyes*: realloc(ptr, 0) is UB?
Date: Wed, 17 Jan 2024 17:46:50 -0800
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <86zfx3jtv9.fsf@linuxsc.com>
References: <20240116162506.143@kylheku.com> <QdTpN.168167$vFZa.62153@fx13.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="977c44247f598dd571c1b364bfd8c85e";
logging-data="2385981"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/lR/hLf+k0Kjy9ODCi+4+9cOww7VxP14E="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:XwWYeWo2Qiu/nztjt06nMl3Q/Pw=
sha1:W8ZpySVQ3FBgYMVtWKmVa+eEvnc=
 by: Tim Rentsch - Thu, 18 Jan 2024 01:46 UTC

scott@slp53.sl.home (Scott Lurndal) writes:

> Kaz Kylheku <433-929-6894@kylheku.com> writes:
>
>> I'm looking at the C99 and N3096 (April 2023) definitions of realloc
>> side by side.
>>
>> N3096 says
>>
>> "Otherwise, if ptr does not match a pointer earlier returned by a memory
>> management function, or if the space has been deallocated by a call to
>> the free or realloc function, or if the size is zero, the behavior is
>> undefined."
>>
>> Yikes! In C99 there is nothing about the size being zero:
>>
>> "Otherwise, if ptr does not match a pointer earlier returned by the
>> calloc, malloc, or realloc function, or if the space has been
>> deallocated by a call to the free or realloc function, the behavior is
>> undefined."
>>
>> Nothing about "or if the size is zero".
>>
>> Yikes; when did this criminal stupidity get perpetrated?
>
> I'm not sure what stupidity you are referring to, but IIRC, there was
> some recent standardization activity relating to realloc
> when size == 0 because there were differences in the behavior
> between different implementations. Making the behavior
> undefined was the only rational choice.

Is that last sentence your own assessment, or are you simply
repeating someone else's assessment?

Re: *rubeyes*: realloc(ptr, 0) is UB?

<uoaee7$2fncb$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31158&group=comp.lang.c#31158

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo...@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.c
Subject: Re: *rubeyes*: realloc(ptr, 0) is UB?
Date: Thu, 18 Jan 2024 05:54:15 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <uoaee7$2fncb$1@dont-email.me>
References: <20240116162506.143@kylheku.com>
<pan$eed53$d5a25673$c4eed852$f5f44c0@invalid.invalid>
<86cytzl8yd.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 18 Jan 2024 05:54:15 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="7b7eb05269adaf47ad0e7a8103a3b8bb";
logging-data="2612619"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/c9FNTUsUGbHStoV5svGeU"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:JtBBVyZ0KN+KnOnEd9szoFTZ+QI=
 by: Lawrence D'Oliv - Thu, 18 Jan 2024 05:54 UTC

On Wed, 17 Jan 2024 17:35:38 -0800, Tim Rentsch wrote:

> The C99 standard, and also the C11 standard,
> plainly state that such requests give implementation-defined behavior:
>
> If the size of the space requested is zero, the behavior is
> implementation-defined: either a null pointer is returned, or the
> behavior is as if the size were some nonzero value, except that the
> returned pointer shall not be used to access an object.

Still, most of us use C on more reasonable, POSIX-type systems, where the
behaviour is somewhat better defined.

Re: *rubeyes*: realloc(ptr, 0) is UB?

<20240117215705.377@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31159&group=comp.lang.c#31159

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: *rubeyes*: realloc(ptr, 0) is UB?
Date: Thu, 18 Jan 2024 05:59:08 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <20240117215705.377@kylheku.com>
References: <20240116162506.143@kylheku.com>
<pan$eed53$d5a25673$c4eed852$f5f44c0@invalid.invalid>
<86cytzl8yd.fsf@linuxsc.com> <uoaee7$2fncb$1@dont-email.me>
Injection-Date: Thu, 18 Jan 2024 05:59:08 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d2d938dda3e1a6a4011b6cb72d132af7";
logging-data="2613321"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19VRXmb8Zj2ndg13oMhc4aiE2VF9UWkXOw="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:RcRFKJEgWb05eETPGWKg/AGEO7o=
 by: Kaz Kylheku - Thu, 18 Jan 2024 05:59 UTC

On 2024-01-18, Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
> On Wed, 17 Jan 2024 17:35:38 -0800, Tim Rentsch wrote:
>
>> The C99 standard, and also the C11 standard,
>> plainly state that such requests give implementation-defined behavior:
>>
>> If the size of the space requested is zero, the behavior is
>> implementation-defined: either a null pointer is returned, or the
>> behavior is as if the size were some nonzero value, except that the
>> returned pointer shall not be used to access an object.
>
> Still, most of us use C on more reasonable, POSIX-type systems, where the
> behaviour is somewhat better defined.

No, it isn't. The above wording is exactly the same in POSIX:

"If the size of the space requested is zero, the behavior shall be
implementation-defined: either a null pointer is returned, or the
behavior shall be as if the size were some non-zero value, except that
the behavior is undefined if the returned pointer is used to access an
object."

https://pubs.opengroup.org/onlinepubs/9699919799/functions/realloc.html

If you find the behavior better defined in your POSIX system, it's
not because of POSIX.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: *rubeyes*: realloc(ptr, 0) is UB?

<uoai97$2g7l3$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31160&group=comp.lang.c#31160

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo...@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.c
Subject: Re: *rubeyes*: realloc(ptr, 0) is UB?
Date: Thu, 18 Jan 2024 06:59:52 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <uoai97$2g7l3$1@dont-email.me>
References: <20240116162506.143@kylheku.com>
<pan$eed53$d5a25673$c4eed852$f5f44c0@invalid.invalid>
<86cytzl8yd.fsf@linuxsc.com> <uoaee7$2fncb$1@dont-email.me>
<20240117215705.377@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 18 Jan 2024 06:59:52 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="7b7eb05269adaf47ad0e7a8103a3b8bb";
logging-data="2629283"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+efcdX/skfWo/nbE0dgakZ"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:rH3o8jy8ut5K6U+ckuCd+dczsek=
 by: Lawrence D'Oliv - Thu, 18 Jan 2024 06:59 UTC

On Thu, 18 Jan 2024 05:59:08 -0000 (UTC), Kaz Kylheku wrote:

> If you find the behavior better defined in your POSIX system, it's not
> because of POSIX.

From <https://manpages.debian.org/3/realloc.en.html>:

If size is equal to zero, and ptr is not NULL, then the call is
equivalent to free(ptr) (but see "Nonportable behavior" for
portability issues).

And from the referenced section:

The behavior of these functions when the requested size is zero is
glibc specific; other implementations may return NULL without setting
errno, and portable POSIX programs should tolerate such behavior.

GNU-specific, then.

Re: *rubeyes*: realloc(ptr, 0) is UB?

<86v87rjbpz.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31161&group=comp.lang.c#31161

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: *rubeyes*: realloc(ptr, 0) is UB?
Date: Thu, 18 Jan 2024 00:18:48 -0800
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <86v87rjbpz.fsf@linuxsc.com>
References: <20240116162506.143@kylheku.com> <pan$eed53$d5a25673$c4eed852$f5f44c0@invalid.invalid> <86cytzl8yd.fsf@linuxsc.com> <uoaee7$2fncb$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="977c44247f598dd571c1b364bfd8c85e";
logging-data="2647707"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+nqIrf5fbJx4w7lzJl/Bg+T9RDDPabhYI="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:FgFpRi+tz7/uVzeUM19hM2CjzEk=
sha1:UcVGwIa9D4wmpLJ/mN8YwsCTkFo=
 by: Tim Rentsch - Thu, 18 Jan 2024 08:18 UTC

Lawrence D'Oliveiro <ldo@nz.invalid> writes:

> On Wed, 17 Jan 2024 17:35:38 -0800, Tim Rentsch wrote:
>
>> The C99 standard, and also the C11 standard,
>> plainly state that such requests give implementation-defined behavior:
>>
>> If the size of the space requested is zero, the behavior is
>> implementation-defined: either a null pointer is returned, or the
>> behavior is as if the size were some nonzero value, except that the
>> returned pointer shall not be used to access an object.
>
> Still, most of us use C on more reasonable, POSIX-type systems, where the
> behaviour is somewhat better defined.

You say that like you think your statement has some relevance to
the issue being discussed. It doesn't.

Re: *rubeyes*: realloc(ptr, 0) is UB?

<86r0ifjbiw.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31162&group=comp.lang.c#31162

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!paganini.bofh.team!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: *rubeyes*: realloc(ptr, 0) is UB?
Date: Thu, 18 Jan 2024 00:23:03 -0800
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <86r0ifjbiw.fsf@linuxsc.com>
References: <20240116162506.143@kylheku.com> <QdTpN.168167$vFZa.62153@fx13.iad> <20240117094759.508@kylheku.com> <9iYpN.354613$83n7.275953@fx18.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="977c44247f598dd571c1b364bfd8c85e";
logging-data="2647707"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1//+zjcm0f1OLB+608oMoa6JYovyhx0C5g="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:HhikT8LbDfJXJiH63OpLitMBWm4=
sha1:o4+VIBWBeziJUInrmJ2MlDEY+oM=
 by: Tim Rentsch - Thu, 18 Jan 2024 08:23 UTC

scott@slp53.sl.home (Scott Lurndal) writes:

> Kaz Kylheku <433-929-6894@kylheku.com> writes:
>
>> On 2024-01-17, Scott Lurndal <scott@slp53.sl.home> wrote:
>>
>>> Kaz Kylheku <433-929-6894@kylheku.com> writes:
>>>
>>>> Yikes; when did this criminal stupidity get perpetrated?
>>>
>>> I'm not sure what stupidity you are referring to, but IIRC, there was
>>> some recent standardization activity relating to realloc
>>> when size == 0 because there were differences in the behavior
>>> between different implementations. Making the behavior
>>> undefined was the only rational choice.
>>
>> No, the rational choice is letting those implementations be
>> nonconforming, until they fix their shit.
>>
>> You cannot claw back decades-old defined behaviors in a major
>
> Nobody is clawing anything back. [...]

This statement seems directly contradicted by the proposed
modification to the C standard, which changes previously
defined behavior to undefined behavior.

Re: *rubeyes*: realloc(ptr, 0) is UB?

<OdbqN.230721$c3Ea.136697@fx10.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=31171&group=comp.lang.c#31171

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!newsreader4.netcologne.de!news.netcologne.de!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx10.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: *rubeyes*: realloc(ptr, 0) is UB?
Newsgroups: comp.lang.c
References: <20240116162506.143@kylheku.com> <QdTpN.168167$vFZa.62153@fx13.iad> <86zfx3jtv9.fsf@linuxsc.com>
Lines: 37
Message-ID: <OdbqN.230721$c3Ea.136697@fx10.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Thu, 18 Jan 2024 15:12:46 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Thu, 18 Jan 2024 15:12:46 GMT
X-Received-Bytes: 2185
 by: Scott Lurndal - Thu, 18 Jan 2024 15:12 UTC

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>scott@slp53.sl.home (Scott Lurndal) writes:
>
>> Kaz Kylheku <433-929-6894@kylheku.com> writes:
>>
>>> I'm looking at the C99 and N3096 (April 2023) definitions of realloc
>>> side by side.
>>>
>>> N3096 says
>>>
>>> "Otherwise, if ptr does not match a pointer earlier returned by a memory
>>> management function, or if the space has been deallocated by a call to
>>> the free or realloc function, or if the size is zero, the behavior is
>>> undefined."
>>>
>>> Yikes! In C99 there is nothing about the size being zero:
>>>
>>> "Otherwise, if ptr does not match a pointer earlier returned by the
>>> calloc, malloc, or realloc function, or if the space has been
>>> deallocated by a call to the free or realloc function, the behavior is
>>> undefined."
>>>
>>> Nothing about "or if the size is zero".
>>>
>>> Yikes; when did this criminal stupidity get perpetrated?
>>
>> I'm not sure what stupidity you are referring to, but IIRC, there was
>> some recent standardization activity relating to realloc
>> when size == 0 because there were differences in the behavior
>> between different implementations. Making the behavior
>> undefined was the only rational choice.
>
>Is that last sentence your own assessment, or are you simply
>repeating someone else's assessment?

My assessment. I've never found realloc useful, regardless of
the value of the size parameter. YMMV.

Pages:1234567
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor