ckolivas / lrzip

Long Range Zip
http://lrzip.kolivas.org
GNU General Public License v2.0
618 stars 76 forks source link

lrzip-0.621 fails to build on ARMv7: : narrowing conversion of '-1' from 'int' to 'char' inside { } [-Wnarrowing] #46

Closed ppisar closed 8 years ago

ppisar commented 8 years ago

lrzip cannot be built on ARMv7 with GCC 6:

  CXX      libzpaq.lo
libzpaq/libzpaq.cpp: In member function 'void libzpaq::Compressor::startBlock(int)':
libzpaq/libzpaq.cpp:1480:6: error: narrowing conversion of '-1' from 'int' to 'char' inside { } [-Wnarrowing]
   0,0}; // 0,0 = end of list
      ^
libzpaq/libzpaq.cpp:1480:6: error: narrowing conversion of '-49' from 'int' to 'char' inside { } [-Wnarrowing]
libzpaq/libzpaq.cpp:1480:6: error: narrowing conversion of '-60' from 'int' to 'char' inside { } [-Wnarrowing]
libzpaq/libzpaq.cpp:1480:6: error: narrowing conversion of '-96' from 'int' to 'char' inside { } [-Wnarrowing]
libzpaq/libzpaq.cpp:1480:6: error: narrowing conversion of '-1' from 'int' to 'char' inside { } [-Wnarrowing]
libzpaq/libzpaq.cpp:1480:6: error: narrowing conversion of '-1' from 'int' to 'char' inside { } [-Wnarrowing]
libzpaq/libzpaq.cpp:1480:6: error: narrowing conversion of '-1' from 'int' to 'char' inside { } [-Wnarrowing]
libzpaq/libzpaq.cpp:1480:6: error: narrowing conversion of '-1' from 'int' to 'char' inside { } [-Wnarrowing]
libzpaq/libzpaq.cpp:1480:6: error: narrowing conversion of '-1' from 'int' to 'char' inside { } [-Wnarrowing]
libzpaq/libzpaq.cpp:1480:6: error: narrowing conversion of '-73' from 'int' to 'char' inside { } [-Wnarrowing]
libzpaq/libzpaq.cpp:1480:6: error: narrowing conversion of '-17' from 'int' to 'char' inside { } [-Wnarrowing]
libzpaq/libzpaq.cpp:1480:6: error: narrowing conversion of '-25' from 'int' to 'char' inside { } [-Wnarrowing]
libzpaq/libzpaq.cpp:1480:6: error: narrowing conversion of '-122' from 'int' to 'char' inside { } [-Wnarrowing]
libzpaq/libzpaq.cpp:1480:6: error: narrowing conversion of '-105' from 'int' to 'char' inside { } [-Wnarrowing]
libzpaq/libzpaq.cpp:1480:6: error: narrowing conversion of '-33' from 'int' to 'char' inside { } [-Wnarrowing]
libzpaq/libzpaq.cpp:1480:6: error: narrowing conversion of '-113' from 'int' to 'char' inside { } [-Wnarrowing]
libzpaq/libzpaq.cpp:1480:6: error: narrowing conversion of '-44' from 'int' to 'char' inside { } [-Wnarrowing]
libzpaq/libzpaq.cpp:1480:6: error: narrowing conversion of '-113' from 'int' to 'char' inside { } [-Wnarrowing]
libzpaq/libzpaq.cpp:1480:6: error: narrowing conversion of '-40' from 'int' to 'char' inside { } [-Wnarrowing]
libzpaq/libzpaq.cpp:1480:6: error: narrowing conversion of '-81' from 'int' to 'char' inside { } [-Wnarrowing]
libzpaq/libzpaq.cpp:1480:6: error: narrowing conversion of '-49' from 'int' to 'char' inside { } [-Wnarrowing]
Makefile:813: recipe for target 'libzpaq.lo' failed

This is because of a warning in newly default c++11 mode. On ARM, the char is unsigned, thus negative values cannot be represented in int type.

