Commit 5d4cad9c02e9d4f31477fed0e3b20b35c83936f8

Authored by Jay Berkenbilt
1 parent 24e2b2b7

ABI change: fix use of off_t, size_t, and integer types

Significantly improve the code's use of off_t for file offsets, size_t
for memory sizes, and integer types in cases where there has to be
compatibility with external interfaces.  Rework sections of the code
that would have prevented qpdf from working on files larger than 2 (or
maybe 4) GB in size.
Showing 66 changed files with 315 additions and 240 deletions
1 Next 1 Next
2 ==== 2 ====
3 3
4 - * Get rid of off_t. size_t is okay. Use autoconf to figure out what  
5 - type to use for offsets.  
6 -  
7 - * Get rid of int/size_t/off_t inconsistencies. MSVC 2010 can find  
8 - these if you add /w14267 to the compilation. We might want to do  
9 - this by default. The easiest way to fix this on Windows is to  
10 - modify msvc.mk to add this to both cl /c lines and run  
11 -  
12 - make 2>&1 | tee build.log  
13 -  
14 - * Deal with portability issues from gcc 4.7. See portability.patch  
15 - from debian package. 4 +*** ABI changes have been made. build.mk has been updated.
16 5
17 * Do a Windows 64-bit build. MSVC 2010 Professional x86_64 verified 6 * Do a Windows 64-bit build. MSVC 2010 Professional x86_64 verified
18 to build and test cleanly in 2.3.1. Hopefully the next release 7 to build and test cleanly in 2.3.1. Hopefully the next release
19 will include 64-bit binary distributions and external libraries. 8 will include 64-bit binary distributions and external libraries.
20 9
21 - * Provide an option to copy encryption parameters from another file.  
22 - This would make it possible to decrypt a file, manually work with  
23 - it, and then re-encrypt it using the original encryption parameters  
24 - including a possibly unknown owner password.  
25 -  
26 - * See if I can support the new encryption formats mentioned in the  
27 - open bug on sourceforge. Check other sourceforge bugs.  
28 -  
29 -  
30 -Better 64-bit support on Windows  
31 -================================  
32 -  
33 * Building 64-bit libraries with MSVC works with existing build.sh as 10 * Building 64-bit libraries with MSVC works with existing build.sh as
34 long as the x86_64 version of the compiler is in the path. 11 long as the x86_64 version of the compiler is in the path.
35 Currently this generates 32-bit mingw and 64-bit msvc. We need to 12 Currently this generates 32-bit mingw and 64-bit msvc. We need to
@@ -38,16 +15,13 @@ Better 64-bit support on Windows @@ -38,16 +15,13 @@ Better 64-bit support on Windows
38 only been verified with MSVC 2010 so far; we still need to get it 15 only been verified with MSVC 2010 so far; we still need to get it
39 working with 64-bit mingw. 16 working with 64-bit mingw.
40 17
41 - * Get rid of int/size_t/off_t inconsistencies. MSVC 2010 can find  
42 - these if you add /w14267 to the compilation. We might want to do  
43 - this by default. The easiest way to fix this on Windows is to  
44 - modify msvc.mk to add this to both cl /c lines and run  
45 -  
46 - make 2>&1 | tee build.log  
47 -  
48 - Then, from emacs, compile with command cat build.log. 18 + * Provide an option to copy encryption parameters from another file.
  19 + This would make it possible to decrypt a file, manually work with
  20 + it, and then re-encrypt it using the original encryption parameters
  21 + including a possibly unknown owner password.
49 22
50 - This will probably require ABI changes, but it seems worth doing. 23 + * See if I can support the new encryption formats mentioned in the
  24 + open bug on sourceforge. Check other sourceforge bugs.
51 25
52 26
53 General 27 General
configure.ac
@@ -37,8 +37,29 @@ if test "$BUILD_INTERNAL_LIBS" = "0"; then @@ -37,8 +37,29 @@ if test "$BUILD_INTERNAL_LIBS" = "0"; then
37 AC_SEARCH_LIBS(pcre_compile,pcre,,[MISSING_PCRE=1; MISSING_ANY=1]) 37 AC_SEARCH_LIBS(pcre_compile,pcre,,[MISSING_PCRE=1; MISSING_ANY=1])
38 fi 38 fi
39 39
  40 +AC_SYS_LARGEFILE
  41 +AC_FUNC_FSEEKO
40 AC_TYPE_UINT16_T 42 AC_TYPE_UINT16_T
41 AC_TYPE_UINT32_T 43 AC_TYPE_UINT32_T
  44 +
  45 +AC_MSG_CHECKING(for whether printf supports %ll)
  46 +AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
  47 +#include <stdio.h>
  48 +#include <string.h>
  49 +#include <sys/types.h>
  50 +int
  51 +main()
  52 +{
  53 + long long a = 160591605916059ll;
  54 + char t[50];
  55 + sprintf(t, "%lld", a);
  56 +}
  57 +]])],[qpdf_PRINTF_LL=yes],[qpdf_PRINTF_LL=no])
  58 +AC_MSG_RESULT($qpdf_PRINTF_LL)
  59 +if test "$qpdf_PRINTF_LL" = "yes"; then
  60 + AC_DEFINE([HAVE_PRINTF_LL], [1], [Whether printf supports %ll])
  61 +fi
  62 +
42 AC_CHECK_FUNCS(random) 63 AC_CHECK_FUNCS(random)
43 64
44 # Check if LD supports linker scripts, and define conditional 65 # Check if LD supports linker scripts, and define conditional
include/qpdf/Buffer.hh
@@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
9 #define __BUFFER_HH__ 9 #define __BUFFER_HH__
10 10
11 #include <qpdf/DLL.h> 11 #include <qpdf/DLL.h>
  12 +#include <cstring> // for size_t
12 13
13 class Buffer 14 class Buffer
14 { 15 {
@@ -19,12 +20,12 @@ class Buffer @@ -19,12 +20,12 @@ class Buffer
19 // Create a Buffer object whose memory is owned by the class and 20 // Create a Buffer object whose memory is owned by the class and
20 // will be freed when the Buffer object is destroyed. 21 // will be freed when the Buffer object is destroyed.
21 QPDF_DLL 22 QPDF_DLL
22 - Buffer(unsigned long size); 23 + Buffer(size_t size);
23 24
24 // Create a Buffer object whose memory is owned by the caller and 25 // Create a Buffer object whose memory is owned by the caller and
25 // will not be freed when the Buffer is destroyed. 26 // will not be freed when the Buffer is destroyed.
26 QPDF_DLL 27 QPDF_DLL
27 - Buffer(unsigned char* buf, unsigned long size); 28 + Buffer(unsigned char* buf, size_t size);
28 29
29 QPDF_DLL 30 QPDF_DLL
30 Buffer(Buffer const&); 31 Buffer(Buffer const&);
@@ -33,19 +34,19 @@ class Buffer @@ -33,19 +34,19 @@ class Buffer
33 QPDF_DLL 34 QPDF_DLL
34 ~Buffer(); 35 ~Buffer();
35 QPDF_DLL 36 QPDF_DLL
36 - unsigned long getSize() const; 37 + size_t getSize() const;
37 QPDF_DLL 38 QPDF_DLL
38 unsigned char const* getBuffer() const; 39 unsigned char const* getBuffer() const;
39 QPDF_DLL 40 QPDF_DLL
40 unsigned char* getBuffer(); 41 unsigned char* getBuffer();
41 42
42 private: 43 private:
43 - void init(unsigned long size, unsigned char* buf, bool own_memory); 44 + void init(size_t size, unsigned char* buf, bool own_memory);
44 void copy(Buffer const&); 45 void copy(Buffer const&);
45 void destroy(); 46 void destroy();
46 47
47 bool own_memory; 48 bool own_memory;
48 - unsigned long size; 49 + size_t size;
49 unsigned char* buf; 50 unsigned char* buf;
50 }; 51 };
51 52
include/qpdf/Pipeline.hh
@@ -46,7 +46,7 @@ class Pipeline @@ -46,7 +46,7 @@ class Pipeline
46 // and then, if they are not end-of-line pipelines, call 46 // and then, if they are not end-of-line pipelines, call
47 // getNext()->write or getNext()->finish. 47 // getNext()->write or getNext()->finish.
48 QPDF_DLL 48 QPDF_DLL
49 - virtual void write(unsigned char* data, int len) = 0; 49 + virtual void write(unsigned char* data, size_t len) = 0;
50 QPDF_DLL 50 QPDF_DLL
51 virtual void finish() = 0; 51 virtual void finish() = 0;
52 52
include/qpdf/Pl_Buffer.hh
@@ -32,7 +32,7 @@ class Pl_Buffer: public Pipeline @@ -32,7 +32,7 @@ class Pl_Buffer: public Pipeline
32 QPDF_DLL 32 QPDF_DLL
33 virtual ~Pl_Buffer(); 33 virtual ~Pl_Buffer();
34 QPDF_DLL 34 QPDF_DLL
35 - virtual void write(unsigned char*, int); 35 + virtual void write(unsigned char*, size_t);
36 QPDF_DLL 36 QPDF_DLL
37 virtual void finish(); 37 virtual void finish();
38 38
include/qpdf/Pl_Count.hh
@@ -12,6 +12,7 @@ @@ -12,6 +12,7 @@
12 // calling finish(). 12 // calling finish().
13 13
14 #include <qpdf/Pipeline.hh> 14 #include <qpdf/Pipeline.hh>
  15 +#include <qpdf/Types.h>
