Просмотр исходного кода

use inttypes to avoid suprises with different type sizes

David Kalnischkies лет назад: 15
Родитель
Сommit
2cae0ccb49
1 измененных файлов с 8 добавлено и 2 удалено
  1. 8 2
      apt-pkg/contrib/fileutl.cc

+ 8 - 2
apt-pkg/contrib/fileutl.cc

@@ -42,6 +42,10 @@
 #include <errno.h>
 #include <set>
 #include <algorithm>
+
+#ifndef WORDS_BIGENDIAN
+#include <inttypes.h>
+#endif
 									/*}}}*/
 
 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
-       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)