[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-tar] Error "Cannot allocate memory" incorrectly reported in som
From: |
Paul Eggert |
Subject: |
Re: [Bug-tar] Error "Cannot allocate memory" incorrectly reported in some cases. |
Date: |
Fri, 28 Oct 2005 16:07:53 -0700 |
User-agent: |
Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux) |
"Sergey Poznyakoff" <address@hidden> writes:
> --- lib/savedir.c 19 Sep 2005 17:28:15 -0000 1.26
> +++ lib/savedir.c 28 Oct 2005 12:39:06 -0000
> @@ -104,6 +104,7 @@ savedir (const char *dir)
> while (allocated <= used + entry_size);
>
> name_space = xrealloc (name_space, allocated);
> + errno = 0;
> }
> memcpy (name_space + used, entry, entry_size);
> used += entry_size;
Thanks for the diagnosis, but the fix isn't quite right in general,
since the C standard says memcpy can set errno as well.
I installed this patch instead, both in gnulib and coreutils.
2005-10-28 Paul Eggert <address@hidden>
* lib/savedir.c (savedir): Don't assume that xrealloc etc. leave
errno alone. Problem reported by Frederic Jolliton.
--- lib/savedir.c 19 Sep 2005 17:28:15 -0000 1.26
+++ lib/savedir.c 28 Oct 2005 23:01:41 -0000
@@ -70,7 +70,6 @@ char *
savedir (const char *dir)
{
DIR *dirp;
- struct dirent *dp;
char *name_space;
size_t allocated = NAME_SIZE_DEFAULT;
size_t used = 0;
@@ -82,12 +81,19 @@ savedir (const char *dir)
name_space = xmalloc (allocated);
- errno = 0;
- while ((dp = readdir (dirp)) != NULL)
+ for (;;)
{
+ struct dirent const *dp;
+ char const *entry;
+
+ errno = 0;
+ dp = readdir (dirp);
+ if (! dp)
+ break;
+
/* Skip "", ".", and "..". "" is returned by at least one buggy
implementation: Solaris 2.4 readdir on NFS file systems. */
- char const *entry = dp->d_name;
+ entry = dp->d_name;
if (entry[entry[0] != '.' ? 0 : entry[1] != '.' ? 1 : 2] != '\0')
{
size_t entry_size = strlen (entry) + 1;