ppisar commented 8 years ago

This patch silents the warnings:

From ed3601dabbb6b55a2b94bf37bbd6bb9e826328e1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Thu, 18 Feb 2016 15:36:09 +0100
Subject: [PATCH] Cast negative values in models definiton
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

models is array of chars. char's signess is implementation specific.
It's unsigned on ARMv7. Unsigned char cannot represent negative values.
GCC 6 complains about it:

    narrowing conversion of '-1' from 'int' to 'char' inside { } [-Wnarrowing]

This can be reproduced with older GCC or by:

   ./configure CXXFLAGS='-Wnarrowing -funsigned-char'

This patch casts the negative values explicitly because changing the
type to signed char[] would change prototypes of public methods.

Signed-off-by: Petr Písař <ppisar@redhat.com>
---
 libzpaq/libzpaq.cpp | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/libzpaq/libzpaq.cpp b/libzpaq/libzpaq.cpp
index ea411f1..633c6f1 100644
--- a/libzpaq/libzpaq.cpp
+++ b/libzpaq/libzpaq.cpp
@@ -1458,23 +1458,23 @@ void Compressor::startBlock(int level) {
   // Model 2 - mid.cfg
   69,0,3,3,0,0,8,3,5,8,13,0,8,17,1,8,
   18,2,8,18,3,8,19,4,4,22,24,7,16,0,7,24,
-  -1,0,17,104,74,4,95,1,59,112,10,25,59,112,10,25,
+  (char)-1,0,17,104,74,4,95,1,59,112,10,25,59,112,10,25,
   59,112,10,25,59,112,10,25,59,112,10,25,59,10,59,112,
-  25,69,-49,8,112,56,0,
+  25,69,(char)-49,8,112,56,0,

   // Model 3 - max.cfg
-  -60,0,5,9,0,0,22,1,-96,3,5,8,13,1,8,16,
+  (char)-60,0,5,9,0,0,22,1,(char)-96,3,5,8,13,1,8,16,
   2,8,18,3,8,19,4,8,19,5,8,20,6,4,22,24,
   3,17,8,19,9,3,13,3,13,3,13,3,14,7,16,0,
-  15,24,-1,7,8,0,16,10,-1,6,0,15,16,24,0,9,
-  8,17,32,-1,6,8,17,18,16,-1,9,16,19,32,-1,6,
+  15,24,(char)-1,7,8,0,16,10,(char)-1,6,0,15,16,24,0,9,
+  8,17,32,(char)-1,6,8,17,18,16,(char)-1,9,16,19,32,(char)-1,6,
   0,19,20,16,0,0,17,104,74,4,95,2,59,112,10,25,
   59,112,10,25,59,112,10,25,59,112,10,25,59,112,10,25,
-  59,10,59,112,10,25,59,112,10,25,69,-73,32,-17,64,47,
-  14,-25,91,47,10,25,60,26,48,-122,-105,20,112,63,9,70,
-  -33,0,39,3,25,112,26,52,25,25,74,10,4,59,112,25,
-  10,4,59,112,25,10,4,59,112,25,65,-113,-44,72,4,59,
-  112,8,-113,-40,8,68,-81,60,60,25,69,-49,9,112,25,25,
+  59,10,59,112,10,25,59,112,10,25,69,(char)-73,32,(char)-17,64,47,
+  14,(char)-25,91,47,10,25,60,26,48,(char)-122,(char)-105,20,112,63,9,70,
+  (char)-33,0,39,3,25,112,26,52,25,25,74,10,4,59,112,25,
+  10,4,59,112,25,10,4,59,112,25,65,(char)-113,(char)-44,72,4,59,
+  112,8,(char)-113,(char)-40,8,68,(char)-81,60,60,25,69,(char)-49,9,112,25,25,
   25,25,25,112,56,0,

   0,0}; // 0,0 = end of list
-- 
2.5.0
ckolivas commented 8 years ago

Applied. Couldn't extract your patch from github this way so I've manually patched it and used your changelog.