On 2024-07-29 07:35, Bruno Haible wrote:
    What can happen with the result pointer ptr if
      asprintf (&ptr, ...)
    fails? There are four possibilities:

      (a) ptr is unchanged.
      (b) ptr is set to NULL.
      (c) ptr is set to a non-NULL pointer that is not free()able.
      (d) ptr is set to a non-NULL pointer that is freshly allocated
          and thus meant to be freed.

    It is quite obvious that no reasonable implementation will do (c) nor (d).
    (c) because that would be an invitation for doing free(invalid_pointer).

Actually (c) might be better, as that would be more likely to catch bugs in programs. That is, asprintf could set ptr to ((void *) 42) so that the resulting mistaken 'free' traps. This might be helpful, at least as a debugging option.

However, that's lower priority. More important:


As usual, we can have a *-gnu variant of the modules. The question is
whether such a change in behaviour is worth all the implementation effort.

I'm not quite following this. We already have vasprintf-gnu, and since the glibc behavior is changing to set ptr to NULL it shouldn't be much implementation effort to add that to the vasprintf-gnu module. Similarly for Gnulib's own modules like c-vaszprintf-gnu. What am I missing here?

Reply via email to