15 16
16 class Pl_Count: public Pipeline 17 class Pl_Count: public Pipeline
17 { 18 {
@@ -21,19 +22,19 @@ class Pl_Count: public Pipeline @@ -21,19 +22,19 @@ class Pl_Count: public Pipeline
21 QPDF_DLL 22 QPDF_DLL
22 virtual ~Pl_Count(); 23 virtual ~Pl_Count();
23 QPDF_DLL 24 QPDF_DLL
24 - virtual void write(unsigned char*, int); 25 + virtual void write(unsigned char*, size_t);
25 QPDF_DLL 26 QPDF_DLL
26 virtual void finish(); 27 virtual void finish();
27 // Returns the number of bytes written 28 // Returns the number of bytes written
28 QPDF_DLL 29 QPDF_DLL
29 - int getCount() const; 30 + off_t getCount() const;
30 // Returns the last character written, or '\0' if no characters 31 // Returns the last character written, or '\0' if no characters
31 // have been written (in which case getCount() returns 0) 32 // have been written (in which case getCount() returns 0)
32 QPDF_DLL 33 QPDF_DLL
33 unsigned char getLastChar() const; 34 unsigned char getLastChar() const;
34 35
35 private: 36 private:
36 - int count; 37 + off_t count;
37 unsigned char last_char; 38 unsigned char last_char;
38 }; 39 };
39 40
include/qpdf/Pl_Discard.hh
@@ -24,7 +24,7 @@ class Pl_Discard: public Pipeline @@ -24,7 +24,7 @@ class Pl_Discard: public Pipeline
24 QPDF_DLL 24 QPDF_DLL
25 virtual ~Pl_Discard(); 25 virtual ~Pl_Discard();
26 QPDF_DLL 26 QPDF_DLL
27 - virtual void write(unsigned char*, int); 27 + virtual void write(unsigned char*, size_t);
28 QPDF_DLL 28 QPDF_DLL
29 virtual void finish(); 29 virtual void finish();
30 }; 30 };
include/qpdf/Pl_Flate.hh
@@ -24,7 +24,7 @@ class Pl_Flate: public Pipeline @@ -24,7 +24,7 @@ class Pl_Flate: public Pipeline
24 virtual ~Pl_Flate(); 24 virtual ~Pl_Flate();
25 25
26 QPDF_DLL 26 QPDF_DLL
27 - virtual void write(unsigned char* data, int len); 27 + virtual void write(unsigned char* data, size_t len);
28 QPDF_DLL 28 QPDF_DLL
29 virtual void finish(); 29 virtual void finish();
30 30
include/qpdf/Pl_StdioFile.hh
@@ -29,7 +29,7 @@ class Pl_StdioFile: public Pipeline @@ -29,7 +29,7 @@ class Pl_StdioFile: public Pipeline
29 virtual ~Pl_StdioFile(); 29 virtual ~Pl_StdioFile();
30 30
31 QPDF_DLL 31 QPDF_DLL
32 - virtual void write(unsigned char* buf, int len); 32 + virtual void write(unsigned char* buf, size_t len);
33 QPDF_DLL 33 QPDF_DLL
34 virtual void finish(); 34 virtual void finish();
35 35
include/qpdf/QPDF.hh
@@ -388,7 +388,7 @@ class QPDF @@ -388,7 +388,7 @@ class QPDF
388 virtual off_t tell() = 0; 388 virtual off_t tell() = 0;
389 virtual void seek(off_t offset, int whence) = 0; 389 virtual void seek(off_t offset, int whence) = 0;
390 virtual void rewind() = 0; 390 virtual void rewind() = 0;
391 - virtual size_t read(char* buffer, int length) = 0; 391 + virtual size_t read(char* buffer, size_t length) = 0;
392 virtual void unreadCh(char ch) = 0; 392 virtual void unreadCh(char ch) = 0;
393 393
394 protected: 394 protected:
@@ -405,7 +405,7 @@ class QPDF @@ -405,7 +405,7 @@ class QPDF
405 virtual off_t tell(); 405 virtual off_t tell();
406 virtual void seek(off_t offset, int whence); 406 virtual void seek(off_t offset, int whence);
407 virtual void rewind(); 407 virtual void rewind();
408 - virtual size_t read(char* buffer, int length); 408 + virtual size_t read(char* buffer, size_t length);
409 virtual void unreadCh(char ch); 409 virtual void unreadCh(char ch);
410 410
411 private: 411 private:
@@ -428,7 +428,7 @@ class QPDF @@ -428,7 +428,7 @@ class QPDF
428 virtual off_t tell(); 428 virtual off_t tell();
429 virtual void seek(off_t offset, int whence); 429 virtual void seek(off_t offset, int whence);
430 virtual void rewind(); 430 virtual void rewind();
431 - virtual size_t read(char* buffer, int length); 431 + virtual size_t read(char* buffer, size_t length);
432 virtual void unreadCh(char ch); 432 virtual void unreadCh(char ch);
433 433
434 private: 434 private:
@@ -490,7 +490,7 @@ class QPDF @@ -490,7 +490,7 @@ class QPDF
490 PointerHolder<InputSource> input, int objid, int generation, 490 PointerHolder<InputSource> input, int objid, int generation,
491 bool in_object_stream, 491 bool in_object_stream,
492 bool in_array, bool in_dictionary); 492 bool in_array, bool in_dictionary);
493 - int recoverStreamLength( 493 + size_t recoverStreamLength(
494 PointerHolder<InputSource> input, int objid, int generation, 494 PointerHolder<InputSource> input, int objid, int generation,
495 off_t stream_offset); 495 off_t stream_offset);
496 QPDFTokenizer::Token readToken(PointerHolder<InputSource>); 496 QPDFTokenizer::Token readToken(PointerHolder<InputSource>);
include/qpdf/QPDFObjectHandle.hh
@@ -327,7 +327,7 @@ class QPDFObjectHandle @@ -327,7 +327,7 @@ class QPDFObjectHandle
327 // object must be dictionary object 327 // object must be dictionary object
328 static QPDFObjectHandle newStream( 328 static QPDFObjectHandle newStream(
329 QPDF* qpdf, int objid, int generation, 329 QPDF* qpdf, int objid, int generation,
330 - QPDFObjectHandle stream_dict, off_t offset, int length) 330 + QPDFObjectHandle stream_dict, off_t offset, size_t length)
331 { 331 {
332 return QPDFObjectHandle::newStream( 332 return QPDFObjectHandle::newStream(
333 qpdf, objid, generation, stream_dict, offset, length); 333 qpdf, objid, generation, stream_dict, offset, length);
@@ -371,7 +371,7 @@ class QPDFObjectHandle @@ -371,7 +371,7 @@ class QPDFObjectHandle
371 static QPDFObjectHandle newIndirect(QPDF*, int objid, int generation); 371 static QPDFObjectHandle newIndirect(QPDF*, int objid, int generation);
372 static QPDFObjectHandle newStream( 372 static QPDFObjectHandle newStream(
373 QPDF* qpdf, int objid, int generation, 373 QPDF* qpdf, int objid, int generation,
374 - QPDFObjectHandle stream_dict, off_t offset, int length); 374 + QPDFObjectHandle stream_dict, off_t offset, size_t length);
375 375
376 void assertInitialized() const; 376 void assertInitialized() const;
377 void assertType(char const* type_name, bool istype); 377 void assertType(char const* type_name, bool istype);
include/qpdf/QPDFWriter.hh
@@ -21,6 +21,7 @@ @@ -21,6 +21,7 @@
21 21
22 #include <qpdf/DLL.h> 22 #include <qpdf/DLL.h>
23 #include <qpdf/Constants.h> 23 #include <qpdf/Constants.h>
  24 +#include <qpdf/Types.h>
24 25
25 #include <qpdf/QPDFXRefEntry.hh> 26 #include <qpdf/QPDFXRefEntry.hh>
26 27
@@ -219,7 +220,7 @@ class QPDFWriter @@ -219,7 +220,7 @@ class QPDFWriter
219 void writePad(int nspaces); 220 void writePad(int nspaces);
220 void assignCompressedObjectNumbers(int objid); 221 void assignCompressedObjectNumbers(int objid);
221 void enqueueObject(QPDFObjectHandle object); 222 void enqueueObject(QPDFObjectHandle object);
222 - void writeObjectStreamOffsets(std::vector<int>& offsets, int first_obj); 223 + void writeObjectStreamOffsets(std::vector<off_t>& offsets, int first_obj);
223 void writeObjectStream(QPDFObjectHandle object); 224 void writeObjectStream(QPDFObjectHandle object);
224 void writeObject(QPDFObjectHandle object, int object_stream_index = -1); 225 void writeObject(QPDFObjectHandle object, int object_stream_index = -1);
225 void writeTrailer(trailer_e which, int size, 226 void writeTrailer(trailer_e which, int size,
@@ -229,7 +230,7 @@ class QPDFWriter @@ -229,7 +230,7 @@ class QPDFWriter
229 void unparseObject(QPDFObjectHandle object, int level, 230 void unparseObject(QPDFObjectHandle object, int level,
230 unsigned int flags, 231 unsigned int flags,
231 // for stream dictionaries 232 // for stream dictionaries
232 - int stream_length, bool compress); 233 + size_t stream_length, bool compress);
233 void unparseChild(QPDFObjectHandle child, int level, int flags); 234 void unparseChild(QPDFObjectHandle child, int level, int flags);
234 void initializeSpecialStreams(); 235 void initializeSpecialStreams();
235 void preserveObjectStreams(); 236 void preserveObjectStreams();
@@ -266,8 +267,8 @@ class QPDFWriter @@ -266,8 +267,8 @@ class QPDFWriter
266 int prev, 267 int prev,
267 bool suppress_offsets, 268 bool suppress_offsets,
268 int hint_id, 269 int hint_id,
269 - int hint_offset,  
270 - int hint_length); 270 + off_t hint_offset,
  271 + off_t hint_length);
271 int writeXRefStream(int objid, int max_id, int max_offset, 272 int writeXRefStream(int objid, int max_id, int max_offset,
272 trailer_e which, int first, int last, int size); 273 trailer_e which, int first, int last, int size);
273 int writeXRefStream(int objid, int max_id, int max_offset, 274 int writeXRefStream(int objid, int max_id, int max_offset,
@@ -275,8 +276,8 @@ class QPDFWriter @@ -275,8 +276,8 @@ class QPDFWriter
275 // for linearization 276 // for linearization
276 int prev, 277 int prev,
277 int hint_id, 278 int hint_id,
278 - int hint_offset,  
279 - int hint_length, 279 + off_t hint_offset,
  280 + off_t hint_length,
280 bool skip_compression); 281 bool skip_compression);
281 int calculateXrefStreamPadding(int xref_bytes); 282 int calculateXrefStreamPadding(int xref_bytes);
282 283
@@ -295,7 +296,7 @@ class QPDFWriter @@ -295,7 +296,7 @@ class QPDFWriter
295 // stack items are of type Pl_Buffer, the buffer is retrieved. 296 // stack items are of type Pl_Buffer, the buffer is retrieved.
296 void popPipelineStack(PointerHolder<Buffer>* bp = 0); 297 void popPipelineStack(PointerHolder<Buffer>* bp = 0);
297 298
298 - void adjustAESStreamLength(unsigned long& length); 299 + void adjustAESStreamLength(size_t& length);
299 void pushEncryptionFilter(); 300 void pushEncryptionFilter();
300 void pushDiscardFilter(); 301 void pushDiscardFilter();
301 302
@@ -336,7 +337,7 @@ class QPDFWriter @@ -336,7 +337,7 @@ class QPDFWriter
336 std::map<int, size_t> lengths; 337 std::map<int, size_t> lengths;
337 int next_objid; 338 int next_objid;
338 int cur_stream_length_id; 339 int cur_stream_length_id;
339 - unsigned long cur_stream_length; 340 + size_t cur_stream_length;
340 bool added_newline; 341 bool added_newline;
341 int max_ostream_index; 342 int max_ostream_index;
342 std::set<int> normalized_streams; 343 std::set<int> normalized_streams;
include/qpdf/QPDFXRefEntry.hh
@@ -23,12 +23,12 @@ class QPDFXRefEntry @@ -23,12 +23,12 @@ class QPDFXRefEntry
23 QPDF_DLL 23 QPDF_DLL
24 QPDFXRefEntry(); 24 QPDFXRefEntry();
25 QPDF_DLL 25 QPDF_DLL
26 - QPDFXRefEntry(int type, int field1, int field2); 26 + QPDFXRefEntry(int type, off_t field1, int field2);
27 27
28 QPDF_DLL 28 QPDF_DLL
29 int getType() const; 29 int getType() const;
30 QPDF_DLL 30 QPDF_DLL
31 - int getOffset() const; // only for type 1 31 + off_t getOffset() const; // only for type 1
32 QPDF_DLL 32 QPDF_DLL
33 int getObjStreamNumber() const; // only for type 2 33 int getObjStreamNumber() const; // only for type 2
34 QPDF_DLL 34 QPDF_DLL
@@ -36,7 +36,7 @@ class QPDFXRefEntry @@ -36,7 +36,7 @@ class QPDFXRefEntry
36 36
37 private: 37 private:
38 int type; 38 int type;
39 - int field1; 39 + off_t field1;
40 int field2; 40 int field2;
41 }; 41 };
42 42
include/qpdf/QUtil.hh
@@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
9 #define __QUTIL_HH__ 9 #define __QUTIL_HH__
10 10
11 #include <qpdf/DLL.h> 11 #include <qpdf/DLL.h>
  12 +#include <qpdf/Types.h>
12 #include <string> 13 #include <string>
13 #include <list> 14 #include <list>
14 #include <stdexcept> 15 #include <stdexcept>
@@ -20,7 +21,7 @@ namespace QUtil @@ -20,7 +21,7 @@ namespace QUtil
20 // This is a collection of useful utility functions that don't 21 // This is a collection of useful utility functions that don't
21 // really go anywhere else. 22 // really go anywhere else.
22 QPDF_DLL 23 QPDF_DLL
23 - std::string int_to_string(int, int length = 0); 24 + std::string int_to_string(long long, int length = 0);
24 QPDF_DLL 25 QPDF_DLL
25 std::string double_to_string(double, int decimal_places = 0); 26 std::string double_to_string(double, int decimal_places = 0);
26 27
@@ -44,6 +45,12 @@ namespace QUtil @@ -44,6 +45,12 @@ namespace QUtil
44 QPDF_DLL 45 QPDF_DLL
45 FILE* fopen_wrapper(std::string const&, FILE*); 46 FILE* fopen_wrapper(std::string const&, FILE*);
46 47
  48 + // Wrap around off_t versions of fseek and ftell if available
  49 + QPDF_DLL
  50 + int fseek_off_t(FILE* stream, off_t offset, int whence);
  51 + QPDF_DLL
  52 + off_t ftell_off_t(FILE* stream);
  53 +
47 QPDF_DLL 54 QPDF_DLL
48 char* copy_string(std::string const&); 55 char* copy_string(std::string const&);
49 56
include/qpdf/qpdf-c.h
@@ -71,6 +71,7 @@ @@ -71,6 +71,7 @@
71 71
72 #include <qpdf/DLL.h> 72 #include <qpdf/DLL.h>
73 #include <qpdf/Constants.h> 73 #include <qpdf/Constants.h>
  74 +#include <qpdf/Types.h>
