Jim Meyering wrote:
> +2008-10-16  Jim Meyering  <[EMAIL PROTECTED]>
> +
> +     openat-die.c: avoid 'no previous prototype' warning
> +     * lib/openat-die.c: Include "openat.h".
> +     Reported by Reuben Thomas <[EMAIL PROTECTED]>.

Thanks to this change, I now get a compilation error when compiling for mingw:

  i386-pc-mingw32-gcc -DHAVE_CONFIG_H -I. -I..   -Wall  -g -O2 -MT openat-die.o 
-MD -MP -MF .deps/openat-die.Tpo -c -o openat-die.o openat-die.c
  openat-die.c:33: error: conflicting types for 'openat_save_fail'
  openat.h:97: error: previous declaration of 'openat_save_fail' was here

At first sight, the two declarations look the same:

  void openat_save_fail (int)

modulo a 'noreturn` attribute of which we know that it is irrelevant for
function type purposes. The preprocessed output, however, reveals what's
happening:

void
openat_save_fail (int (*_errno()))
{
  error (exit_failure, (*_errno()),
  ((const char *) ("unable to record current working directory")));
...

So the function declared in the header file as taking an 'int' parameter
is now defined with a function pointer parameter, and this function is
immediately invoked. This would have crashed at runtime, trying to transfer
control to a small address in the range 0 < _errno < 200.

Here's a proposed fix:


2008-10-18  Bruno Haible  <[EMAIL PROTECTED]>

        * lib/openat-die.c (openat_save_fail, openat_restore_fail): Rename
        the parameter from 'errno' to 'errnum'. Fixes a compilation error on
        mingw.

--- lib/openat-die.c.orig       2008-10-19 02:42:49.000000000 +0200
+++ lib/openat-die.c    2008-10-19 02:40:41.000000000 +0200
@@ -29,9 +29,9 @@
 #define N_(msgid) msgid
 
 void
-openat_save_fail (int errno)
+openat_save_fail (int errnum)
 {
-  error (exit_failure, errno,
+  error (exit_failure, errnum,
         _("unable to record current working directory"));
 
   /* The `noreturn' attribute cannot be applied to error, since it returns
@@ -42,9 +42,9 @@
 }
 
 void
-openat_restore_fail (int errno)
+openat_restore_fail (int errnum)
 {
-  error (exit_failure, errno,
+  error (exit_failure, errnum,
         _("failed to return to initial working directory"));
 
   /* As above.  */



Reply via email to