Bruno Haible <[EMAIL PROTECTED]> wrote:
>> > "rm d" should fail at
>> > remove.c:1094 with "cannot remove 'd': Is a directory"
>> > but fails there with "cannot remove 'd': No such file or diectory"
>
> remove.c:1094 reads like this:
>
> error (0, errno, _("cannot remove %s"),
> quote (full_filename (filename)));
>
> _() and quote() preserve errno, but full_filename () does not: it calls
> realloc() and free().
Good catch. I've fixed that:
>From 035a5ca2b0fb83ca179ed7739e18bb60437bc525 Mon Sep 17 00:00:00 2001
From: Jim Meyering <[EMAIL PROTECTED]>
Date: Sun, 7 Oct 2007 21:55:42 +0200
Subject: [PATCH] Don't let a helper function modify errno.
* src/remove.c (full_filename_): Save and restore errno.
Spotted by Bruno Haible.
Signed-off-by: Jim Meyering <[EMAIL PROTECTED]>
---
ChangeLog | 4 ++++
src/remove.c | 6 +++++-
2 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 157f126..1c3b257 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2007-10-07 Jim Meyering <[EMAIL PROTECTED]>
+ Don't let a helper function modify errno.
+ * src/remove.c (full_filename_): Save and restore errno.
+ Spotted by Bruno Haible.
+
Reflect 2->3 GPL copyright version update in gnulib.
* gl/lib/tempname.h: Update copyright from gnulib.
* gl/lib/tempname.c: Likewise.
diff --git a/src/remove.c b/src/remove.c
index 3cbfe66..4f91dd4 100644
--- a/src/remove.c
+++ b/src/remove.c
@@ -305,7 +305,8 @@ right_justify (char *dst, size_t dst_len, const char *src,
size_t src_len,
/* Using the global directory name obstack, create the full name FILENAME.
Return it in sometimes-realloc'd space that should not be freed by the
caller. Realloc as necessary. If realloc fails, use a static buffer
- and put as long a suffix in that buffer as possible. */
+ and put as long a suffix in that buffer as possible. Be careful not
+ to change errno. */
#define full_filename(Filename) full_filename_ (ds, Filename)
static char *
@@ -313,6 +314,7 @@ full_filename_ (Dirstack_state const *ds, const char
*filename)
{
static char *buf = NULL;
static size_t n_allocated = 0;
+ int saved_errno = errno;
size_t dir_len = obstack_object_size (&ds->dir_stack);
char *dir_name = obstack_base (&ds->dir_stack);
@@ -350,6 +352,7 @@ full_filename_ (Dirstack_state const *ds, const char
*filename)
memcpy (static_buf, ELLIPSES_PREFIX,
sizeof (ELLIPSES_PREFIX) - 1);
}
+ errno = saved_errno;
return p;
}
@@ -372,6 +375,7 @@ full_filename_ (Dirstack_state const *ds, const char
*filename)
assert (strlen (buf) + 1 == n_bytes_needed);
}
+ errno = saved_errno;
return buf;
}
--
1.5.3.4.206.g58ba4