[Top][All Lists]

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

Re: getline() behaviour change

From: Jim Meyering
Subject: Re: getline() behaviour change
Date: Wed, 22 Aug 2007 23:46:39 +0200

Hi Bruno,

Thanks for all the reviews.
I haven't had time to look at the rest, but the following stood out:

Bruno Haible <address@hidden> wrote:
> The POSIX spec implies that errno should be set when getdelim fails. Therefore
> errno needs to be set not only here, with EOVERFLOW. In lines 77 and 113
> errno should be set to ENOMEM, since errno is undefined upon return from
> malloc() or realloc().

Are you advocating support for non-POSIX malloc/realloc?
A *lot* of code expects malloc and realloc to set errno when they fail.

POSIX guarantees that errno is defined when malloc or realloc
fails, so there's no need to set it manually in that case.
Here are the two blocks of code you mention:

      *lineptr = (char *) realloc (*lineptr, 120);
      if (*lineptr == NULL)
          result = -1;
          goto unlock_return;
          new_lineptr = (char *) realloc (*lineptr, needed);
          if (new_lineptr == NULL)
              result = -1;
              goto unlock_return;

in each case, realloc fails, so errno is defined.

However, there is a related problem.
Here's the target of those "goto" statements:

  funlockfile (fp);
  return result;

Upon failure, on a system with the funlockfile function,
the errno value from a failed realloc may be clobbered
by that funlockfile call.  So when HAVE_FUNLOCKFILE != 0,
it should save and restore errno around that funlockfile call.

reply via email to

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