]> git.saurik.com Git - apt.git/commitdiff
use inttypes to avoid suprises with different type sizes
authorDavid Kalnischkies <kalnischkies@gmail.com>
Mon, 14 Feb 2011 10:20:48 +0000 (11:20 +0100)
committerDavid Kalnischkies <kalnischkies@gmail.com>
Mon, 14 Feb 2011 10:20:48 +0000 (11:20 +0100)
apt-pkg/contrib/fileutl.cc

index 6a621e2a9d9d987d4b23be82f995ac5ab6a8bd21..24e3f08d9367ea6f97de2915b5ba60465de55cc4 100644 (file)
 #include <errno.h>
 #include <set>
 #include <algorithm>
 #include <errno.h>
 #include <set>
 #include <algorithm>
+
+#ifndef WORDS_BIGENDIAN
+#include <inttypes.h>
+#endif
                                                                        /*}}}*/
 
 using namespace std;
                                                                        /*}}}*/
 
 using namespace std;
@@ -967,8 +971,10 @@ unsigned long FileFd::Size()
           return _error->Errno("read","Unable to read original size of gzipped file");
 
 #ifdef WORDS_BIGENDIAN
           return _error->Errno("read","Unable to read original size of gzipped file");
 
 #ifdef WORDS_BIGENDIAN
-       unsigned char const * const p = (unsigned char *) &size;
-       size = (p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0];
+       uint32_t tmp_size = size;
+       uint8_t const * const p = (uint8_t const * const) &tmp_size;
+       tmp_size = (p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0];
+       size = tmp_size;
 #endif
 
        if (lseek(iFd, orig_pos, SEEK_SET) < 0)
 #endif
 
        if (lseek(iFd, orig_pos, SEEK_SET) < 0)