emmanuel-marty / apultra

Free open-source compressor for apLib with 5-7% better ratios

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gcc 6.3.0 gives warning: comparison of unsigned expression < 0 is always false

ecm-pushbx opened this issue · comments

Getting this warning when compiling expand.c on a Debian 9 server with gcc 6.3.0

@ulukai:~/proj/apultra$ make
clang -O3 -g -fomit-frame-pointer -Isrc/libdivsufsort/include -Isrc -c src/../src/apultra.c -o obj/src/apultra.o
clang -O3 -g -fomit-frame-pointer -Isrc/libdivsufsort/include -Isrc -c src/../src/expand.c -o obj/src/expand.o
src/../src/expand.c:103:19: warning: comparison of unsigned expression < 0 is
      always false [-Wtautological-compare]
      if (nResult < 0) return -1;
          ~~~~~~~ ^ ~
src/../src/expand.c:118:22: warning: comparison of unsigned expression < 0 is
      always false [-Wtautological-compare]
         if (nResult < 0) return -1;
             ~~~~~~~ ^ ~
src/../src/expand.c:148:25: warning: comparison of unsigned expression < 0 is
      always false [-Wtautological-compare]
            if (nResult < 0) return -1;
                ~~~~~~~ ^ ~
src/../src/expand.c:173:28: warning: comparison of unsigned expression < 0 is
      always false [-Wtautological-compare]
               if (nResult < 0) return -1;
                   ~~~~~~~ ^ ~
src/../src/expand.c:177:28: warning: comparison of unsigned expression < 0 is
      always false [-Wtautological-compare]
               if (nResult < 0) return -1;
                   ~~~~~~~ ^ ~
src/../src/expand.c:181:28: warning: comparison of unsigned expression < 0 is
      always false [-Wtautological-compare]
               if (nResult < 0) return -1;
                   ~~~~~~~ ^ ~
src/../src/expand.c:185:28: warning: comparison of unsigned expression < 0 is
      always false [-Wtautological-compare]
               if (nResult < 0) return -1;
                   ~~~~~~~ ^ ~
src/../src/expand.c:228:19: warning: comparison of unsigned expression < 0 is
      always false [-Wtautological-compare]
      if (nResult < 0) return -1;
          ~~~~~~~ ^ ~
src/../src/expand.c:242:22: warning: comparison of unsigned expression < 0 is
      always false [-Wtautological-compare]
         if (nResult < 0) return -1;
             ~~~~~~~ ^ ~
src/../src/expand.c:309:25: warning: comparison of unsigned expression < 0 is
      always false [-Wtautological-compare]
            if (nResult < 0) return -1;
                ~~~~~~~ ^ ~
src/../src/expand.c:355:28: warning: comparison of unsigned expression < 0 is
      always false [-Wtautological-compare]
               if (nResult < 0) return -1;
                   ~~~~~~~ ^ ~
src/../src/expand.c:359:28: warning: comparison of unsigned expression < 0 is
      always false [-Wtautological-compare]
               if (nResult < 0) return -1;
                   ~~~~~~~ ^ ~
src/../src/expand.c:363:28: warning: comparison of unsigned expression < 0 is
      always false [-Wtautological-compare]
               if (nResult < 0) return -1;
                   ~~~~~~~ ^ ~
src/../src/expand.c:367:28: warning: comparison of unsigned expression < 0 is
      always false [-Wtautological-compare]
               if (nResult < 0) return -1;
                   ~~~~~~~ ^ ~
14 warnings generated.

gcc version:

gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

This patch appears to fix the problem:

diff --git a/src/expand.c b/src/expand.c
index 76b3bf1..b65409d 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -97,7 +97,7 @@ size_t apultra_get_max_decompressed_size(const unsigned char *pInputData, size_t
    nDecompressedSize++;
 
    while (1) {
-      unsigned int nResult;
+      int nResult;
 
       nResult = apultra_read_bit(&pInputData, pInputDataEnd, &nCurBitMask, &bits);
       if (nResult < 0) return -1;
@@ -222,7 +222,7 @@ size_t apultra_decompress(const unsigned char *pInputData, unsigned char *pOutDa
    *pCurOutData++ = *pInputData++;
 
    while (1) {
-      unsigned int nResult;
+      int nResult;
 
       nResult = apultra_read_bit(&pInputData, pInputDataEnd, &nCurBitMask, &bits);
       if (nResult < 0) return -1;

Thank you so much! Fixed the warning