Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #380924

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

From Tim Rentsch <tr.17687@z991.linuxsc.com>
Newsgroups comp.lang.c
Subject Re: *rubeyes*: realloc(ptr, 0) is UB?
Date 2024-01-25 09:08 -0800
Organization A noiseless patient Spider
Message-ID <867cjxe3y2.fsf@linuxsc.com> (permalink)
References (10 earlier) <87r0iech8j.fsf@nosuchdomain.example.com> <uoem42$39ohi$2@dont-email.me> <20240119132728.888@kylheku.com> <86edebhrl6.fsf@linuxsc.com> <20240121092107.281@kylheku.com>

Show all headers | View raw


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

> On 2024-01-21, Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
>
>> Kaz Kylheku <433-929-6894@kylheku.com> writes:
>>
>> [.. considering the behavior of malloc(0) ..]
>>
>>> [If] implentations could have a single dedicated object for
>>> representing empty allocations (which can be passed to free any
>>> number of times), that would also be a nice requirement.
>>
>> That defeats the whole purpose of having malloc(0) return
>> a non-null value.  Don't you understand anything?
>
> I undertand very clearly from past disccussions that you're attached
> to a particular use case whereby malloc(0) returns unique objects.

What I like or don't like has nothing to do with it.  The motivating
principle comes from the group that originally advocated it (one of
whom was Doug McIlroy, IIRC), long before there ever was a C
standard.

> However, I don't see that as the purpose, let alone the "whole
> purpose".

Then I suggest you read up more on the history of the early
discussions.

> The standard currently does not endorse malloc(0) as a factory
> for unique pointers.

The C standard requires that all non-null return values from the
memory allocation functions be distinct:  "Each such allocation
shall yield a pointer to an object disjoint from any other object."
See, eg, section 7.20.3, paragraph 1, in n1256.

> Currently, it cannot be relied on due to the possibility of the null
> return.  If you want that behavior portably, you currently have to
> use malloc(1) instead, or some other nonzero value.  Even if your
> program detects that malloc(0) returns a non-null pointer one time,
> there is no requirement that all subsequent such allocations will
> return non-null.

