[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
yesno fails with optimization and gcc>=4.7 on x86_64
From: |
Allan McRae |
Subject: |
yesno fails with optimization and gcc>=4.7 on x86_64 |
Date: |
Tue, 05 Feb 2013 22:21:30 +1000 |
User-agent: |
Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130109 Thunderbird/17.0.2 |
Hi,
Compiling with -O2 generate codes which mangles the return value from
the yesno function, causing the overwrite prompt to ignore 'n'.
To reproduce:
$ echo "original" >out
$ gzip out
$ echo "replaced" >out
$ gzip out
gzip: out.gz already exists; do you wish to overwrite (y or n)? n
$ gzip -cd out.gz
replaced
This can be seen in Arch Linux and Fedora 18 x86_64 builds (and likely
any other distribution using gcc-4.7)
A very helpful person in the gcc bug tracker [1] pointed out it was
probably yesno being declared with two different function declarations.
And sure enough, the gnulib one declares with bool and gzip.h uses int
as the return value.
[1] http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56211
The following fixes this for me:
2013-02-05 Allan McRae <address@hidden>
* gzip.h: Return bool from yesno to be consistent with gnulib.
diff -Naur gzip-1.5-orig/gzip.h gzip-1.5/gzip.h
--- gzip-1.5-orig/gzip.h 2012-01-01 18:53:58.000000000 +1000
+++ gzip-1.5/gzip.h 2013-02-05 22:08:44.498810902 +1000
@@ -42,6 +42,7 @@
#include <sys/types.h> /* for off_t */
#include <time.h>
#include <string.h>
+#include <stdbool.h>
#define memzero(s, n) memset ((voidp)(s), 0, (n))
#ifndef RETSIGTYPE
@@ -323,4 +324,4 @@
extern int inflate (void);
/* in yesno.c */
-extern int yesno (void);
+extern bool yesno (void);
- yesno fails with optimization and gcc>=4.7 on x86_64,
Allan McRae <=