Bläddra i källkod

Base256ToNum: Fix uninitialized value

If the inner Base256ToNum() returned false, it did not set
Num to a new value, causing it to be uninitialized, and thus
might have caused the function to exit despite a good result.

Also document why the Res = Num, if (Res != Num) magic is done.

Reported-By: valgrind
Julian Andres Klode 10 år sedan
förälder
incheckning
cf7503d8a0
1 ändrade filer med 2 tillägg och 1 borttagningar
  1. 2 1
      apt-pkg/contrib/strutl.cc

+ 2 - 1
apt-pkg/contrib/strutl.cc

@@ -1171,10 +1171,11 @@ bool Base256ToNum(const char *Str,unsigned long long &Res,unsigned int Len)
    tar files */
 bool Base256ToNum(const char *Str,unsigned long &Res,unsigned int Len)
 {
-   unsigned long long Num;
+   unsigned long long Num = 0;
    bool rc;
 
    rc = Base256ToNum(Str, Num, Len);
+   // rudimentary check for overflow (Res = ulong, Num = ulonglong)
    Res = Num;
    if (Res != Num)
       return false;