* error.c (error_tail): Move some declarations
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 27 Sep 2003 05:11:56 +0000 (05:11 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 27 Sep 2003 05:11:56 +0000 (05:11 +0000)
into inner scope where the local variables are used.

lib/ChangeLog
lib/error.c

index 987ae0a..dea641c 100644 (file)
@@ -1,3 +1,8 @@
+2003-09-26  Jim Meyering  <jim@meyering.net>
+
+       * error.c (error_tail): Move some declarations
+       into inner scope where the local variables are used.
+
 2003-09-26  Bruno Haible  <bruno@clisp.org>
 
        * stpncpy.h (gnu_stpncpy): New declaration.
 
        * error.c (SIZE_MAX) [!defined SIZE_MAX]: Define.
        (error_tail): Do not loop, reallocating temporary buffer, since
-       the original size is big enough.  This avoids one potential size
-       overflow calculation.  Check for size overflow when calculating
-       temporary buffer size.  Free temporary buffer when done, if
-       it was allocated with malloc; this closes a memory leak.
+       the output cannot contain more wide characters than the input
+       contains bytes, the size must be big enough already.  This avoids
+       one potential size overflow calculation.  Check for size overflow
+       when calculating temporary buffer size.  Free temporary buffer
+       when done, if it was allocated with malloc; this plugs a memory
+       leak.  Remove casts from void * to pointers, that are no longer
+       needed now that we're assuming C89 or better.
 
        Merge error changes from glibc.
 
index 1c74a14..16228c4 100644 (file)
@@ -147,9 +147,6 @@ error_tail (int status, int errnum, const char *message, va_list args)
 # define ALLOCA_LIMIT 2000
       size_t len = strlen (message) + 1;
       const wchar_t *wmessage = L"out of memory";
-      mbstate_t st;
-      size_t res;
-      const char *tmp;
       wchar_t *wbuf = (len < ALLOCA_LIMIT
                       ? (void *) alloca (len * sizeof *wbuf)
                       : len <= SIZE_MAX / sizeof *wbuf
@@ -158,8 +155,10 @@ error_tail (int status, int errnum, const char *message, va_list args)
 
       if (wbuf)
        {
+         size_t res;
+         mbstate_t st;
+         const char *tmp = message;
          memset (&st, '\0', sizeof (st));
-         tmp =message;
          res = mbsrtowcs (wbuf, &tmp, len, &st);
          wmessage = res == (size_t) -1 ? L"???" : wbuf;
        }