Your understanding of the term "implementation-defined" is flawed.
Each implementation must make a particular choice and stick to it.
In cases where the choice is allowed to vary the C standard uses
different language, as for example "in an implementation-defined
manner".  Note also the item in Annex J.3.12:  "Whether the calloc,
malloc, and realloc functions return a null pointer or a pointer to
an allocated object when the size requested is zero".  Not "when" or
"under what circumstances" but "whether".  Granted, text in Annex J
is non-normative, but surely it reflects the meaning intended by the
C standard's authors.

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Re: *rubeyes*: realloc(ptr, 0) is UB? James Kuyper <jameskuyper@alumni.caltech.edu> - 2024-01-18 15:01 -0500
  Re: *rubeyes*: realloc(ptr, 0) is UB? Kaz Kylheku <433-929-6894@kylheku.com> - 2024-01-18 22:43 +0000
    Re: *rubeyes*: realloc(ptr, 0) is UB? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-01-18 15:14 -0800
    Re: *rubeyes*: realloc(ptr, 0) is UB? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-01-18 16:13 -0800
      Re: *rubeyes*: realloc(ptr, 0) is UB? Kaz Kylheku <433-929-6894@kylheku.com> - 2024-01-19 03:06 +0000
        Re: *rubeyes*: realloc(ptr, 0) is UB? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-01-21 03:47 -0800
          Re: *rubeyes*: realloc(ptr, 0) is UB? Richard Kettlewell <invalid@invalid.invalid> - 2024-01-22 10:21 +0000
            Re: *rubeyes*: realloc(ptr, 0) is UB? Kaz Kylheku <433-929-6894@kylheku.com> - 2024-01-22 18:54 +0000
            Re: *rubeyes*: realloc(ptr, 0) is UB? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-01-22 20:01 -0800
              Re: *rubeyes*: realloc(ptr, 0) is UB? Richard Kettlewell <invalid@invalid.invalid> - 2024-01-23 09:35 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-01-23 09:08 -0800
                Re: *rubeyes*: realloc(ptr, 0) is UB? Kaz Kylheku <433-929-6894@kylheku.com> - 2024-01-23 21:56 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-01-26 05:51 -0800
                Re: *rubeyes*: realloc(ptr, 0) is UB? Richard Kettlewell <invalid@invalid.invalid> - 2024-01-24 23:37 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-01-26 07:54 -0800
                Re: *rubeyes*: realloc(ptr, 0) is UB? Richard Kettlewell <invalid@invalid.invalid> - 2024-01-26 21:04 +0000
      Re: *rubeyes*: realloc(ptr, 0) is UB? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-01-19 20:29 +0000
        Re: *rubeyes*: realloc(ptr, 0) is UB? Kaz Kylheku <433-929-6894@kylheku.com> - 2024-01-19 21:35 +0000
          Re: *rubeyes*: realloc(ptr, 0) is UB? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-01-21 03:08 -0800
            Re: *rubeyes*: realloc(ptr, 0) is UB? Kaz Kylheku <433-929-6894@kylheku.com> - 2024-01-21 17:32 +0000
              Re: *rubeyes*: realloc(ptr, 0) is UB? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-01-25 09:08 -0800
                Re: *rubeyes*: realloc(ptr, 0) is UB? Kaz Kylheku <433-929-6894@kylheku.com> - 2024-01-25 18:49 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-01-25 11:35 -0800
                Re: *rubeyes*: realloc(ptr, 0) is UB? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-01-25 11:45 -0800
                Re: *rubeyes*: realloc(ptr, 0) is UB? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-01-25 13:40 -0800
                Re: *rubeyes*: realloc(ptr, 0) is UB? David Brown <david.brown@hesbynett.no> - 2024-01-26 09:27 +0100
                Re: *rubeyes*: realloc(ptr, 0) is UB? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-01-29 13:21 -0800
                Re: *rubeyes*: realloc(ptr, 0) is UB? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-01-26 12:20 -0800
                Re: *rubeyes*: realloc(ptr, 0) is UB? Kaz Kylheku <433-929-6894@kylheku.com> - 2024-01-28 18:17 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-01-31 01:02 -0800
                Re: *rubeyes*: realloc(ptr, 0) is UB? James Kuyper <jameskuyper@alumni.caltech.edu> - 2024-01-28 20:09 -0500
        Re: *rubeyes*: realloc(ptr, 0) is UB? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-01-19 13:37 -0800
          Re: *rubeyes*: realloc(ptr, 0) is UB? Kaz Kylheku <433-929-6894@kylheku.com> - 2024-01-19 21:50 +0000
            Re: *rubeyes*: realloc(ptr, 0) is UB? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-01-19 14:16 -0800
              Re: *rubeyes*: realloc(ptr, 0) is UB? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-01-21 03:25 -0800
            Re: *rubeyes*: realloc(ptr, 0) is UB? bart <bc@freeuk.com> - 2024-01-21 11:55 +0000
              Re: *rubeyes*: realloc(ptr, 0) is UB? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-01-21 09:41 -0800
              Re: *rubeyes*: realloc(ptr, 0) is UB? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-01-21 12:22 -0800
                Re: *rubeyes*: realloc(ptr, 0) is UB? bart <bc@freeuk.com> - 2024-01-21 20:34 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? David Brown <david.brown@hesbynett.no> - 2024-01-21 21:54 +0100
                Re: *rubeyes*: realloc(ptr, 0) is UB? Kaz Kylheku <433-929-6894@kylheku.com> - 2024-01-21 21:20 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? David Brown <david.brown@hesbynett.no> - 2024-01-22 09:20 +0100
                Re: *rubeyes*: realloc(ptr, 0) is UB? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-01-21 13:31 -0800
                Re: *rubeyes*: realloc(ptr, 0) is UB? Kaz Kylheku <433-929-6894@kylheku.com> - 2024-01-21 21:49 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? bart <bc@freeuk.com> - 2024-01-21 22:09 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2024-01-21 23:49 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? David Brown <david.brown@hesbynett.no> - 2024-01-22 09:24 +0100
                Re: *rubeyes*: realloc(ptr, 0) is UB? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-01-22 22:09 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? David Brown <david.brown@hesbynett.no> - 2024-01-23 09:28 +0100
                Re: *rubeyes*: realloc(ptr, 0) is UB? bart <bc@freeuk.com> - 2024-01-21 21:37 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-01-21 17:05 -0800
                Re: *rubeyes*: realloc(ptr, 0) is UB? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-01-21 17:09 -0800
                Re: *rubeyes*: realloc(ptr, 0) is UB? Kaz Kylheku <433-929-6894@kylheku.com> - 2024-01-21 21:16 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-01-21 17:14 -0800
                Re: *rubeyes*: realloc(ptr, 0) is UB? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-01-21 17:04 -0800
                Re: *rubeyes*: realloc(ptr, 0) is UB? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2024-01-22 02:05 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-01-21 18:37 -0800
                Re: *rubeyes*: realloc(ptr, 0) is UB? bart <bc@freeuk.com> - 2024-01-22 11:55 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? bart <bc@freeuk.com> - 2024-01-22 12:00 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-01-22 22:08 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2024-01-21 20:51 +0000
              Re: *rubeyes*: realloc(ptr, 0) is UB? Richard Kettlewell <invalid@invalid.invalid> - 2024-01-22 10:22 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? bart <bc@freeuk.com> - 2024-01-22 11:27 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? Kaz Kylheku <433-929-6894@kylheku.com> - 2024-01-22 19:36 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? kalevi@kolttonen.fi (Kalevi Kolttonen) - 2024-01-22 20:40 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? bart <bc@freeuk.com> - 2024-01-22 22:14 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-01-22 14:38 -0800
                Re: *rubeyes*: realloc(ptr, 0) is UB? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-01-22 14:40 -0800
                Re: *rubeyes*: realloc(ptr, 0) is UB? scott@slp53.sl.home (Scott Lurndal) - 2024-01-22 22:45 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-01-22 14:54 -0800
                Re: *rubeyes*: realloc(ptr, 0) is UB? Richard Kettlewell <invalid@invalid.invalid> - 2024-01-22 23:05 +0000
            Re: *rubeyes*: realloc(ptr, 0) is UB? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-01-21 04:04 -0800
              Re: *rubeyes*: realloc(ptr, 0) is UB? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2024-01-22 12:36 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-01-22 08:23 -0800
                Re: *rubeyes*: realloc(ptr, 0) is UB? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-01-22 08:27 -0800
                Re: *rubeyes*: realloc(ptr, 0) is UB? scott@slp53.sl.home (Scott Lurndal) - 2024-01-22 16:34 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-01-24 04:42 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? Spiros Bousbouras <spibou@gmail.com> - 2024-01-22 19:23 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-01-22 20:20 -0800
          Re: *rubeyes*: realloc(ptr, 0) is UB? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-01-21 06:55 -0800
      Re: *rubeyes*: realloc(ptr, 0) is UB? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-01-20 19:50 -0800
        Re: *rubeyes*: realloc(ptr, 0) is UB? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-01-21 05:11 +0000
          Re: *rubeyes*: realloc(ptr, 0) is UB? Kaz Kylheku <433-929-6894@kylheku.com> - 2024-01-21 05:20 +0000
            Re: *rubeyes*: realloc(ptr, 0) is UB? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-01-21 14:38 -0800
        Re: *rubeyes*: realloc(ptr, 0) is UB? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-01-21 14:33 -0800
          Re: *rubeyes*: realloc(ptr, 0) is UB? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-01-21 15:04 -0800
            Re: *rubeyes*: realloc(ptr, 0) is UB? Richard Kettlewell <invalid@invalid.invalid> - 2024-01-22 08:12 +0000
              Re: *rubeyes*: realloc(ptr, 0) is UB? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-01-22 08:06 -0800
                Re: *rubeyes*: realloc(ptr, 0) is UB? Richard Kettlewell <invalid@invalid.invalid> - 2024-01-22 18:17 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? scott@slp53.sl.home (Scott Lurndal) - 2024-01-22 18:43 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? Richard Kettlewell <invalid@invalid.invalid> - 2024-01-22 19:11 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-01-24 02:46 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? scott@slp53.sl.home (Scott Lurndal) - 2024-01-24 14:54 +0000
              Re: *rubeyes*: realloc(ptr, 0) is UB? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-01-22 20:08 -0800
            Re: *rubeyes*: realloc(ptr, 0) is UB? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-01-23 19:28 -0800
              Re: *rubeyes*: realloc(ptr, 0) is UB? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-01-24 06:33 +0000
                Re: *rubeyes*: realloc(ptr, 0) is UB? Kaz Kylheku <433-929-6894@kylheku.com> - 2024-01-24 07:46 +0000
              Re: *rubeyes*: realloc(ptr, 0) is UB? Kaz Kylheku <433-929-6894@kylheku.com> - 2024-01-24 07:44 +0000
              Re: *rubeyes*: realloc(ptr, 0) is UB? David Brown <david.brown@hesbynett.no> - 2024-01-24 10:41 +0100
                Re: *rubeyes*: realloc(ptr, 0) is UB? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-01-24 08:34 -0800
                Re: *rubeyes*: realloc(ptr, 0) is UB? James Kuyper <jameskuyper@alumni.caltech.edu> - 2024-01-24 12:23 -0500
      Re: *rubeyes*: realloc(ptr, 0) is UB? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-01-21 05:10 -0800

csiph-web