74 75
75 #ifdef __cplusplus 76 #ifdef __cplusplus
76 extern "C" { 77 extern "C" {
@@ -300,7 +301,7 @@ extern &quot;C&quot; { @@ -300,7 +301,7 @@ extern &quot;C&quot; {
300 * if a subsequent call to qpdf_init_write or 301 * if a subsequent call to qpdf_init_write or
301 * qpdf_init_write_memory is called. */ 302 * qpdf_init_write_memory is called. */
302 QPDF_DLL 303 QPDF_DLL
303 - unsigned long qpdf_get_buffer_length(qpdf_data qpdf); 304 + size_t qpdf_get_buffer_length(qpdf_data qpdf);
304 QPDF_DLL 305 QPDF_DLL
305 unsigned char const* qpdf_get_buffer(qpdf_data qpdf); 306 unsigned char const* qpdf_get_buffer(qpdf_data qpdf);
306 307
libqpdf/BitWriter.cc
@@ -12,7 +12,7 @@ BitWriter::BitWriter(Pipeline* pl) : @@ -12,7 +12,7 @@ BitWriter::BitWriter(Pipeline* pl) :
12 } 12 }
13 13
14 void 14 void
15 -BitWriter::writeBits(unsigned long val, int bits) 15 +BitWriter::writeBits(unsigned long val, unsigned int bits)
16 { 16 {
17 write_bits(this->ch, this->bit_offset, val, bits, this->pl); 17 write_bits(this->ch, this->bit_offset, val, bits, this->pl);
18 } 18 }
libqpdf/Buffer.cc
@@ -7,12 +7,12 @@ Buffer::Buffer() @@ -7,12 +7,12 @@ Buffer::Buffer()
7 init(0, 0, true); 7 init(0, 0, true);
8 } 8 }
9 9
10 -Buffer::Buffer(unsigned long size) 10 +Buffer::Buffer(size_t size)
11 { 11 {
12 init(size, 0, true); 12 init(size, 0, true);
13 } 13 }
14 14
15 -Buffer::Buffer(unsigned char* buf, unsigned long size) 15 +Buffer::Buffer(unsigned char* buf, size_t size)
16 { 16 {
17 init(size, buf, false); 17 init(size, buf, false);
18 } 18 }
@@ -36,7 +36,7 @@ Buffer::~Buffer() @@ -36,7 +36,7 @@ Buffer::~Buffer()
36 } 36 }
37 37
38 void 38 void
39 -Buffer::init(unsigned long size, unsigned char* buf, bool own_memory) 39 +Buffer::init(size_t size, unsigned char* buf, bool own_memory)
40 { 40 {
41 this->own_memory = own_memory; 41 this->own_memory = own_memory;
42 this->size = size; 42 this->size = size;
@@ -75,7 +75,7 @@ Buffer::destroy() @@ -75,7 +75,7 @@ Buffer::destroy()
75 this->buf = 0; 75 this->buf = 0;
76 } 76 }
77 77
78 -unsigned long 78 +size_t
79 Buffer::getSize() const 79 Buffer::getSize() const
80 { 80 {
81 return this->size; 81 return this->size;
libqpdf/MD5.cc
@@ -308,7 +308,7 @@ void MD5::reset() @@ -308,7 +308,7 @@ void MD5::reset()
308 308
309 void MD5::encodeString(char const* str) 309 void MD5::encodeString(char const* str)
310 { 310 {
311 - unsigned int len = strlen(str); 311 + unsigned int len = (unsigned int)strlen(str);
312 312
313 update((unsigned char *)str, len); 313 update((unsigned char *)str, len);
314 final(); 314 final();
@@ -316,7 +316,7 @@ void MD5::encodeString(char const* str) @@ -316,7 +316,7 @@ void MD5::encodeString(char const* str)
316 316
317 void MD5::appendString(char const* input_string) 317 void MD5::appendString(char const* input_string)
318 { 318 {
319 - update((unsigned char *)input_string, strlen(input_string)); 319 + update((unsigned char *)input_string, (unsigned int) strlen(input_string));
320 } 320 }
321 321
322 void MD5::encodeDataIncrementally(char const* data, int len) 322 void MD5::encodeDataIncrementally(char const* data, int len)
@@ -332,7 +332,7 @@ void MD5::encodeFile(char const *filename, int up_to_size) @@ -332,7 +332,7 @@ void MD5::encodeFile(char const *filename, int up_to_size)
332 std::string("MD5: open ") + filename, 332 std::string("MD5: open ") + filename,
333 fopen(filename, "rb")); 333 fopen(filename, "rb"));
334 334
335 - int len; 335 + size_t len;
336 int so_far = 0; 336 int so_far = 0;
337 int to_try = 1024; 337 int to_try = 1024;
338 do 338 do
@@ -344,7 +344,7 @@ void MD5::encodeFile(char const *filename, int up_to_size) @@ -344,7 +344,7 @@ void MD5::encodeFile(char const *filename, int up_to_size)
344 len = fread(buffer, 1, to_try, file); 344 len = fread(buffer, 1, to_try, file);
345 if (len > 0) 345 if (len > 0)
346 { 346 {
347 - update(buffer, len); 347 + update(buffer, (unsigned int) len);
348 so_far += len; 348 so_far += len;
349 if ((up_to_size >= 0) && (so_far >= up_to_size)) 349 if ((up_to_size >= 0) && (so_far >= up_to_size))
350 { 350 {
libqpdf/PCRE.cc
@@ -166,7 +166,7 @@ PCRE::match(char const* subject, int options, int startoffset, int size) @@ -166,7 +166,7 @@ PCRE::match(char const* subject, int options, int startoffset, int size)
166 { 166 {
167 if (size == -1) 167 if (size == -1)
168 { 168 {
169 - size = strlen(subject); 169 + size = (int) strlen(subject);
170 } 170 }
171 171
172 Match result(this->nbackrefs, subject); 172 Match result(this->nbackrefs, subject);
libqpdf/Pl_AES_PDF.cc
@@ -60,9 +60,9 @@ Pl_AES_PDF::useStaticIV() @@ -60,9 +60,9 @@ Pl_AES_PDF::useStaticIV()
60 } 60 }
61 61
62 void 62 void
63 -Pl_AES_PDF::write(unsigned char* data, int len) 63 +Pl_AES_PDF::write(unsigned char* data, size_t len)
64 { 64 {
65 - unsigned int bytes_left = len; 65 + size_t bytes_left = len;
66 unsigned char* p = data; 66 unsigned char* p = data;
67 67
68 while (bytes_left > 0) 68 while (bytes_left > 0)
@@ -72,8 +72,8 @@ Pl_AES_PDF::write(unsigned char* data, int len) @@ -72,8 +72,8 @@ Pl_AES_PDF::write(unsigned char* data, int len)
72 flush(false); 72 flush(false);
73 } 73 }
74 74
75 - unsigned int available = this->buf_size - this->offset;  
76 - int bytes = (bytes_left < available ? bytes_left : available); 75 + size_t available = this->buf_size - this->offset;
  76 + size_t bytes = (bytes_left < available ? bytes_left : available);
77 bytes_left -= bytes; 77 bytes_left -= bytes;
78 std::memcpy(this->inbuf + this->offset, p, bytes); 78 std::memcpy(this->inbuf + this->offset, p, bytes);
79 this->offset += bytes; 79 this->offset += bytes;
@@ -93,7 +93,7 @@ Pl_AES_PDF::finish() @@ -93,7 +93,7 @@ Pl_AES_PDF::finish()
93 // Pad as described in section 3.5.1 of version 1.7 of the PDF 93 // Pad as described in section 3.5.1 of version 1.7 of the PDF
94 // specification, including providing an entire block of padding 94 // specification, including providing an entire block of padding
95 // if the input was a multiple of 16 bytes. 95 // if the input was a multiple of 16 bytes.
96 - unsigned char pad = this->buf_size - this->offset; 96 + unsigned char pad = (unsigned char) (this->buf_size - this->offset);
97 memset(this->inbuf + this->offset, pad, pad); 97 memset(this->inbuf + this->offset, pad, pad);
98 this->offset = this->buf_size; 98 this->offset = this->buf_size;
99 flush(false); 99 flush(false);
libqpdf/Pl_ASCII85Decoder.cc
@@ -16,13 +16,13 @@ Pl_ASCII85Decoder::~Pl_ASCII85Decoder() @@ -16,13 +16,13 @@ Pl_ASCII85Decoder::~Pl_ASCII85Decoder()
16 } 16 }
17 17
18 void 18 void
19 -Pl_ASCII85Decoder::write(unsigned char* buf, int len) 19 +Pl_ASCII85Decoder::write(unsigned char* buf, size_t len)
20 { 20 {
21 if (eod > 1) 21 if (eod > 1)
22 { 22 {
23 return; 23 return;
24 } 24 }
25 - for (int i = 0; i < len; ++i) 25 + for (size_t i = 0; i < len; ++i)
26 { 26 {
27 if (eod > 1) 27 if (eod > 1)
28 { 28 {
libqpdf/Pl_ASCIIHexDecoder.cc
@@ -17,13 +17,13 @@ Pl_ASCIIHexDecoder::~Pl_ASCIIHexDecoder() @@ -17,13 +17,13 @@ Pl_ASCIIHexDecoder::~Pl_ASCIIHexDecoder()
17 } 17 }
18 18
19 void 19 void
20 -Pl_ASCIIHexDecoder::write(unsigned char* buf, int len) 20 +Pl_ASCIIHexDecoder::write(unsigned char* buf, size_t len)
21 { 21 {
22 if (this->eod) 22 if (this->eod)
23 { 23 {
24 return; 24 return;
25 } 25 }
26 - for (int i = 0; i < len; ++i) 26 + for (size_t i = 0; i < len; ++i)
27 { 27 {
28 char ch = toupper(buf[i]); 28 char ch = toupper(buf[i]);
29 switch (ch) 29 switch (ch)
libqpdf/Pl_Buffer.cc
@@ -15,7 +15,7 @@ Pl_Buffer::~Pl_Buffer() @@ -15,7 +15,7 @@ Pl_Buffer::~Pl_Buffer()
15 } 15 }
16 16
17 void 17 void
18 -Pl_Buffer::write(unsigned char* buf, int len) 18 +Pl_Buffer::write(unsigned char* buf, size_t len)
19 { 19 {
20 Buffer* b = new Buffer(len); 20 Buffer* b = new Buffer(len);
21 memcpy(b->getBuffer(), buf, len); 21 memcpy(b->getBuffer(), buf, len);
libqpdf/Pl_Count.cc
@@ -12,7 +12,7 @@ Pl_Count::~Pl_Count() @@ -12,7 +12,7 @@ Pl_Count::~Pl_Count()
12 } 12 }
13 13
14 void 14 void
15 -Pl_Count::write(unsigned char* buf, int len) 15 +Pl_Count::write(unsigned char* buf, size_t len)
16 { 16 {
17 if (len) 17 if (len)
18 { 18 {
@@ -28,7 +28,7 @@ Pl_Count::finish() @@ -28,7 +28,7 @@ Pl_Count::finish()
28 getNext()->finish(); 28 getNext()->finish();
29 } 29 }
30 30
31 -int 31 +off_t
32 Pl_Count::getCount() const 32 Pl_Count::getCount() const
33 { 33 {
34 return this->count; 34 return this->count;
libqpdf/Pl_Discard.cc
@@ -12,7 +12,7 @@ Pl_Discard::~Pl_Discard() @@ -12,7 +12,7 @@ Pl_Discard::~Pl_Discard()
12 } 12 }
13 13
14 void 14 void
15 -Pl_Discard::write(unsigned char* buf, int len) 15 +Pl_Discard::write(unsigned char* buf, size_t len)
16 { 16 {
17 } 17 }
18 18
libqpdf/Pl_Flate.cc
@@ -40,7 +40,7 @@ Pl_Flate::~Pl_Flate() @@ -40,7 +40,7 @@ Pl_Flate::~Pl_Flate()
40 } 40 }
41 41
42 void 42 void
43 -Pl_Flate::write(unsigned char* data, int len) 43 +Pl_Flate::write(unsigned char* data, size_t len)
44 { 44 {
45 if (this->outbuf == 0) 45 if (this->outbuf == 0)
46 { 46 {
@@ -48,7 +48,19 @@ Pl_Flate::write(unsigned char* data, int len) @@ -48,7 +48,19 @@ Pl_Flate::write(unsigned char* data, int len)
48 this->identifier + 48 this->identifier +
49 ": Pl_Flate: write() called after finish() called"); 49 ": Pl_Flate: write() called after finish() called");
50 } 50 }
51 - handleData(data, len, Z_NO_FLUSH); 51 +
  52 + // Write in chunks in case len is too big to fit in an int.
  53 + // Assume int is at least 32 bits.
  54 + static size_t const max_bytes = 1 << 30;
  55 + size_t bytes_left = len;
  56 + unsigned char* buf = data;
  57 + while (bytes_left > 0)
  58 + {
  59 + size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left);
  60 + handleData(buf, (int)bytes, Z_NO_FLUSH);
  61 + bytes_left -= bytes;
  62 + buf += bytes;
  63 + }
52 } 64 }
53 65
54 void 66 void
libqpdf/Pl_LZWDecoder.cc
@@ -25,9 +25,9 @@ Pl_LZWDecoder::~Pl_LZWDecoder() @@ -25,9 +25,9 @@ Pl_LZWDecoder::~Pl_LZWDecoder()
25 } 25 }
26 26
27 void 27 void
28 -Pl_LZWDecoder::write(unsigned char* bytes, int len) 28 +Pl_LZWDecoder::write(unsigned char* bytes, size_t len)
29 { 29 {
30 - for (int i = 0; i < len; ++i) 30 + for (size_t i = 0; i < len; ++i)
31 { 31 {
32 this->buf[next++] = bytes[i]; 32 this->buf[next++] = bytes[i];
33 if (this->next == 3) 33 if (this->next == 3)
@@ -131,7 +131,7 @@ Pl_LZWDecoder::addToTable(unsigned char next) @@ -131,7 +131,7 @@ Pl_LZWDecoder::addToTable(unsigned char next)
131 assert(idx < table.size()); 131 assert(idx < table.size());
132 Buffer& b = table[idx]; 132 Buffer& b = table[idx];
133 last_data = b.getBuffer(); 133 last_data = b.getBuffer();
134 - last_size = b.getSize(); 134 + last_size = (unsigned int) b.getSize();
135 } 135 }
136 136
137 Buffer entry(1 + last_size); 137 Buffer entry(1 + last_size);
@@ -170,7 +170,7 @@ Pl_LZWDecoder::handleCode(int code) @@ -170,7 +170,7 @@ Pl_LZWDecoder::handleCode(int code)
170 // be what we read last plus the first character of what 170 // be what we read last plus the first character of what
171 // we're reading now. 171 // we're reading now.
172 unsigned char next = '\0'; 172 unsigned char next = '\0';
173 - unsigned int table_size = table.size(); 173 + unsigned int table_size = (unsigned int) table.size();
174 if (code < 256) 174 if (code < 256)
175 { 175 {
176 // just read < 256; last time's next was code 176 // just read < 256; last time's next was code
@@ -178,7 +178,7 @@ Pl_LZWDecoder::handleCode(int code) @@ -178,7 +178,7 @@ Pl_LZWDecoder::handleCode(int code)
178 } 178 }
179 else if (code > 257) 179 else if (code > 257)
180 { 180 {
181 - unsigned int idx = code - 258; 181 + size_t idx = code - 258;
182 if (idx > table_size) 182 if (idx > table_size)
183 { 183 {
184 throw std::runtime_error("LZWDecoder: bad code received"); 184 throw std::runtime_error("LZWDecoder: bad code received");
libqpdf/Pl_MD5.cc
@@ -12,14 +12,27 @@ Pl_MD5::~Pl_MD5() @@ -12,14 +12,27 @@ Pl_MD5::~Pl_MD5()
12 } 12 }
13 13
14 void 14 void
15 -Pl_MD5::write(unsigned char* buf, int len) 15 +Pl_MD5::write(unsigned char* buf, size_t len)
16 { 16 {
17 if (! this->in_progress) 17 if (! this->in_progress)
18 { 18 {
19 this->md5.reset(); 19 this->md5.reset();
20 this->in_progress = true; 20 this->in_progress = true;
21 } 21 }
22 - this->md5.encodeDataIncrementally((char*) buf, len); 22 +
  23 + // Write in chunks in case len is too big to fit in an int.
  24 + // Assume int is at least 32 bits.
  25 + static size_t const max_bytes = 1 << 30;
  26 + size_t bytes_left = len;
  27 + unsigned char* data = buf;
  28 + while (bytes_left > 0)
  29 + {
  30 + size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left);
  31 + this->md5.encodeDataIncrementally((char*) data, (int)bytes);
  32 + bytes_left -= bytes;
  33 + data += bytes;
  34 + }
  35 +
23 this->getNext()->write(buf, len); 36 this->getNext()->write(buf, len);
24 } 37 }
25 38
libqpdf/Pl_PNGFilter.cc
@@ -29,10 +29,10 @@ Pl_PNGFilter::~Pl_PNGFilter() @@ -29,10 +29,10 @@ Pl_PNGFilter::~Pl_PNGFilter()
29 } 29 }
30 30
31 void 31 void
32 -Pl_PNGFilter::write(unsigned char* data, int len) 32 +Pl_PNGFilter::write(unsigned char* data, size_t len)
33 { 33 {
34 - int left = this->incoming - this->pos;  
35 - unsigned int offset = 0; 34 + size_t left = this->incoming - this->pos;
  35 + size_t offset = 0;
36 while (len >= left) 36 while (len >= left)
37 { 37 {
38 // finish off current row 38 // finish off current row
libqpdf/Pl_QPDFTokenizer.cc
@@ -22,7 +22,7 @@ Pl_QPDFTokenizer::~Pl_QPDFTokenizer() @@ -22,7 +22,7 @@ Pl_QPDFTokenizer::~Pl_QPDFTokenizer()
22 } 22 }
23 23
24 void 24 void
25 -Pl_QPDFTokenizer::writeNext(char const* buf, int len) 25 +Pl_QPDFTokenizer::writeNext(char const* buf, size_t len)
26 { 26 {
27 if (len) 27 if (len)
28 { 28 {
@@ -159,10 +159,10 @@ Pl_QPDFTokenizer::checkUnread() @@ -159,10 +159,10 @@ Pl_QPDFTokenizer::checkUnread()
159 } 159 }
160 160
161 void 161 void
162 -Pl_QPDFTokenizer::write(unsigned char* buf, int len) 162 +Pl_QPDFTokenizer::write(unsigned char* buf, size_t len)
163 { 163 {
164 checkUnread(); 164 checkUnread();
165 - for (int i = 0; i < len; ++i) 165 + for (size_t i = 0; i < len; ++i)
166 { 166 {
167 processChar(buf[i]); 167 processChar(buf[i]);
168 checkUnread(); 168 checkUnread();
libqpdf/Pl_RC4.cc
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 3
4 Pl_RC4::Pl_RC4(char const* identifier, Pipeline* next, 4 Pl_RC4::Pl_RC4(char const* identifier, Pipeline* next,
5 unsigned char const* key_data, int key_len, 5 unsigned char const* key_data, int key_len,
6 - int out_bufsize) : 6 + size_t out_bufsize) :
7 Pipeline(identifier, next), 7 Pipeline(identifier, next),
8 out_bufsize(out_bufsize), 8 out_bufsize(out_bufsize),
9 rc4(key_data, key_len) 9 rc4(key_data, key_len)
@@ -21,7 +21,7 @@ Pl_RC4::~Pl_RC4() @@ -21,7 +21,7 @@ Pl_RC4::~Pl_RC4()
21 } 21 }
22 22
23 void 23 void
24 -Pl_RC4::write(unsigned char* data, int len) 24 +Pl_RC4::write(unsigned char* data, size_t len)
25 { 25 {
26 if (this->outbuf == 0) 26 if (this->outbuf == 0)
27 { 27 {
@@ -30,14 +30,15 @@ Pl_RC4::write(unsigned char* data, int len) @@ -30,14 +30,15 @@ Pl_RC4::write(unsigned char* data, int len)
30 ": Pl_RC4: write() called after finish() called"); 30 ": Pl_RC4: write() called after finish() called");
31 } 31 }
32 32
33 - int bytes_left = len; 33 + size_t bytes_left = len;
34 unsigned char* p = data; 34 unsigned char* p = data;
35 35
36 while (bytes_left > 0) 36 while (bytes_left > 0)
37 { 37 {
38 - int bytes = (bytes_left < this->out_bufsize ? bytes_left : out_bufsize); 38 + size_t bytes =
  39 + (bytes_left < this->out_bufsize ? bytes_left : out_bufsize);
39 bytes_left -= bytes; 40 bytes_left -= bytes;
40 - rc4.process(p, bytes, outbuf); 41 + rc4.process(p, (int)bytes, outbuf);
41 p += bytes; 42 p += bytes;
42 getNext()->write(outbuf, bytes); 43 getNext()->write(outbuf, bytes);
43 } 44 }
libqpdf/Pl_StdioFile.cc
@@ -14,7 +14,7 @@ Pl_StdioFile::~Pl_StdioFile() @@ -14,7 +14,7 @@ Pl_StdioFile::~Pl_StdioFile()
14 } 14 }
15 15
16 void 16 void
17 -Pl_StdioFile::write(unsigned char* buf, int len) 17 +Pl_StdioFile::write(unsigned char* buf, size_t len)
18 { 18 {
19 size_t so_far = 0; 19 size_t so_far = 0;
20 while (len > 0) 20 while (len > 0)
libqpdf/QPDF.cc
@@ -117,7 +117,7 @@ QPDF::FileInputSource::getName() const @@ -117,7 +117,7 @@ QPDF::FileInputSource::getName() const
117 off_t 117 off_t
118 QPDF::FileInputSource::tell() 118 QPDF::FileInputSource::tell()
119 { 119 {
120 - return ftell(this->file); 120 + return QUtil::ftell_off_t(this->file);
121 } 121 }
122 122
123 void 123 void
@@ -126,7 +126,7 @@ QPDF::FileInputSource::seek(off_t offset, int whence) @@ -126,7 +126,7 @@ QPDF::FileInputSource::seek(off_t offset, int whence)
126 QUtil::os_wrapper(std::string("seek to ") + this->filename + ", offset " + 126 QUtil::os_wrapper(std::string("seek to ") + this->filename + ", offset " +
127 QUtil::int_to_string(offset) + " (" + 127 QUtil::int_to_string(offset) + " (" +
128 QUtil::int_to_string(whence) + ")", 128 QUtil::int_to_string(whence) + ")",
129 - fseek(this->file, offset, whence)); 129 + QUtil::fseek_off_t(this->file, offset, whence));
130 } 130 }
131 131
132 void 132 void
@@ -136,9 +136,9 @@ QPDF::FileInputSource::rewind() @@ -136,9 +136,9 @@ QPDF::FileInputSource::rewind()
136 } 136 }
137 137
138 size_t 138 size_t
139 -QPDF::FileInputSource::read(char* buffer, int length) 139 +QPDF::FileInputSource::read(char* buffer, size_t length)
140 { 140 {
141 - this->last_offset = ftell(this->file); 141 + this->last_offset = QUtil::ftell_off_t(this->file);
142 size_t len = fread(buffer, 1, length, this->file); 142 size_t len = fread(buffer, 1, length, this->file);
143 if ((len == 0) && ferror(this->file)) 143 if ((len == 0) && ferror(this->file))
144 { 144 {
@@ -197,7 +197,7 @@ QPDF::BufferInputSource::seek(off_t offset, int whence) @@ -197,7 +197,7 @@ QPDF::BufferInputSource::seek(off_t offset, int whence)
197 break; 197 break;
198 198
199 case SEEK_END: 199 case SEEK_END:
200 - this->cur_offset = this->buf->getSize() + offset; 200 + this->cur_offset = (off_t)this->buf->getSize() + offset;
201 break; 201 break;
202 202
203 case SEEK_CUR: 203 case SEEK_CUR:
@@ -218,9 +218,9 @@ QPDF::BufferInputSource::rewind() @@ -218,9 +218,9 @@ QPDF::BufferInputSource::rewind()
218 } 218 }
219 219
220 size_t 220 size_t
221 -QPDF::BufferInputSource::read(char* buffer, int length) 221 +QPDF::BufferInputSource::read(char* buffer, size_t length)
222 { 222 {
223 - off_t end_pos = this->buf->getSize(); 223 + off_t end_pos = (off_t) this->buf->getSize();
224 if (this->cur_offset >= end_pos) 224 if (this->cur_offset >= end_pos)
225 { 225 {
226 this->last_offset = end_pos; 226 this->last_offset = end_pos;
@@ -228,7 +228,7 @@ QPDF::BufferInputSource::read(char* buffer, int length) @@ -228,7 +228,7 @@ QPDF::BufferInputSource::read(char* buffer, int length)
228 } 228 }
229 229
230 this->last_offset = this->cur_offset; 230 this->last_offset = this->cur_offset;
231 - size_t len = std::min((int)(end_pos - this->cur_offset), length); 231 + size_t len = std::min((size_t)(end_pos - this->cur_offset), length);
232 memcpy(buffer, buf->getBuffer() + this->cur_offset, len); 232 memcpy(buffer, buf->getBuffer() + this->cur_offset, len);
233 this->cur_offset += len; 233 this->cur_offset += len;
234 return len; 234 return len;
@@ -432,7 +432,7 @@ QPDF::parse(char const* password) @@ -432,7 +432,7 @@ QPDF::parse(char const* password)
432 throw QPDFExc(qpdf_e_damaged_pdf, this->file->getName(), "", 0, 432 throw QPDFExc(qpdf_e_damaged_pdf, this->file->getName(), "", 0,
433 "can't find startxref"); 433 "can't find startxref");
434 } 434 }
435 - off_t xref_offset = atoi(m2.getMatch(1).c_str()); 435 + off_t xref_offset = atol(m2.getMatch(1).c_str());
436 read_xref(xref_offset); 436 read_xref(xref_offset);
437 } 437 }
438 catch (QPDFExc& e) 438 catch (QPDFExc& e)
@@ -878,10 +878,10 @@ QPDF::processXRefStream(off_t xref_offset, QPDFObjectHandle&amp; xref_obj) @@ -878,10 +878,10 @@ QPDF::processXRefStream(off_t xref_offset, QPDFObjectHandle&amp; xref_obj)
878 entry_size += W[i]; 878 entry_size += W[i];
879 } 879 }
880 880
881 - int expected_size = entry_size * num_entries; 881 + size_t expected_size = entry_size * num_entries;
882 882
883 PointerHolder<Buffer> bp = xref_obj.getStreamData(); 883 PointerHolder<Buffer> bp = xref_obj.getStreamData();
884 - int actual_size = bp->getSize(); 884 + size_t actual_size = bp->getSize();
885 885
886 if (expected_size != actual_size) 886 if (expected_size != actual_size)
887 { 887 {
@@ -1396,7 +1396,7 @@ QPDF::readObjectInternal(PointerHolder&lt;InputSource&gt; input, @@ -1396,7 +1396,7 @@ QPDF::readObjectInternal(PointerHolder&lt;InputSource&gt; input,
1396 // objects since resolving a previously unresolved 1396 // objects since resolving a previously unresolved
1397 // indirect object will change file position. 1397 // indirect object will change file position.
1398 off_t stream_offset = input->tell(); 1398 off_t stream_offset = input->tell();
1399 - int length = 0; 1399 + size_t length = 0;
1400 1400
1401 try 1401 try
1402 { 1402 {
@@ -1419,7 +1419,7 @@ QPDF::readObjectInternal(PointerHolder&lt;InputSource&gt; input, @@ -1419,7 +1419,7 @@ QPDF::readObjectInternal(PointerHolder&lt;InputSource&gt; input,
1419 } 1419 }
1420 1420
1421 length = length_obj.getIntValue(); 1421 length = length_obj.getIntValue();
1422 - input->seek(stream_offset + length, SEEK_SET); 1422 + input->seek(stream_offset + (off_t)length, SEEK_SET);
1423 if (! (readToken(input) == 1423 if (! (readToken(input) ==
1424 QPDFTokenizer::Token( 1424 QPDFTokenizer::Token(
1425 QPDFTokenizer::tt_word, "endstream"))) 1425 QPDFTokenizer::tt_word, "endstream")))
@@ -1457,7 +1457,7 @@ QPDF::readObjectInternal(PointerHolder&lt;InputSource&gt; input, @@ -1457,7 +1457,7 @@ QPDF::readObjectInternal(PointerHolder&lt;InputSource&gt; input,
1457 return object; 1457 return object;
1458 } 1458 }
1459 1459
1460 -int 1460 +size_t
1461 QPDF::recoverStreamLength(PointerHolder<InputSource> input, 1461 QPDF::recoverStreamLength(PointerHolder<InputSource> input,
1462 int objid, int generation, off_t stream_offset) 1462 int objid, int generation, off_t stream_offset)
1463 { 1463 {
@@ -1474,7 +1474,7 @@ QPDF::recoverStreamLength(PointerHolder&lt;InputSource&gt; input, @@ -1474,7 +1474,7 @@ QPDF::recoverStreamLength(PointerHolder&lt;InputSource&gt; input,
1474 input->seek(stream_offset, SEEK_SET); 1474 input->seek(stream_offset, SEEK_SET);
1475 std::string last_line; 1475 std::string last_line;
1476 off_t last_line_offset = 0; 1476 off_t last_line_offset = 0;
1477 - int length = 0; 1477 + size_t length = 0;
1478 while (input->tell() < eof) 1478 while (input->tell() < eof)
1479 { 1479 {
1480 std::string line = input->readLine(); 1480 std::string line = input->readLine();
libqpdf/QPDFObjectHandle.cc
@@ -604,7 +604,7 @@ QPDFObjectHandle::newDictionary( @@ -604,7 +604,7 @@ QPDFObjectHandle::newDictionary(
604 QPDFObjectHandle 604 QPDFObjectHandle
605 QPDFObjectHandle::newStream(QPDF* qpdf, int objid, int generation, 605 QPDFObjectHandle::newStream(QPDF* qpdf, int objid, int generation,
606 QPDFObjectHandle stream_dict, 606 QPDFObjectHandle stream_dict,
607 - off_t offset, int length) 607 + off_t offset, size_t length)
608 { 608 {
609 return QPDFObjectHandle(new QPDF_Stream( 609 return QPDFObjectHandle(new QPDF_Stream(
610 qpdf, objid, generation, 610 qpdf, objid, generation,
libqpdf/QPDFTokenizer.cc
@@ -175,7 +175,7 @@ QPDFTokenizer::presentCharacter(char ch) @@ -175,7 +175,7 @@ QPDFTokenizer::presentCharacter(char ch)
175 string_ignoring_newline = false; 175 string_ignoring_newline = false;
176 } 176 }
177 177
178 - unsigned int bs_num_count = strlen(bs_num_register); 178 + size_t bs_num_count = strlen(bs_num_register);
179 bool ch_is_octal = ((ch >= '0') && (ch <= '7')); 179 bool ch_is_octal = ((ch >= '0') && (ch <= '7'));
180 if ((bs_num_count == 3) || ((bs_num_count > 0) && (! ch_is_octal))) 180 if ((bs_num_count == 3) || ((bs_num_count > 0) && (! ch_is_octal)))
181 { 181 {
libqpdf/QPDFWriter.cc
@@ -651,7 +651,7 @@ QPDFWriter::popPipelineStack(PointerHolder&lt;Buffer&gt;* bp) @@ -651,7 +651,7 @@ QPDFWriter::popPipelineStack(PointerHolder&lt;Buffer&gt;* bp)
651 } 651 }
652 652
653 void 653 void
654 -QPDFWriter::adjustAESStreamLength(unsigned long& length) 654 +QPDFWriter::adjustAESStreamLength(size_t& length)
655 { 655 {
656 if (this->encrypted && (! this->cur_data_key.empty()) && 656 if (this->encrypted && (! this->cur_data_key.empty()) &&
657 this->encrypt_use_aes) 657 this->encrypt_use_aes)
@@ -679,7 +679,7 @@ QPDFWriter::pushEncryptionFilter() @@ -679,7 +679,7 @@ QPDFWriter::pushEncryptionFilter()
679 { 679 {
680 p = new Pl_RC4("rc4 stream encryption", this->pipeline, 680 p = new Pl_RC4("rc4 stream encryption", this->pipeline,
681 (unsigned char*) this->cur_data_key.c_str(), 681 (unsigned char*) this->cur_data_key.c_str(),
682 - this->cur_data_key.length()); 682 + (int)this->cur_data_key.length());
683 } 683 }
684 pushPipeline(p); 684 pushPipeline(p);
685 } 685 }
@@ -879,9 +879,9 @@ QPDFWriter::writeTrailer(trailer_e which, int size, bool xref_stream, int prev) @@ -879,9 +879,9 @@ QPDFWriter::writeTrailer(trailer_e which, int size, bool xref_stream, int prev)
879 if (which == t_lin_first) 879 if (which == t_lin_first)
880 { 880 {
881 writeString(" /Prev "); 881 writeString(" /Prev ");
882 - int pos = this->pipeline->getCount(); 882 + off_t pos = this->pipeline->getCount();
883 writeString(QUtil::int_to_string(prev)); 883 writeString(QUtil::int_to_string(prev));
884 - int nspaces = pos + 11 - this->pipeline->getCount(); 884 + int nspaces = (int)(pos - this->pipeline->getCount() + 11);
885 assert(nspaces >= 0); 885 assert(nspaces >= 0);
886 writePad(nspaces); 886 writePad(nspaces);
887 } 887 }
@@ -926,7 +926,8 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level, @@ -926,7 +926,8 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level,
926 926
927 void 927 void
928 QPDFWriter::unparseObject(QPDFObjectHandle object, int level, 928 QPDFWriter::unparseObject(QPDFObjectHandle object, int level,
929 - unsigned int flags, int stream_length, bool compress) 929 + unsigned int flags, size_t stream_length,
  930 + bool compress)
930 { 931 {
931 unsigned int child_flags = flags & ~f_stream; 932 unsigned int child_flags = flags & ~f_stream;
932 933
@@ -1137,16 +1138,16 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level, @@ -1137,16 +1138,16 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level,
1137 Buffer* buf = bufpl.getBuffer(); 1138 Buffer* buf = bufpl.getBuffer();
1138 val = QPDF_String( 1139 val = QPDF_String(
1139 std::string((char*)buf->getBuffer(), 1140 std::string((char*)buf->getBuffer(),
1140 - (size_t)buf->getSize())).unparse(true); 1141 + buf->getSize())).unparse(true);
1141 delete buf; 1142 delete buf;
1142 } 1143 }
1143 else 1144 else
1144 { 1145 {
1145 char* tmp = QUtil::copy_string(val); 1146 char* tmp = QUtil::copy_string(val);
1146 - unsigned int vlen = val.length(); 1147 + size_t vlen = val.length();
1147 RC4 rc4((unsigned char const*)this->cur_data_key.c_str(), 1148 RC4 rc4((unsigned char const*)this->cur_data_key.c_str(),
1148 - this->cur_data_key.length());  
1149 - rc4.process((unsigned char*)tmp, vlen); 1149 + (int)this->cur_data_key.length());
  1150 + rc4.process((unsigned char*)tmp, (int)vlen);
1150 val = QPDF_String(std::string(tmp, vlen)).unparse(); 1151 val = QPDF_String(std::string(tmp, vlen)).unparse();
1151 delete [] tmp; 1152 delete [] tmp;
1152 } 1153 }
@@ -1164,7 +1165,7 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level, @@ -1164,7 +1165,7 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level,
1164 } 1165 }
1165 1166
1166 void 1167 void
1167 -QPDFWriter::writeObjectStreamOffsets(std::vector<int>& offsets, 1168 +QPDFWriter::writeObjectStreamOffsets(std::vector<off_t>& offsets,
1168 int first_obj) 1169 int first_obj)
1169 { 1170 {
1170 for (unsigned int i = 0; i < offsets.size(); ++i) 1171 for (unsigned int i = 0; i < offsets.size(); ++i)
@@ -1190,8 +1191,8 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) @@ -1190,8 +1191,8 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object)
1190 int old_id = object.getObjectID(); 1191 int old_id = object.getObjectID();
1191 int new_id = obj_renumber[old_id]; 1192 int new_id = obj_renumber[old_id];
1192 1193
1193 - std::vector<int> offsets;  
1194 - int first = 0; 1194 + std::vector<off_t> offsets;
  1195 + off_t first = 0;
1195 1196
1196 // Generate stream itself. We have to do this in two passes so we 1197 // Generate stream itself. We have to do this in two passes so we
1197 // can calculate offsets in the first pass. 1198 // can calculate offsets in the first pass.
@@ -1209,7 +1210,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) @@ -1209,7 +1210,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object)
1209 // Adjust offsets to skip over comment before first object 1210 // Adjust offsets to skip over comment before first object
1210 1211
1211 first = offsets[0]; 1212 first = offsets[0];
1212 - for (std::vector<int>::iterator iter = offsets.begin(); 1213 + for (std::vector<off_t>::iterator iter = offsets.begin();
1213 iter != offsets.end(); ++iter) 1214 iter != offsets.end(); ++iter)
1214 { 1215 {
1215 *iter -= first; 1216 *iter -= first;
@@ -1280,7 +1281,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) @@ -1280,7 +1281,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object)
1280 writeStringQDF("\n "); 1281 writeStringQDF("\n ");
1281 writeString(" /Type /ObjStm"); 1282 writeString(" /Type /ObjStm");
1282 writeStringQDF("\n "); 1283 writeStringQDF("\n ");
1283 - unsigned long length = stream_buffer->getSize(); 1284 + size_t length = stream_buffer->getSize();
1284 adjustAESStreamLength(length); 1285 adjustAESStreamLength(length);
1285 writeString(" /Length " + QUtil::int_to_string(length)); 1286 writeString(" /Length " + QUtil::int_to_string(length));
1286 writeStringQDF("\n "); 1287 writeStringQDF("\n ");
@@ -1523,8 +1524,9 @@ QPDFWriter::generateObjectStreams() @@ -1523,8 +1524,9 @@ QPDFWriter::generateObjectStreams()
1523 // This code doesn't do anything with /Extends. 1524 // This code doesn't do anything with /Extends.
1524 1525
1525 std::vector<int> const& eligible = this->pdf.getCompressibleObjects(); 1526 std::vector<int> const& eligible = this->pdf.getCompressibleObjects();
1526 - unsigned int n_object_streams = (eligible.size() + 99) / 100;  
1527 - unsigned int n_per = eligible.size() / n_object_streams; 1527 + unsigned int n_object_streams =
  1528 + (unsigned int)((eligible.size() + 99) / 100);
  1529 + unsigned int n_per = (unsigned int)(eligible.size() / n_object_streams);
1528 if (n_per * n_object_streams < eligible.size()) 1530 if (n_per * n_object_streams < eligible.size())
1529 { 1531 {
1530 ++n_per; 1532 ++n_per;
@@ -1777,7 +1779,7 @@ QPDFWriter::writeHintStream(int hint_id) @@ -1777,7 +1779,7 @@ QPDFWriter::writeHintStream(int hint_id)
1777 openObject(hint_id); 1779 openObject(hint_id);
1778 setDataKey(hint_id); 1780 setDataKey(hint_id);
1779 1781
1780 - unsigned long hlen = hint_buffer->getSize(); 1782 + size_t hlen = hint_buffer->getSize();
1781 1783
1782 writeString("<< /Filter /FlateDecode /S "); 1784 writeString("<< /Filter /FlateDecode /S ");
1783 writeString(QUtil::int_to_string(S)); 1785 writeString(QUtil::int_to_string(S));
@@ -1817,13 +1819,13 @@ QPDFWriter::writeXRefTable(trailer_e which, int first, int last, int size) @@ -1817,13 +1819,13 @@ QPDFWriter::writeXRefTable(trailer_e which, int first, int last, int size)
1817 int 1819 int
1818 QPDFWriter::writeXRefTable(trailer_e which, int first, int last, int size, 1820 QPDFWriter::writeXRefTable(trailer_e which, int first, int last, int size,
1819 int prev, bool suppress_offsets, 1821 int prev, bool suppress_offsets,
1820 - int hint_id, int hint_offset, int hint_length) 1822 + int hint_id, off_t hint_offset, off_t hint_length)
1821 { 1823 {
1822 writeString("xref\n"); 1824 writeString("xref\n");
1823 writeString(QUtil::int_to_string(first)); 1825 writeString(QUtil::int_to_string(first));
1824 writeString(" "); 1826 writeString(" ");
1825 writeString(QUtil::int_to_string(last - first + 1)); 1827 writeString(QUtil::int_to_string(last - first + 1));
1826 - int space_before_zero = this->pipeline->getCount(); 1828 + off_t space_before_zero = this->pipeline->getCount();
1827 writeString("\n"); 1829 writeString("\n");
1828 for (int i = first; i <= last; ++i) 1830 for (int i = first; i <= last; ++i)
1829 { 1831 {
@@ -1865,10 +1867,10 @@ int @@ -1865,10 +1867,10 @@ int
1865 QPDFWriter::writeXRefStream(int xref_id, int max_id, int max_offset, 1867 QPDFWriter::writeXRefStream(int xref_id, int max_id, int max_offset,
1866 trailer_e which, int first, int last, int size, 1868 trailer_e which, int first, int last, int size,
1867 int prev, int hint_id, 1869 int prev, int hint_id,
1868 - int hint_offset, int hint_length, 1870 + off_t hint_offset, off_t hint_length,
1869 bool skip_compression) 1871 bool skip_compression)
1870 { 1872 {
1871 - int xref_offset = this->pipeline->getCount(); 1873 + off_t xref_offset = this->pipeline->getCount();
1872 int space_before_zero = xref_offset - 1; 1874 int space_before_zero = xref_offset - 1;
1873 1875
1874 // field 1 contains offsets and object stream identifiers 1876 // field 1 contains offsets and object stream identifiers
@@ -2021,7 +2023,8 @@ QPDFWriter::writeLinearized() @@ -2021,7 +2023,8 @@ QPDFWriter::writeLinearized()
2021 // 2023 //
2022 2024
2023 // Second half objects 2025 // Second half objects
2024 - int second_half_uncompressed = part7.size() + part8.size() + part9.size(); 2026 + int second_half_uncompressed =
  2027 + (int)(part7.size() + part8.size() + part9.size());
2025 int second_half_first_obj = 1; 2028 int second_half_first_obj = 1;
2026 int after_second_half = 1 + second_half_uncompressed; 2029 int after_second_half = 1 + second_half_uncompressed;
2027 this->next_objid = after_second_half; 2030 this->next_objid = after_second_half;
@@ -2077,13 +2080,13 @@ QPDFWriter::writeLinearized() @@ -2077,13 +2080,13 @@ QPDFWriter::writeLinearized()
2077 2080
2078 int part4_end_marker = part4.back().getObjectID(); 2081 int part4_end_marker = part4.back().getObjectID();
2079 int part6_end_marker = part6.back().getObjectID(); 2082 int part6_end_marker = part6.back().getObjectID();
2080 - int space_before_zero = 0;  
2081 - int file_size = 0;  
2082 - int part6_end_offset = 0;  
2083 - int first_half_max_obj_offset = 0;  
2084 - int second_xref_offset = 0;  
2085 - int first_xref_end = 0;  
2086 - int second_xref_end = 0; 2083 + off_t space_before_zero = 0;
  2084 + off_t file_size = 0;
  2085 + off_t part6_end_offset = 0;
  2086 + off_t first_half_max_obj_offset = 0;
  2087 + off_t second_xref_offset = 0;
  2088 + off_t first_xref_end = 0;
  2089 + off_t second_xref_end = 0;
2087 2090
2088 this->next_objid = part4_first_obj; 2091 this->next_objid = part4_first_obj;
2089 enqueuePart(part4); 2092 enqueuePart(part4);
@@ -2097,7 +2100,7 @@ QPDFWriter::writeLinearized() @@ -2097,7 +2100,7 @@ QPDFWriter::writeLinearized()
2097 enqueuePart(part9); 2100 enqueuePart(part9);
2098 assert(this->next_objid == after_second_half); 2101 assert(this->next_objid == after_second_half);
2099 2102
2100 - int hint_length = 0; 2103 + off_t hint_length = 0;
2101 PointerHolder<Buffer> hint_buffer; 2104 PointerHolder<Buffer> hint_buffer;
2102 2105
2103 // Write file in two passes. Part numbers refer to PDF spec 1.4. 2106 // Write file in two passes. Part numbers refer to PDF spec 1.4.
@@ -2118,14 +2121,14 @@ QPDFWriter::writeLinearized() @@ -2118,14 +2121,14 @@ QPDFWriter::writeLinearized()
2118 // space if all numerical values in the parameter dictionary 2121 // space if all numerical values in the parameter dictionary
2119 // are 10 digits long plus a few extra characters for safety. 2122 // are 10 digits long plus a few extra characters for safety.
2120 2123
2121 - int pos = this->pipeline->getCount(); 2124 + off_t pos = this->pipeline->getCount();
2122 openObject(lindict_id); 2125 openObject(lindict_id);
2123 writeString("<<"); 2126 writeString("<<");
2124 if (pass == 2) 2127 if (pass == 2)
2125 { 2128 {
2126 std::vector<QPDFObjectHandle> const& pages = pdf.getAllPages(); 2129 std::vector<QPDFObjectHandle> const& pages = pdf.getAllPages();
2127 int first_page_object = obj_renumber[pages[0].getObjectID()]; 2130 int first_page_object = obj_renumber[pages[0].getObjectID()];
2128 - int npages = pages.size(); 2131 + int npages = (int)pages.size();
2129 2132
2130 writeString(" /Linearized 1 /L "); 2133 writeString(" /Linearized 1 /L ");
2131 writeString(QUtil::int_to_string(file_size + hint_length)); 2134 writeString(QUtil::int_to_string(file_size + hint_length));
@@ -2147,15 +2150,15 @@ QPDFWriter::writeLinearized() @@ -2147,15 +2150,15 @@ QPDFWriter::writeLinearized()
2147 writeString(" >>"); 2150 writeString(" >>");
2148 closeObject(lindict_id); 2151 closeObject(lindict_id);
2149 static int const pad = 150; 2152 static int const pad = 150;
2150 - int spaces = (pos + pad - this->pipeline->getCount()); 2153 + int spaces = (pos - this->pipeline->getCount() + pad);
2151 assert(spaces >= 0); 2154 assert(spaces >= 0);
2152 writePad(spaces); 2155 writePad(spaces);
2153 writeString("\n"); 2156 writeString("\n");
2154 2157
2155 // Part 3: first page cross reference table and trailer. 2158 // Part 3: first page cross reference table and trailer.
2156 2159
2157 - int first_xref_offset = this->pipeline->getCount();  
2158 - int hint_offset = 0; 2160 + off_t first_xref_offset = this->pipeline->getCount();
  2161 + off_t hint_offset = 0;
2159 if (pass == 2) 2162 if (pass == 2)
2160 { 2163 {
2161 hint_offset = this->xref[hint_id].getOffset(); 2164 hint_offset = this->xref[hint_id].getOffset();
@@ -2183,7 +2186,7 @@ QPDFWriter::writeLinearized() @@ -2183,7 +2186,7 @@ QPDFWriter::writeLinearized()
2183 hint_length + second_xref_offset, 2186 hint_length + second_xref_offset,
2184 hint_id, hint_offset, hint_length, 2187 hint_id, hint_offset, hint_length,
2185 (pass == 1)); 2188 (pass == 1));
2186 - int endpos = this->pipeline->getCount(); 2189 + off_t endpos = this->pipeline->getCount();
2187 if (pass == 1) 2190 if (pass == 1)
2188 { 2191 {
2189 // Pad so we have enough room for the real xref 2192 // Pad so we have enough room for the real xref
@@ -2260,7 +2263,7 @@ QPDFWriter::writeLinearized() @@ -2260,7 +2263,7 @@ QPDFWriter::writeLinearized()
2260 t_lin_second, 0, second_half_end, 2263 t_lin_second, 0, second_half_end,
2261 second_trailer_size, 2264 second_trailer_size,
2262 0, 0, 0, 0, (pass == 1)); 2265 0, 0, 0, 0, (pass == 1));
2263 - int endpos = this->pipeline->getCount(); 2266 + off_t endpos = this->pipeline->getCount();
2264 2267
2265 if (pass == 1) 2268 if (pass == 1)
2266 { 2269 {
@@ -2274,14 +2277,14 @@ QPDFWriter::writeLinearized() @@ -2274,14 +2277,14 @@ QPDFWriter::writeLinearized()
2274 else 2277 else
2275 { 2278 {
2276 // Make the file size the same. 2279 // Make the file size the same.
2277 - int pos = this->pipeline->getCount(); 2280 + off_t pos = this->pipeline->getCount();
2278 writePad(second_xref_end + hint_length - 1 - pos); 2281 writePad(second_xref_end + hint_length - 1 - pos);
2279 writeString("\n"); 2282 writeString("\n");
2280 2283
2281 // If this assertion fails, maybe we didn't have 2284 // If this assertion fails, maybe we didn't have
2282 // enough padding above. 2285 // enough padding above.
2283 assert(this->pipeline->getCount() == 2286 assert(this->pipeline->getCount() ==
2284 - second_xref_end + hint_length); 2287 + (off_t)(second_xref_end + hint_length));
2285 } 2288 }
2286 } 2289 }
2287 else 2290 else
@@ -2309,7 +2312,7 @@ QPDFWriter::writeLinearized() @@ -2309,7 +2312,7 @@ QPDFWriter::writeLinearized()
2309 activatePipelineStack(); 2312 activatePipelineStack();
2310 writeHintStream(hint_id); 2313 writeHintStream(hint_id);
2311 popPipelineStack(&hint_buffer); 2314 popPipelineStack(&hint_buffer);
2312 - hint_length = hint_buffer->getSize(); 2315 + hint_length = (off_t)hint_buffer->getSize();
2313 2316
2314 // Restore hint offset 2317 // Restore hint offset
2315 this->xref[hint_id] = QPDFXRefEntry(1, hint_offset, 0); 2318 this->xref[hint_id] = QPDFXRefEntry(1, hint_offset, 0);
libqpdf/QPDFXRefEntry.cc
@@ -9,7 +9,7 @@ QPDFXRefEntry::QPDFXRefEntry() : @@ -9,7 +9,7 @@ QPDFXRefEntry::QPDFXRefEntry() :
9 { 9 {
10 } 10 }
11 11
12 -QPDFXRefEntry::QPDFXRefEntry(int type, int field1, int field2) : 12 +QPDFXRefEntry::QPDFXRefEntry(int type, off_t field1, int field2) :
13 type(type), 13 type(type),
14 field1(field1), 14 field1(field1),
15 field2(field2) 15 field2(field2)
@@ -27,7 +27,7 @@ QPDFXRefEntry::getType() const @@ -27,7 +27,7 @@ QPDFXRefEntry::getType() const
27 return this->type; 27 return this->type;
28 } 28 }
29 29
30 -int 30 +off_t
31 QPDFXRefEntry::getOffset() const 31 QPDFXRefEntry::getOffset() const
32 { 32 {
33 if (this->type != 1) 33 if (this->type != 1)
@@ -46,7 +46,7 @@ QPDFXRefEntry::getObjStreamNumber() const @@ -46,7 +46,7 @@ QPDFXRefEntry::getObjStreamNumber() const
46 throw std::logic_error( 46 throw std::logic_error(
47 "getObjStreamNumber called for xref entry of type != 2"); 47 "getObjStreamNumber called for xref entry of type != 2");
48 } 48 }
49 - return this->field1; 49 + return (int) this->field1;
50 } 50 }
51 51
52 int 52 int
libqpdf/QPDF_Array.cc
@@ -37,7 +37,7 @@ QPDF_Array::unparse() @@ -37,7 +37,7 @@ QPDF_Array::unparse()
37 int 37 int
38 QPDF_Array::getNItems() const 38 QPDF_Array::getNItems() const
39 { 39 {
40 - return this->items.size(); 40 + return (int)this->items.size();
41 } 41 }
42 42
43 QPDFObjectHandle 43 QPDFObjectHandle
libqpdf/QPDF_Stream.cc
@@ -22,7 +22,7 @@ std::map&lt;std::string, std::string&gt; QPDF_Stream::filter_abbreviations; @@ -22,7 +22,7 @@ std::map&lt;std::string, std::string&gt; QPDF_Stream::filter_abbreviations;
22 22
23 QPDF_Stream::QPDF_Stream(QPDF* qpdf, int objid, int generation, 23 QPDF_Stream::QPDF_Stream(QPDF* qpdf, int objid, int generation,
24 QPDFObjectHandle stream_dict, 24 QPDFObjectHandle stream_dict,
25 - off_t offset, int length) : 25 + off_t offset, size_t length) :
26 qpdf(qpdf), 26 qpdf(qpdf),
27 objid(objid), 27 objid(objid),
28 generation(generation), 28 generation(generation),
@@ -379,8 +379,8 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool filter, @@ -379,8 +379,8 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool filter,
379 Pl_Count count("stream provider count", pipeline); 379 Pl_Count count("stream provider count", pipeline);
380 this->stream_provider->provideStreamData( 380 this->stream_provider->provideStreamData(
381 this->objid, this->generation, &count); 381 this->objid, this->generation, &count);
382 - size_t actual_length = count.getCount();  
383 - size_t desired_length = 382 + off_t actual_length = count.getCount();
  383 + off_t desired_length =
384 this->stream_dict.getKey("/Length").getIntValue(); 384 this->stream_dict.getKey("/Length").getIntValue();
385 if (actual_length == desired_length) 385 if (actual_length == desired_length)
386 { 386 {
@@ -446,5 +446,5 @@ QPDF_Stream::replaceFilterData(QPDFObjectHandle const&amp; filter, @@ -446,5 +446,5 @@ QPDF_Stream::replaceFilterData(QPDFObjectHandle const&amp; filter,
446 this->stream_dict.replaceOrRemoveKey("/Filter", filter); 446 this->stream_dict.replaceOrRemoveKey("/Filter", filter);
447 this->stream_dict.replaceOrRemoveKey("/DecodeParms", decode_parms); 447 this->stream_dict.replaceOrRemoveKey("/DecodeParms", decode_parms);
448 this->stream_dict.replaceKey("/Length", 448 this->stream_dict.replaceKey("/Length",
449 - QPDFObjectHandle::newInteger(length)); 449 + QPDFObjectHandle::newInteger((int)length));
450 } 450 }
libqpdf/QPDF_String.cc
@@ -157,7 +157,7 @@ std::string @@ -157,7 +157,7 @@ std::string
157 QPDF_String::getUTF8Val() const 157 QPDF_String::getUTF8Val() const
158 { 158 {
159 std::string result; 159 std::string result;
160 - unsigned int len = this->val.length(); 160 + size_t len = this->val.length();
161 if ((len >= 2) && (len % 2 == 0) && 161 if ((len >= 2) && (len % 2 == 0) &&
162 (this->val[0] == '\xfe') && (this->val[1] == '\xff')) 162 (this->val[0] == '\xfe') && (this->val[1] == '\xff'))
163 { 163 {
libqpdf/QPDF_encryption.cc
@@ -29,7 +29,7 @@ static unsigned int const key_bytes = 32; @@ -29,7 +29,7 @@ static unsigned int const key_bytes = 32;
29 void 29 void
30 pad_or_truncate_password(std::string const& password, char k1[key_bytes]) 30 pad_or_truncate_password(std::string const& password, char k1[key_bytes])
31 { 31 {
32 - int password_bytes = std::min((size_t) key_bytes, password.length()); 32 + int password_bytes = std::min(key_bytes, (unsigned int)password.length());
33 int pad_bytes = key_bytes - password_bytes; 33 int pad_bytes = key_bytes - password_bytes;
34 memcpy(k1, password.c_str(), password_bytes); 34 memcpy(k1, password.c_str(), password_bytes);
35 memcpy(k1 + password_bytes, padding_string, pad_bytes); 35 memcpy(k1 + password_bytes, padding_string, pad_bytes);
@@ -121,7 +121,7 @@ QPDF::compute_data_key(std::string const&amp; encryption_key, @@ -121,7 +121,7 @@ QPDF::compute_data_key(std::string const&amp; encryption_key,
121 } 121 }
122 122
123 MD5 md5; 123 MD5 md5;
124 - md5.encodeDataIncrementally(result.c_str(), result.length()); 124 + md5.encodeDataIncrementally(result.c_str(), (int)result.length());
125 MD5::Digest digest; 125 MD5::Digest digest;
126 md5.digest(digest); 126 md5.digest(digest);
127 return std::string((char*) digest, 127 return std::string((char*) digest,
@@ -144,7 +144,7 @@ QPDF::compute_encryption_key( @@ -144,7 +144,7 @@ QPDF::compute_encryption_key(
144 pbytes[2] = (char) ((data.P >> 16) & 0xff); 144 pbytes[2] = (char) ((data.P >> 16) & 0xff);
145 pbytes[3] = (char) ((data.P >> 24) & 0xff); 145 pbytes[3] = (char) ((data.P >> 24) & 0xff);
146 md5.encodeDataIncrementally(pbytes, 4); 146 md5.encodeDataIncrementally(pbytes, 4);
147 - md5.encodeDataIncrementally(data.id1.c_str(), data.id1.length()); 147 + md5.encodeDataIncrementally(data.id1.c_str(), (int)data.id1.length());
148 if ((data.R >= 4) && (! data.encrypt_metadata)) 148 if ((data.R >= 4) && (! data.encrypt_metadata))
149 { 149 {
150 char bytes[4]; 150 char bytes[4];
@@ -218,7 +218,7 @@ compute_U_value_R3(std::string const&amp; user_password, @@ -218,7 +218,7 @@ compute_U_value_R3(std::string const&amp; user_password,
218 MD5 md5; 218 MD5 md5;
219 md5.encodeDataIncrementally( 219 md5.encodeDataIncrementally(
220 pad_or_truncate_password("").c_str(), key_bytes); 220 pad_or_truncate_password("").c_str(), key_bytes);
221 - md5.encodeDataIncrementally(data.id1.c_str(), data.id1.length()); 221 + md5.encodeDataIncrementally(data.id1.c_str(), (int)data.id1.length());
222 MD5::Digest digest; 222 MD5::Digest digest;
223 md5.digest(digest); 223 md5.digest(digest);
224 iterate_rc4(digest, sizeof(MD5::Digest), 224 iterate_rc4(digest, sizeof(MD5::Digest),
@@ -583,16 +583,16 @@ QPDF::decryptString(std::string&amp; str, int objid, int generation) @@ -583,16 +583,16 @@ QPDF::decryptString(std::string&amp; str, int objid, int generation)
583 pl.write((unsigned char*)str.c_str(), str.length()); 583 pl.write((unsigned char*)str.c_str(), str.length());
584 pl.finish(); 584 pl.finish();
585 PointerHolder<Buffer> buf = bufpl.getBuffer(); 585 PointerHolder<Buffer> buf = bufpl.getBuffer();
586 - str = std::string((char*)buf->getBuffer(), (size_t)buf->getSize()); 586 + str = std::string((char*)buf->getBuffer(), buf->getSize());
587 } 587 }
588 else 588 else
589 { 589 {
590 QTC::TC("qpdf", "QPDF_encryption rc4 decode string"); 590 QTC::TC("qpdf", "QPDF_encryption rc4 decode string");
591 - unsigned int vlen = str.length(); 591 + unsigned int vlen = (int)str.length();
592 // Using PointerHolder guarantees that tmp will 592 // Using PointerHolder guarantees that tmp will
593 // be freed even if rc4.process throws an exception. 593 // be freed even if rc4.process throws an exception.
594 PointerHolder<char> tmp(true, QUtil::copy_string(str)); 594 PointerHolder<char> tmp(true, QUtil::copy_string(str));
595 - RC4 rc4((unsigned char const*)key.c_str(), key.length()); 595 + RC4 rc4((unsigned char const*)key.c_str(), (int)key.length());
596 rc4.process((unsigned char*)tmp.getPointer(), vlen); 596 rc4.process((unsigned char*)tmp.getPointer(), vlen);
597 str = std::string(tmp.getPointer(), vlen); 597 str = std::string(tmp.getPointer(), vlen);
598 } 598 }
@@ -704,7 +704,7 @@ QPDF::decryptStream(Pipeline*&amp; pipeline, int objid, int generation, @@ -704,7 +704,7 @@ QPDF::decryptStream(Pipeline*&amp; pipeline, int objid, int generation,
704 { 704 {
705 QTC::TC("qpdf", "QPDF_encryption rc4 decode stream"); 705 QTC::TC("qpdf", "QPDF_encryption rc4 decode stream");
706 pipeline = new Pl_RC4("RC4 stream decryption", pipeline, 706 pipeline = new Pl_RC4("RC4 stream decryption", pipeline,
707 - (unsigned char*) key.c_str(), key.length()); 707 + (unsigned char*) key.c_str(), (int)key.length());
708 } 708 }
709 heap.push_back(pipeline); 709 heap.push_back(pipeline);
710 } 710 }
libqpdf/QPDF_linearization.cc
@@ -289,7 +289,7 @@ QPDF::readLinearizationData() @@ -289,7 +289,7 @@ QPDF::readLinearizationData()
289 PointerHolder<Buffer> hbp = pb.getBuffer(); 289 PointerHolder<Buffer> hbp = pb.getBuffer();
290 Buffer* hb = hbp.getPointer(); 290 Buffer* hb = hbp.getPointer();
291 unsigned char const* h_buf = hb->getBuffer(); 291 unsigned char const* h_buf = hb->getBuffer();
292 - int h_size = hb->getSize(); 292 + int h_size = (int)hb->getSize();
293 293
294 readHPageOffset(BitStream(h_buf, h_size)); 294 readHPageOffset(BitStream(h_buf, h_size));
295 295
@@ -345,7 +345,7 @@ QPDF::readHintStream(Pipeline&amp; pl, off_t offset, size_t length) @@ -345,7 +345,7 @@ QPDF::readHintStream(Pipeline&amp; pl, off_t offset, size_t length)
345 { 345 {
346 QTC::TC("qpdf", "QPDF hint table length direct"); 346 QTC::TC("qpdf", "QPDF hint table length direct");
347 } 347 }
348 - off_t computed_end = offset + length; 348 + off_t computed_end = offset + (off_t)length;
349 if ((computed_end < min_end_offset) || 349 if ((computed_end < min_end_offset) ||
350 (computed_end > max_end_offset)) 350 (computed_end > max_end_offset))
351 { 351 {
@@ -488,7 +488,7 @@ QPDF::checkLinearizationInternal() @@ -488,7 +488,7 @@ QPDF::checkLinearizationInternal()
488 } 488 }
489 489
490 // N: number of pages 490 // N: number of pages
491 - int npages = pages.size(); 491 + int npages = (int)pages.size();
492 if (p.npages != npages) 492 if (p.npages != npages)
493 { 493 {
494 // Not tested in the test suite 494 // Not tested in the test suite
@@ -736,7 +736,7 @@ QPDF::checkHPageOffset(std::list&lt;std::string&gt;&amp; errors, @@ -736,7 +736,7 @@ QPDF::checkHPageOffset(std::list&lt;std::string&gt;&amp; errors,
736 // under a page's /Resources dictionary in with shared objects 736 // under a page's /Resources dictionary in with shared objects
737 // even when they are private. 737 // even when they are private.
738 738
739 - unsigned int npages = pages.size(); 739 + unsigned int npages = (unsigned int)pages.size();
740 int table_offset = adjusted_offset( 740 int table_offset = adjusted_offset(
741 this->page_offset_hints.first_page_offset); 741 this->page_offset_hints.first_page_offset);
742 ObjGen first_page_og(pages[0].getObjectID(), pages[0].getGeneration()); 742 ObjGen first_page_og(pages[0].getObjectID(), pages[0].getGeneration());
@@ -1425,7 +1425,7 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data) @@ -1425,7 +1425,7 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1425 pages.push_back(getUncompressedObject(*iter, object_stream_data)); 1425 pages.push_back(getUncompressedObject(*iter, object_stream_data));
1426 } 1426 }
1427 } 1427 }
1428 - unsigned int npages = pages.size(); 1428 + unsigned int npages = (unsigned int)pages.size();
1429 1429
1430 // We will be initializing some values of the computed hint 1430 // We will be initializing some values of the computed hint
1431 // tables. Specifically, we can initialize any items that deal 1431 // tables. Specifically, we can initialize any items that deal
@@ -1495,7 +1495,7 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data) @@ -1495,7 +1495,7 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1495 // in garbage values for all the shared object identifiers on the 1495 // in garbage values for all the shared object identifiers on the
1496 // first page. 1496 // first page.
1497 1497
1498 - this->c_page_offset_data.entries[0].nobjects = this->part6.size(); 1498 + this->c_page_offset_data.entries[0].nobjects = (int)this->part6.size();
1499 1499
1500 // Part 7: other pages' private objects 1500 // Part 7: other pages' private objects
1501 1501
@@ -1646,9 +1646,11 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data) @@ -1646,9 +1646,11 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1646 1646
1647 // Make sure we got everything exactly once. 1647 // Make sure we got everything exactly once.
1648 1648
1649 - unsigned int num_placed = this->part4.size() + this->part6.size() +  
1650 - this->part7.size() + this->part8.size() + this->part9.size();  
1651 - unsigned int num_wanted = this->object_to_obj_users.size(); 1649 + unsigned int num_placed =
  1650 + (unsigned int)(this->part4.size() + this->part6.size() +
  1651 + this->part7.size() + this->part8.size() +
  1652 + this->part9.size());
  1653 + unsigned int num_wanted = (unsigned int)this->object_to_obj_users.size();
1652 if (num_placed != num_wanted) 1654 if (num_placed != num_wanted)
1653 { 1655 {
1654 throw std::logic_error( 1656 throw std::logic_error(
@@ -1672,10 +1674,11 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data) @@ -1672,10 +1674,11 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1672 // can map from object number only without regards to generation. 1674 // can map from object number only without regards to generation.
1673 std::map<int, int> obj_to_index; 1675 std::map<int, int> obj_to_index;
1674 1676
1675 - this->c_shared_object_data.nshared_first_page = this->part6.size(); 1677 + this->c_shared_object_data.nshared_first_page =
  1678 + (unsigned int)this->part6.size();
1676 this->c_shared_object_data.nshared_total = 1679 this->c_shared_object_data.nshared_total =
1677 this->c_shared_object_data.nshared_first_page + 1680 this->c_shared_object_data.nshared_first_page +
1678 - this->part8.size(); 1681 + (unsigned int) this->part8.size();
1679 1682
1680 std::vector<CHSharedObjectEntry>& shared = 1683 std::vector<CHSharedObjectEntry>& shared =
1681 this->c_shared_object_data.entries; 1684 this->c_shared_object_data.entries;
@@ -1684,7 +1687,7 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data) @@ -1684,7 +1687,7 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1684 { 1687 {
1685 QPDFObjectHandle& oh = *iter; 1688 QPDFObjectHandle& oh = *iter;
1686 int obj = oh.getObjectID(); 1689 int obj = oh.getObjectID();
1687 - obj_to_index[obj] = shared.size(); 1690 + obj_to_index[obj] = (int)shared.size();
1688 shared.push_back(CHSharedObjectEntry(obj)); 1691 shared.push_back(CHSharedObjectEntry(obj));
1689 } 1692 }
1690 QTC::TC("qpdf", "QPDF lin part 8 empty", this->part8.empty() ? 1 : 0); 1693 QTC::TC("qpdf", "QPDF lin part 8 empty", this->part8.empty() ? 1 : 0);
@@ -1698,7 +1701,7 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data) @@ -1698,7 +1701,7 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1698 { 1701 {
1699 QPDFObjectHandle& oh = *iter; 1702 QPDFObjectHandle& oh = *iter;
1700 int obj = oh.getObjectID(); 1703 int obj = oh.getObjectID();
1701 - obj_to_index[obj] = shared.size(); 1704 + obj_to_index[obj] = (int)shared.size();
1702 shared.push_back(CHSharedObjectEntry(obj)); 1705 shared.push_back(CHSharedObjectEntry(obj));
1703 } 1706 }
1704 } 1707 }
@@ -1814,7 +1817,7 @@ QPDF::calculateHPageOffset( @@ -1814,7 +1817,7 @@ QPDF::calculateHPageOffset(
1814 // values. 1817 // values.
1815 1818
1816 std::vector<QPDFObjectHandle> const& pages = getAllPages(); 1819 std::vector<QPDFObjectHandle> const& pages = getAllPages();
1817 - unsigned int npages = pages.size(); 1820 + unsigned int npages = (unsigned int)pages.size();
1818 CHPageOffset& cph = this->c_page_offset_data; 1821 CHPageOffset& cph = this->c_page_offset_data;
1819 std::vector<CHPageOffsetEntry>& cphe = cph.entries; 1822 std::vector<CHPageOffsetEntry>& cphe = cph.entries;
1820 1823
@@ -2019,7 +2022,7 @@ QPDF::writeHPageOffset(BitWriter&amp; w) @@ -2019,7 +2022,7 @@ QPDF::writeHPageOffset(BitWriter&amp; w)
2019 w.writeBits(t.nbits_shared_numerator, 16); // 12 2022 w.writeBits(t.nbits_shared_numerator, 16); // 12
2020 w.writeBits(t.shared_denominator, 16); // 13 2023 w.writeBits(t.shared_denominator, 16); // 13
2021 2024
2022 - unsigned int nitems = getAllPages().size(); 2025 + unsigned int nitems = (unsigned int)getAllPages().size();
2023 std::vector<HPageOffsetEntry>& entries = t.entries; 2026 std::vector<HPageOffsetEntry>& entries = t.entries;
2024 2027
2025 write_vector_int(w, nitems, entries, 2028 write_vector_int(w, nitems, entries,
@@ -2110,12 +2113,12 @@ QPDF::generateHintStream(std::map&lt;int, QPDFXRefEntry&gt; const&amp; xref, @@ -2110,12 +2113,12 @@ QPDF::generateHintStream(std::map&lt;int, QPDFXRefEntry&gt; const&amp; xref,
2110 BitWriter w(&c); 2113 BitWriter w(&c);
2111 2114
2112 writeHPageOffset(w); 2115 writeHPageOffset(w);
2113 - S = c.getCount(); 2116 + S = (int)c.getCount();
2114 writeHSharedObject(w); 2117 writeHSharedObject(w);
2115 O = 0; 2118 O = 0;
2116 if (this->outline_hints.nobjects > 0) 2119 if (this->outline_hints.nobjects > 0)
2117 { 2120 {
2118 - O = c.getCount(); 2121 + O = (int)c.getCount();
2119 writeHGeneric(w, this->outline_hints); 2122 writeHGeneric(w, this->outline_hints);
2120 } 2123 }
2121 c.finish(); 2124 c.finish();
libqpdf/QUtil.cc
1 #include <qpdf/QUtil.hh> 1 #include <qpdf/QUtil.hh>
  2 +#include <qpdf/qpdf-config.h>
2 #include <stdio.h> 3 #include <stdio.h>
3 #include <errno.h> 4 #include <errno.h>
4 #include <ctype.h> 5 #include <ctype.h>
@@ -14,7 +15,7 @@ @@ -14,7 +15,7 @@
14 #endif 15 #endif
15 16
16 std::string 17 std::string
17 -QUtil::int_to_string(int num, int fullpad) 18 +QUtil::int_to_string(long long num, int fullpad)
18 { 19 {
19 // This routine will need to be recompiled if an int can be longer than 20 // This routine will need to be recompiled if an int can be longer than
20 // 49 digits. 21 // 49 digits.
@@ -28,14 +29,20 @@ QUtil::int_to_string(int num, int fullpad) @@ -28,14 +29,20 @@ QUtil::int_to_string(int num, int fullpad)
28 "limit"); 29 "limit");
29 } 30 }
30 31
  32 +#ifdef HAVE_PRINTF_LL
  33 +# define PRINTF_LL "ll"
  34 +#else
  35 +# define PRINTF_LL "l"
  36 +#endif
31 if (fullpad) 37 if (fullpad)
32 { 38 {
33 - sprintf(t, "%0*d", fullpad, num); 39 + sprintf(t, "%0*" PRINTF_LL "d", fullpad, num);
34 } 40 }
35 else 41 else
36 { 42 {
37 - sprintf(t, "%d", num); 43 + sprintf(t, "%" PRINTF_LL "d", num);
38 } 44 }
  45 +#undef PRINTF_LL
39 46
40 return std::string(t); 47 return std::string(t);
41 } 48 }
@@ -101,6 +108,26 @@ QUtil::fopen_wrapper(std::string const&amp; description, FILE* f) @@ -101,6 +108,26 @@ QUtil::fopen_wrapper(std::string const&amp; description, FILE* f)
101 return f; 108 return f;
102 } 109 }
103 110
  111 +int
  112 +QUtil::fseek_off_t(FILE* stream, off_t offset, int whence)
  113 +{
  114 +#if HAVE_FSEEKO
  115 + return fseeko(stream, offset, whence);
  116 +#else
  117 + return fseek(stream, offset, whence);
  118 +#endif
  119 +}
  120 +
  121 +off_t
  122 +QUtil::ftell_off_t(FILE* stream)
  123 +{
  124 +#if HAVE_FSEEKO
  125 + return ftello(stream);
  126 +#else
  127 + return ftell(stream);
  128 +#endif
  129 +}
  130 +
104 char* 131 char*
105 QUtil::copy_string(std::string const& str) 132 QUtil::copy_string(std::string const& str)
106 { 133 {
libqpdf/RC4.cc
@@ -15,7 +15,7 @@ RC4::RC4(unsigned char const* key_data, int key_len) @@ -15,7 +15,7 @@ RC4::RC4(unsigned char const* key_data, int key_len)
15 { 15 {
16 if (key_len == -1) 16 if (key_len == -1)
17 { 17 {
18 - key_len = strlen((char*)key_data); 18 + key_len = (int)strlen((char*)key_data);
19 } 19 }
20 20
21 for (int i = 0; i < 256; ++i) 21 for (int i = 0; i < 256; ++i)
libqpdf/bits.icc
@@ -95,7 +95,7 @@ read_bits(unsigned char const*&amp; p, unsigned int&amp; bit_offset, @@ -95,7 +95,7 @@ read_bits(unsigned char const*&amp; p, unsigned int&amp; bit_offset,
95 #ifdef BITS_WRITE 95 #ifdef BITS_WRITE
96 static void 96 static void
97 write_bits(unsigned char& ch, unsigned int& bit_offset, 97 write_bits(unsigned char& ch, unsigned int& bit_offset,
98 - unsigned long val, unsigned bits, Pipeline* pipeline) 98 + unsigned long val, unsigned int bits, Pipeline* pipeline)
99 { 99 {
100 if (bits > 32) 100 if (bits > 32)
101 { 101 {
libqpdf/qpdf-c.cc
@@ -462,10 +462,10 @@ static void qpdf_get_buffer_internal(qpdf_data qpdf) @@ -462,10 +462,10 @@ static void qpdf_get_buffer_internal(qpdf_data qpdf)
462 } 462 }
463 } 463 }
464 464
465 -unsigned long qpdf_get_buffer_length(qpdf_data qpdf) 465 +size_t qpdf_get_buffer_length(qpdf_data qpdf)
466 { 466 {
467 qpdf_get_buffer_internal(qpdf); 467 qpdf_get_buffer_internal(qpdf);
468 - unsigned long result = 0L; 468 + size_t result = 0;
469 if (qpdf->output_buffer) 469 if (qpdf->output_buffer)
470 { 470 {
471 result = qpdf->output_buffer->getSize(); 471 result = qpdf->output_buffer->getSize();
libqpdf/qpdf/BitWriter.hh
@@ -15,7 +15,7 @@ class BitWriter @@ -15,7 +15,7 @@ class BitWriter
15 QPDF_DLL 15 QPDF_DLL
16 BitWriter(Pipeline* pl); 16 BitWriter(Pipeline* pl);
17 QPDF_DLL 17 QPDF_DLL
18 - void writeBits(unsigned long val, int bits); 18 + void writeBits(unsigned long val, unsigned int bits);
19 // Force any partial byte to be written to the pipeline. 19 // Force any partial byte to be written to the pipeline.
20 QPDF_DLL 20 QPDF_DLL
21 void flush(); 21 void flush();
libqpdf/qpdf/Pl_AES_PDF.hh
@@ -22,7 +22,7 @@ class Pl_AES_PDF: public Pipeline @@ -22,7 +22,7 @@ class Pl_AES_PDF: public Pipeline
22 virtual ~Pl_AES_PDF(); 22 virtual ~Pl_AES_PDF();
23 23
24 QPDF_DLL 24 QPDF_DLL
25 - virtual void write(unsigned char* data, int len); 25 + virtual void write(unsigned char* data, size_t len);
26 QPDF_DLL 26 QPDF_DLL
27 virtual void finish(); 27 virtual void finish();
28 28
@@ -43,7 +43,7 @@ class Pl_AES_PDF: public Pipeline @@ -43,7 +43,7 @@ class Pl_AES_PDF: public Pipeline
43 bool encrypt; 43 bool encrypt;
44 bool cbc_mode; 44 bool cbc_mode;
45 bool first; 45 bool first;
46 - unsigned int offset; 46 + size_t offset; // offset into memory buffer
47 unsigned char key[key_size]; 47 unsigned char key[key_size];
48 uint32_t rk[key_size + 28]; 48 uint32_t rk[key_size + 28];
49 unsigned char inbuf[buf_size]; 49 unsigned char inbuf[buf_size];
libqpdf/qpdf/Pl_ASCII85Decoder.hh
@@ -11,7 +11,7 @@ class Pl_ASCII85Decoder: public Pipeline @@ -11,7 +11,7 @@ class Pl_ASCII85Decoder: public Pipeline
11 QPDF_DLL 11 QPDF_DLL
12 virtual ~Pl_ASCII85Decoder(); 12 virtual ~Pl_ASCII85Decoder();
13 QPDF_DLL 13 QPDF_DLL
14 - virtual void write(unsigned char* buf, int len); 14 + virtual void write(unsigned char* buf, size_t len);
15 QPDF_DLL 15 QPDF_DLL
16 virtual void finish(); 16 virtual void finish();
17 17
@@ -19,8 +19,8 @@ class Pl_ASCII85Decoder: public Pipeline @@ -19,8 +19,8 @@ class Pl_ASCII85Decoder: public Pipeline
19 void flush(); 19 void flush();
20 20
21 char inbuf[5]; 21 char inbuf[5];
22 - int pos;  
23 - int eod; 22 + size_t pos;
  23 + size_t eod;
24 }; 24 };
25 25
26 #endif // __PL_ASCII85DECODER_HH__ 26 #endif // __PL_ASCII85DECODER_HH__
libqpdf/qpdf/Pl_ASCIIHexDecoder.hh
@@ -11,7 +11,7 @@ class Pl_ASCIIHexDecoder: public Pipeline @@ -11,7 +11,7 @@ class Pl_ASCIIHexDecoder: public Pipeline
11 QPDF_DLL 11 QPDF_DLL
12 virtual ~Pl_ASCIIHexDecoder(); 12 virtual ~Pl_ASCIIHexDecoder();
13 QPDF_DLL 13 QPDF_DLL
14 - virtual void write(unsigned char* buf, int len); 14 + virtual void write(unsigned char* buf, size_t len);
15 QPDF_DLL 15 QPDF_DLL
16 virtual void finish(); 16 virtual void finish();
17 17
@@ -19,7 +19,7 @@ class Pl_ASCIIHexDecoder: public Pipeline @@ -19,7 +19,7 @@ class Pl_ASCIIHexDecoder: public Pipeline
19 void flush(); 19 void flush();
20 20
21 char inbuf[3]; 21 char inbuf[3];
22 - int pos; 22 + size_t pos;
23 bool eod; 23 bool eod;
24 }; 24 };
25 25
libqpdf/qpdf/Pl_LZWDecoder.hh
@@ -15,7 +15,7 @@ class Pl_LZWDecoder: public Pipeline @@ -15,7 +15,7 @@ class Pl_LZWDecoder: public Pipeline
15 QPDF_DLL 15 QPDF_DLL
16 virtual ~Pl_LZWDecoder(); 16 virtual ~Pl_LZWDecoder();
17 QPDF_DLL 17 QPDF_DLL
18 - virtual void write(unsigned char* buf, int len); 18 + virtual void write(unsigned char* buf, size_t len);
19 QPDF_DLL 19 QPDF_DLL
20 virtual void finish(); 20 virtual void finish();
21 21
libqpdf/qpdf/Pl_MD5.hh
@@ -20,7 +20,7 @@ class Pl_MD5: public Pipeline @@ -20,7 +20,7 @@ class Pl_MD5: public Pipeline
20 QPDF_DLL 20 QPDF_DLL
21 virtual ~Pl_MD5(); 21 virtual ~Pl_MD5();
22 QPDF_DLL 22 QPDF_DLL
23 - virtual void write(unsigned char*, int); 23 + virtual void write(unsigned char*, size_t);
24 QPDF_DLL 24 QPDF_DLL
25 virtual void finish(); 25 virtual void finish();
26 QPDF_DLL 26 QPDF_DLL
libqpdf/qpdf/Pl_PNGFilter.hh
@@ -30,7 +30,7 @@ class Pl_PNGFilter: public Pipeline @@ -30,7 +30,7 @@ class Pl_PNGFilter: public Pipeline
30 virtual ~Pl_PNGFilter(); 30 virtual ~Pl_PNGFilter();
31 31
32 QPDF_DLL 32 QPDF_DLL
33 - virtual void write(unsigned char* data, int len); 33 + virtual void write(unsigned char* data, size_t len);
34 QPDF_DLL 34 QPDF_DLL
35 virtual void finish(); 35 virtual void finish();
36 36
@@ -45,8 +45,8 @@ class Pl_PNGFilter: public Pipeline @@ -45,8 +45,8 @@ class Pl_PNGFilter: public Pipeline
45 unsigned char* prev_row; 45 unsigned char* prev_row;
46 unsigned char* buf1; 46 unsigned char* buf1;
47 unsigned char* buf2; 47 unsigned char* buf2;
48 - int pos;  
49 - int incoming; 48 + size_t pos;
  49 + size_t incoming;
50 }; 50 };
51 51
52 #endif // __PL_PNGFILTER_HH__ 52 #endif // __PL_PNGFILTER_HH__
libqpdf/qpdf/Pl_QPDFTokenizer.hh
@@ -18,13 +18,13 @@ class Pl_QPDFTokenizer: public Pipeline @@ -18,13 +18,13 @@ class Pl_QPDFTokenizer: public Pipeline
18 public: 18 public:
19 Pl_QPDFTokenizer(char const* identifier, Pipeline* next); 19 Pl_QPDFTokenizer(char const* identifier, Pipeline* next);
20 virtual ~Pl_QPDFTokenizer(); 20 virtual ~Pl_QPDFTokenizer();
21 - virtual void write(unsigned char* buf, int len); 21 + virtual void write(unsigned char* buf, size_t len);
22 virtual void finish(); 22 virtual void finish();
23 23
24 private: 24 private:
25 void processChar(char ch); 25 void processChar(char ch);
26 void checkUnread(); 26 void checkUnread();
27 - void writeNext(char const*, int len); 27 + void writeNext(char const*, size_t len);
28 void writeToken(QPDFTokenizer::Token&); 28 void writeToken(QPDFTokenizer::Token&);
29 29
30 QPDFTokenizer tokenizer; 30 QPDFTokenizer tokenizer;
libqpdf/qpdf/Pl_RC4.hh
@@ -14,18 +14,18 @@ class Pl_RC4: public Pipeline @@ -14,18 +14,18 @@ class Pl_RC4: public Pipeline
14 QPDF_DLL 14 QPDF_DLL
15 Pl_RC4(char const* identifier, Pipeline* next, 15 Pl_RC4(char const* identifier, Pipeline* next,
16 unsigned char const* key_data, int key_len = -1, 16 unsigned char const* key_data, int key_len = -1,
17 - int out_bufsize = def_bufsize); 17 + size_t out_bufsize = def_bufsize);
18 QPDF_DLL 18 QPDF_DLL
19 virtual ~Pl_RC4(); 19 virtual ~Pl_RC4();
20 20
21 QPDF_DLL 21 QPDF_DLL
22 - virtual void write(unsigned char* data, int len); 22 + virtual void write(unsigned char* data, size_t len);
23 QPDF_DLL 23 QPDF_DLL
24 virtual void finish(); 24 virtual void finish();
25 25
26 private: 26 private:
27 unsigned char* outbuf; 27 unsigned char* outbuf;
28 - int out_bufsize; 28 + size_t out_bufsize;
29 RC4 rc4; 29 RC4 rc4;
30 }; 30 };
31 31
libqpdf/qpdf/QPDF_Stream.hh
@@ -13,7 +13,7 @@ class QPDF_Stream: public QPDFObject @@ -13,7 +13,7 @@ class QPDF_Stream: public QPDFObject
13 public: 13 public:
14 QPDF_Stream(QPDF*, int objid, int generation, 14 QPDF_Stream(QPDF*, int objid, int generation,
15 QPDFObjectHandle stream_dict, 15 QPDFObjectHandle stream_dict,
16 - off_t offset, int length); 16 + off_t offset, size_t length);
17 virtual ~QPDF_Stream(); 17 virtual ~QPDF_Stream();
18 virtual std::string unparse(); 18 virtual std::string unparse();
19 QPDFObjectHandle getDict() const; 19 QPDFObjectHandle getDict() const;
@@ -51,7 +51,7 @@ class QPDF_Stream: public QPDFObject @@ -51,7 +51,7 @@ class QPDF_Stream: public QPDFObject
51 int generation; 51 int generation;
52 QPDFObjectHandle stream_dict; 52 QPDFObjectHandle stream_dict;
53 off_t offset; 53 off_t offset;
54 - int length; 54 + size_t length;
55 PointerHolder<Buffer> stream_data; 55 PointerHolder<Buffer> stream_data;
56 PointerHolder<QPDFObjectHandle::StreamDataProvider> stream_provider; 56 PointerHolder<QPDFObjectHandle::StreamDataProvider> stream_provider;
57 }; 57 };
libtests/aes.cc
@@ -46,7 +46,7 @@ int main(int argc, char* argv[]) @@ -46,7 +46,7 @@ int main(int argc, char* argv[])
46 usage(); 46 usage();
47 } 47 }
48 48
49 - unsigned int hexkeylen = strlen(hexkey); 49 + unsigned int hexkeylen = (unsigned int)strlen(hexkey);
50 unsigned int keylen = hexkeylen / 2; 50 unsigned int keylen = hexkeylen / 2;
51 if (keylen != Pl_AES_PDF::key_size) 51 if (keylen != Pl_AES_PDF::key_size)
52 { 52 {
@@ -93,7 +93,7 @@ int main(int argc, char* argv[]) @@ -93,7 +93,7 @@ int main(int argc, char* argv[])
93 bool done = false; 93 bool done = false;
94 while (! done) 94 while (! done)
95 { 95 {
96 - int len = fread(buf, 1, sizeof(buf), infile); 96 + size_t len = fread(buf, 1, sizeof(buf), infile);
97 if (len <= 0) 97 if (len <= 0)
98 { 98 {
99 done = true; 99 done = true;
libtests/ascii85.cc
@@ -15,7 +15,7 @@ int main() @@ -15,7 +15,7 @@ int main()
15 bool done = false; 15 bool done = false;
16 while (! done) 16 while (! done)
17 { 17 {
18 - int len = fread(buf, 1, sizeof(buf), stdin); 18 + size_t len = fread(buf, 1, sizeof(buf), stdin);
19 if (len <= 0) 19 if (len <= 0)
20 { 20 {
21 done = true; 21 done = true;
libtests/bits.cc
@@ -46,7 +46,7 @@ print_buffer(Pl_Buffer* bp) @@ -46,7 +46,7 @@ print_buffer(Pl_Buffer* bp)
46 bp->finish(); 46 bp->finish();
47 Buffer* b = bp->getBuffer(); 47 Buffer* b = bp->getBuffer();
48 unsigned char const* p = b->getBuffer(); 48 unsigned char const* p = b->getBuffer();
49 - unsigned long l = b->getSize(); 49 + size_t l = b->getSize();
50 for (unsigned long i = 0; i < l; ++i) 50 for (unsigned long i = 0; i < l; ++i)
51 { 51 {
52 printf("%02x%s", (unsigned int)(p[i]), 52 printf("%02x%s", (unsigned int)(p[i]),
libtests/hex.cc
@@ -15,7 +15,7 @@ int main() @@ -15,7 +15,7 @@ int main()
15 bool done = false; 15 bool done = false;
16 while (! done) 16 while (! done)
17 { 17 {
18 - int len = fread(buf, 1, sizeof(buf), stdin); 18 + size_t len = fread(buf, 1, sizeof(buf), stdin);
19 if (len <= 0) 19 if (len <= 0)
20 { 20 {
21 done = true; 21 done = true;
libtests/lzw.cc
@@ -38,7 +38,7 @@ int main(int argc, char* argv[]) @@ -38,7 +38,7 @@ int main(int argc, char* argv[])
38 bool done = false; 38 bool done = false;
39 while (! done) 39 while (! done)
40 { 40 {
41 - int len = fread(buf, 1, sizeof(buf), infile); 41 + size_t len = fread(buf, 1, sizeof(buf), infile);
42 if (len <= 0) 42 if (len <= 0)
43 { 43 {
44 done = true; 44 done = true;
libtests/md5.cc
@@ -54,7 +54,7 @@ int main(int, char*[]) @@ -54,7 +54,7 @@ int main(int, char*[])
54 bool done = false; 54 bool done = false;
55 while (! done) 55 while (! done)
56 { 56 {
57 - int len = fread(buf, 1, sizeof(buf), f); 57 + size_t len = fread(buf, 1, sizeof(buf), f);
58 if (len <= 0) 58 if (len <= 0)
59 { 59 {
60 done = true; 60 done = true;
libtests/rc4.cc
@@ -17,8 +17,8 @@ int main(int argc, char* argv[]) @@ -17,8 +17,8 @@ int main(int argc, char* argv[])
17 char* hexkey = argv[1]; 17 char* hexkey = argv[1];
18 char* infilename = argv[2]; 18 char* infilename = argv[2];
19 char* outfilename = argv[3]; 19 char* outfilename = argv[3];
20 - int hexkeylen = strlen(hexkey);  
21 - int keylen = hexkeylen / 2; 20 + unsigned int hexkeylen = (unsigned int)strlen(hexkey);
  21 + unsigned int keylen = hexkeylen / 2;
22 unsigned char* key = new unsigned char[keylen + 1]; 22 unsigned char* key = new unsigned char[keylen + 1];
23 key[keylen] = '\0'; 23 key[keylen] = '\0';
24 24
@@ -56,7 +56,7 @@ int main(int argc, char* argv[]) @@ -56,7 +56,7 @@ int main(int argc, char* argv[])
56 bool done = false; 56 bool done = false;
57 while (! done) 57 while (! done)
58 { 58 {
59 - int len = fread(buf, 1, sizeof(buf), infile); 59 + size_t len = fread(buf, 1, sizeof(buf), infile);
60 if (len <= 0) 60 if (len <= 0)
61 { 61 {
62 done = true; 62 done = true;
make/msvc.mk
@@ -19,6 +19,16 @@ endef @@ -19,6 +19,16 @@ endef
19 CFLAGS := $(filter-out -g,$(CFLAGS)) 19 CFLAGS := $(filter-out -g,$(CFLAGS))
20 CXXFLAGS := $(filter-out -g,$(CXXFLAGS)) 20 CXXFLAGS := $(filter-out -g,$(CXXFLAGS))
21 21
  22 +# /WX makes all warnings errors.
  23 +CFLAGS += /WX
  24 +CXXFLAGS += /WX
  25 +
  26 +# /w14267 makes warning 4267 a level 1 warning. This warning reports
  27 +# potential issues between size_t, off_t, and non-compatible integer
  28 +# types.
  29 +CFLAGS += /w14267
  30 +CXXFLAGS += /w14267
  31 +
22 clean:: 32 clean::
23 $(RM) *.pdb 33 $(RM) *.pdb
24 34
@@ -35,7 +45,7 @@ endef @@ -35,7 +45,7 @@ endef
35 # 1 2 45 # 1 2
36 # Usage: $(call c_compile,src,includes) 46 # Usage: $(call c_compile,src,includes)
37 define c_compile 47 define c_compile
38 - cl /nologo /O2 /Zi /Gy /EHsc /MD $(CPPFLAGS) $(CXXFLAGS) \ 48 + cl /nologo /O2 /Zi /Gy /EHsc /MD $(CPPFLAGS) $(CFLAGS) \
39 $(foreach I,$(2),-I$(I)) \ 49 $(foreach I,$(2),-I$(I)) \
40 /c $(1) /Fo$(call c_src_to_obj,$(1)) 50 /c $(1) /Fo$(call c_src_to_obj,$(1))
41 endef 51 endef
qpdf/test_driver.cc
@@ -74,7 +74,7 @@ void runtest(int n, char const* filename) @@ -74,7 +74,7 @@ void runtest(int n, char const* filename)
74 FILE* f = QUtil::fopen_wrapper(std::string("open ") + filename, 74 FILE* f = QUtil::fopen_wrapper(std::string("open ") + filename,
75 fopen(filename, "rb")); 75 fopen(filename, "rb"));
76 fseek(f, 0, SEEK_END); 76 fseek(f, 0, SEEK_END);
77 - size_t size = (size_t) ftell(f); 77 + size_t size = (size_t) QUtil::ftell_off_t(f);
78 fseek(f, 0, SEEK_SET); 78 fseek(f, 0, SEEK_SET);
79 file_buf = PointerHolder<char>(true, new char[size]); 79 file_buf = PointerHolder<char>(true, new char[size]);
80 char* buf_p = file_buf.getPointer(); 80 char* buf_p = file_buf.getPointer();
zlib-flate/zlib-flate.cc
@@ -70,7 +70,7 @@ int main(int argc, char* argv[]) @@ -70,7 +70,7 @@ int main(int argc, char* argv[])
70 bool done = false; 70 bool done = false;
71 while (! done) 71 while (! done)
72 { 72 {
73 - int len = fread(buf, 1, sizeof(buf), stdin); 73 + size_t len = fread(buf, 1, sizeof(buf), stdin);
74 if (len <= 0) 74 if (len <= 0)
75 { 75 {
76 done = true; 76 done = true;