]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Fixes for GCC 4.7.0
authorDan McGee <dan@archlinux.org>
Tue, 27 Mar 2012 22:22:40 +0000 (17:22 -0500)
committerTim Kientzle <kientzle@acm.org>
Tue, 3 Apr 2012 15:32:43 +0000 (08:32 -0700)
Fixes the following compile error exposed with GCC 4.7.0:

    libarchive/archive_string.c: In function 'cesu8_to_unicode':
    libarchive/archive_string.c:2450:11: error: 'wc' may be used uninitialized in this function [-Werror=uninitialized]
    cc1: all warnings being treated as errors

As well as a test failure that depends on signed integer wraparound,
which is a very bad thing to do in C [1]. Mark the intermediate result
as volatile to prevent the compiler optimizing away the arithmetic and
the logical test.

[1] http://www.gnu.org/software/autoconf/manual/autoconf-2.67/html_node/Signed-Overflow-Examples.html

libarchive/archive_string.c
libarchive/test/test_read_format_mtree.c

index 2728a376c6696606148e342caa4c9632e0cff47e..2b56a48eedba002b380c449ec861258ead0377ed 100644 (file)
@@ -2447,11 +2447,12 @@ combine_surrogate_pair(uint32_t uc, uint32_t uc2)
 static int
 cesu8_to_unicode(uint32_t *pwc, const char *s, size_t n)
 {
-       uint32_t wc, wc2;
+       uint32_t wc = 0;
        int cnt;
 
        cnt = _utf8_to_unicode(&wc, s, n);
        if (cnt == 3 && IS_HIGH_SURROGATE_LA(wc)) {
+               uint32_t wc2 = 0;
                if (n - 3 < 3) {
                        /* Invalid byte sequence. */
                        goto invalid_sequence;
index 0d86bd4788c7bbe7180af38ad4f1e5f3d68b06a0..a5d7febe1763a197d9ecd9dc8d878cd0cbcbe9f8 100644 (file)
@@ -37,7 +37,8 @@ test_read_format_mtree1(void)
         * without relying on overflow.  This assumes that long long
         * is at least 64 bits. */
        static const long long max_int64 = ((((long long)1) << 62) - 1) + (((long long)1) << 62);
-       time_t min_time, t;
+       time_t min_time;
+       volatile time_t t;
 
        extract_reference_file(reffile);