From 5d4cad9c02e9d4f31477fed0e3b20b35c83936f8 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Wed, 20 Jun 2012 11:20:57 -0400 Subject: 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. --- TODO | 40 ++++-------------- configure.ac | 21 ++++++++++ include/qpdf/Buffer.hh | 11 ++--- include/qpdf/Pipeline.hh | 2 +- include/qpdf/Pl_Buffer.hh | 2 +- include/qpdf/Pl_Count.hh | 7 ++-- include/qpdf/Pl_Discard.hh | 2 +- include/qpdf/Pl_Flate.hh | 2 +- include/qpdf/Pl_StdioFile.hh | 2 +- include/qpdf/QPDF.hh | 8 ++-- include/qpdf/QPDFObjectHandle.hh | 4 +- include/qpdf/QPDFWriter.hh | 17 ++++---- include/qpdf/QPDFXRefEntry.hh | 6 +-- include/qpdf/QUtil.hh | 9 ++++- include/qpdf/qpdf-c.h | 3 +- libqpdf/BitWriter.cc | 2 +- libqpdf/Buffer.cc | 8 ++-- libqpdf/MD5.cc | 8 ++-- libqpdf/PCRE.cc | 2 +- libqpdf/Pl_AES_PDF.cc | 10 ++--- libqpdf/Pl_ASCII85Decoder.cc | 4 +- libqpdf/Pl_ASCIIHexDecoder.cc | 4 +- libqpdf/Pl_Buffer.cc | 2 +- libqpdf/Pl_Count.cc | 4 +- libqpdf/Pl_Discard.cc | 2 +- libqpdf/Pl_Flate.cc | 16 +++++++- libqpdf/Pl_LZWDecoder.cc | 10 ++--- libqpdf/Pl_MD5.cc | 17 +++++++- libqpdf/Pl_PNGFilter.cc | 6 +-- libqpdf/Pl_QPDFTokenizer.cc | 6 +-- libqpdf/Pl_RC4.cc | 11 ++--- libqpdf/Pl_StdioFile.cc | 2 +- libqpdf/QPDF.cc | 30 +++++++------- libqpdf/QPDFObjectHandle.cc | 2 +- libqpdf/QPDFTokenizer.cc | 2 +- libqpdf/QPDFWriter.cc | 83 ++++++++++++++++++++------------------ libqpdf/QPDFXRefEntry.cc | 6 +-- libqpdf/QPDF_Array.cc | 2 +- libqpdf/QPDF_Stream.cc | 8 ++-- libqpdf/QPDF_String.cc | 2 +- libqpdf/QPDF_encryption.cc | 16 ++++---- libqpdf/QPDF_linearization.cc | 37 +++++++++-------- libqpdf/QUtil.cc | 33 +++++++++++++-- libqpdf/RC4.cc | 2 +- libqpdf/bits.icc | 2 +- libqpdf/qpdf-c.cc | 4 +- libqpdf/qpdf/BitWriter.hh | 2 +- libqpdf/qpdf/Pl_AES_PDF.hh | 4 +- libqpdf/qpdf/Pl_ASCII85Decoder.hh | 6 +-- libqpdf/qpdf/Pl_ASCIIHexDecoder.hh | 4 +- libqpdf/qpdf/Pl_LZWDecoder.hh | 2 +- libqpdf/qpdf/Pl_MD5.hh | 2 +- libqpdf/qpdf/Pl_PNGFilter.hh | 6 +-- libqpdf/qpdf/Pl_QPDFTokenizer.hh | 4 +- libqpdf/qpdf/Pl_RC4.hh | 6 +-- libqpdf/qpdf/QPDF_Stream.hh | 4 +- libtests/aes.cc | 4 +- libtests/ascii85.cc | 2 +- libtests/bits.cc | 2 +- libtests/hex.cc | 2 +- libtests/lzw.cc | 2 +- libtests/md5.cc | 2 +- libtests/rc4.cc | 6 +-- make/msvc.mk | 12 +++++- qpdf/test_driver.cc | 2 +- zlib-flate/zlib-flate.cc | 2 +- 66 files changed, 315 insertions(+), 240 deletions(-) diff --git a/TODO b/TODO index 0083c89f..6e998f2c 100644 --- a/TODO +++ b/TODO @@ -1,35 +1,12 @@ Next ==== - * Get rid of off_t. size_t is okay. Use autoconf to figure out what - type to use for offsets. - - * Get rid of int/size_t/off_t inconsistencies. MSVC 2010 can find - these if you add /w14267 to the compilation. We might want to do - this by default. The easiest way to fix this on Windows is to - modify msvc.mk to add this to both cl /c lines and run - - make 2>&1 | tee build.log - - * Deal with portability issues from gcc 4.7. See portability.patch - from debian package. +*** ABI changes have been made. build.mk has been updated. * Do a Windows 64-bit build. MSVC 2010 Professional x86_64 verified to build and test cleanly in 2.3.1. Hopefully the next release will include 64-bit binary distributions and external libraries. - * Provide an option to copy encryption parameters from another file. - This would make it possible to decrypt a file, manually work with - it, and then re-encrypt it using the original encryption parameters - including a possibly unknown owner password. - - * See if I can support the new encryption formats mentioned in the - open bug on sourceforge. Check other sourceforge bugs. - - -Better 64-bit support on Windows -================================ - * Building 64-bit libraries with MSVC works with existing build.sh as long as the x86_64 version of the compiler is in the path. Currently this generates 32-bit mingw and 64-bit msvc. We need to @@ -38,16 +15,13 @@ Better 64-bit support on Windows only been verified with MSVC 2010 so far; we still need to get it working with 64-bit mingw. - * Get rid of int/size_t/off_t inconsistencies. MSVC 2010 can find - these if you add /w14267 to the compilation. We might want to do - this by default. The easiest way to fix this on Windows is to - modify msvc.mk to add this to both cl /c lines and run - - make 2>&1 | tee build.log - - Then, from emacs, compile with command cat build.log. + * Provide an option to copy encryption parameters from another file. + This would make it possible to decrypt a file, manually work with + it, and then re-encrypt it using the original encryption parameters + including a possibly unknown owner password. - This will probably require ABI changes, but it seems worth doing. + * See if I can support the new encryption formats mentioned in the + open bug on sourceforge. Check other sourceforge bugs. General diff --git a/configure.ac b/configure.ac index 05082956..3e89f978 100644 --- a/configure.ac +++ b/configure.ac @@ -37,8 +37,29 @@ if test "$BUILD_INTERNAL_LIBS" = "0"; then AC_SEARCH_LIBS(pcre_compile,pcre,,[MISSING_PCRE=1; MISSING_ANY=1]) fi +AC_SYS_LARGEFILE +AC_FUNC_FSEEKO AC_TYPE_UINT16_T AC_TYPE_UINT32_T + +AC_MSG_CHECKING(for whether printf supports %ll) +AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ +#include +#include +#include +int +main() +{ + long long a = 160591605916059ll; + char t[50]; + sprintf(t, "%lld", a); +} +]])],[qpdf_PRINTF_LL=yes],[qpdf_PRINTF_LL=no]) +AC_MSG_RESULT($qpdf_PRINTF_LL) +if test "$qpdf_PRINTF_LL" = "yes"; then + AC_DEFINE([HAVE_PRINTF_LL], [1], [Whether printf supports %ll]) +fi + AC_CHECK_FUNCS(random) # Check if LD supports linker scripts, and define conditional diff --git a/include/qpdf/Buffer.hh b/include/qpdf/Buffer.hh index 31db93e2..234d6ec0 100644 --- a/include/qpdf/Buffer.hh +++ b/include/qpdf/Buffer.hh @@ -9,6 +9,7 @@ #define __BUFFER_HH__ #include +#include // for size_t class Buffer { @@ -19,12 +20,12 @@ class Buffer // Create a Buffer object whose memory is owned by the class and // will be freed when the Buffer object is destroyed. QPDF_DLL - Buffer(unsigned long size); + Buffer(size_t size); // Create a Buffer object whose memory is owned by the caller and // will not be freed when the Buffer is destroyed. QPDF_DLL - Buffer(unsigned char* buf, unsigned long size); + Buffer(unsigned char* buf, size_t size); QPDF_DLL Buffer(Buffer const&); @@ -33,19 +34,19 @@ class Buffer QPDF_DLL ~Buffer(); QPDF_DLL - unsigned long getSize() const; + size_t getSize() const; QPDF_DLL unsigned char const* getBuffer() const; QPDF_DLL unsigned char* getBuffer(); private: - void init(unsigned long size, unsigned char* buf, bool own_memory); + void init(size_t size, unsigned char* buf, bool own_memory); void copy(Buffer const&); void destroy(); bool own_memory; - unsigned long size; + size_t size; unsigned char* buf; }; diff --git a/include/qpdf/Pipeline.hh b/include/qpdf/Pipeline.hh index 796bd0eb..4bab715a 100644 --- a/include/qpdf/Pipeline.hh +++ b/include/qpdf/Pipeline.hh @@ -46,7 +46,7 @@ class Pipeline // and then, if they are not end-of-line pipelines, call // getNext()->write or getNext()->finish. QPDF_DLL - virtual void write(unsigned char* data, int len) = 0; + virtual void write(unsigned char* data, size_t len) = 0; QPDF_DLL virtual void finish() = 0; diff --git a/include/qpdf/Pl_Buffer.hh b/include/qpdf/Pl_Buffer.hh index a85a595d..c8cdc92b 100644 --- a/include/qpdf/Pl_Buffer.hh +++ b/include/qpdf/Pl_Buffer.hh @@ -32,7 +32,7 @@ class Pl_Buffer: public Pipeline QPDF_DLL virtual ~Pl_Buffer(); QPDF_DLL - virtual void write(unsigned char*, int); + virtual void write(unsigned char*, size_t); QPDF_DLL virtual void finish(); diff --git a/include/qpdf/Pl_Count.hh b/include/qpdf/Pl_Count.hh index c2543f21..e5b8939f 100644 --- a/include/qpdf/Pl_Count.hh +++ b/include/qpdf/Pl_Count.hh @@ -12,6 +12,7 @@ // calling finish(). #include +#include class Pl_Count: public Pipeline { @@ -21,19 +22,19 @@ class Pl_Count: public Pipeline QPDF_DLL virtual ~Pl_Count(); QPDF_DLL - virtual void write(unsigned char*, int); + virtual void write(unsigned char*, size_t); QPDF_DLL virtual void finish(); // Returns the number of bytes written QPDF_DLL - int getCount() const; + off_t getCount() const; // Returns the last character written, or '\0' if no characters // have been written (in which case getCount() returns 0) QPDF_DLL unsigned char getLastChar() const; private: - int count; + off_t count; unsigned char last_char; }; diff --git a/include/qpdf/Pl_Discard.hh b/include/qpdf/Pl_Discard.hh index c08afd88..6531506a 100644 --- a/include/qpdf/Pl_Discard.hh +++ b/include/qpdf/Pl_Discard.hh @@ -24,7 +24,7 @@ class Pl_Discard: public Pipeline QPDF_DLL virtual ~Pl_Discard(); QPDF_DLL - virtual void write(unsigned char*, int); + virtual void write(unsigned char*, size_t); QPDF_DLL virtual void finish(); }; diff --git a/include/qpdf/Pl_Flate.hh b/include/qpdf/Pl_Flate.hh index 5244377e..fac9d467 100644 --- a/include/qpdf/Pl_Flate.hh +++ b/include/qpdf/Pl_Flate.hh @@ -24,7 +24,7 @@ class Pl_Flate: public Pipeline virtual ~Pl_Flate(); QPDF_DLL - virtual void write(unsigned char* data, int len); + virtual void write(unsigned char* data, size_t len); QPDF_DLL virtual void finish(); diff --git a/include/qpdf/Pl_StdioFile.hh b/include/qpdf/Pl_StdioFile.hh index b40f43bb..fc7c58c1 100644 --- a/include/qpdf/Pl_StdioFile.hh +++ b/include/qpdf/Pl_StdioFile.hh @@ -29,7 +29,7 @@ class Pl_StdioFile: public Pipeline virtual ~Pl_StdioFile(); QPDF_DLL - virtual void write(unsigned char* buf, int len); + virtual void write(unsigned char* buf, size_t len); QPDF_DLL virtual void finish(); diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh index 6a9728b1..ee9dba87 100644 --- a/include/qpdf/QPDF.hh +++ b/include/qpdf/QPDF.hh @@ -388,7 +388,7 @@ class QPDF virtual off_t tell() = 0; virtual void seek(off_t offset, int whence) = 0; virtual void rewind() = 0; - virtual size_t read(char* buffer, int length) = 0; + virtual size_t read(char* buffer, size_t length) = 0; virtual void unreadCh(char ch) = 0; protected: @@ -405,7 +405,7 @@ class QPDF virtual off_t tell(); virtual void seek(off_t offset, int whence); virtual void rewind(); - virtual size_t read(char* buffer, int length); + virtual size_t read(char* buffer, size_t length); virtual void unreadCh(char ch); private: @@ -428,7 +428,7 @@ class QPDF virtual off_t tell(); virtual void seek(off_t offset, int whence); virtual void rewind(); - virtual size_t read(char* buffer, int length); + virtual size_t read(char* buffer, size_t length); virtual void unreadCh(char ch); private: @@ -490,7 +490,7 @@ class QPDF PointerHolder input, int objid, int generation, bool in_object_stream, bool in_array, bool in_dictionary); - int recoverStreamLength( + size_t recoverStreamLength( PointerHolder input, int objid, int generation, off_t stream_offset); QPDFTokenizer::Token readToken(PointerHolder); diff --git a/include/qpdf/QPDFObjectHandle.hh b/include/qpdf/QPDFObjectHandle.hh index 6213ff10..f2ed22b7 100644 --- a/include/qpdf/QPDFObjectHandle.hh +++ b/include/qpdf/QPDFObjectHandle.hh @@ -327,7 +327,7 @@ class QPDFObjectHandle // object must be dictionary object static QPDFObjectHandle newStream( QPDF* qpdf, int objid, int generation, - QPDFObjectHandle stream_dict, off_t offset, int length) + QPDFObjectHandle stream_dict, off_t offset, size_t length) { return QPDFObjectHandle::newStream( qpdf, objid, generation, stream_dict, offset, length); @@ -371,7 +371,7 @@ class QPDFObjectHandle static QPDFObjectHandle newIndirect(QPDF*, int objid, int generation); static QPDFObjectHandle newStream( QPDF* qpdf, int objid, int generation, - QPDFObjectHandle stream_dict, off_t offset, int length); + QPDFObjectHandle stream_dict, off_t offset, size_t length); void assertInitialized() const; void assertType(char const* type_name, bool istype); diff --git a/include/qpdf/QPDFWriter.hh b/include/qpdf/QPDFWriter.hh index a8a51791..6a1c23cf 100644 --- a/include/qpdf/QPDFWriter.hh +++ b/include/qpdf/QPDFWriter.hh @@ -21,6 +21,7 @@ #include #include +#include #include @@ -219,7 +220,7 @@ class QPDFWriter void writePad(int nspaces); void assignCompressedObjectNumbers(int objid); void enqueueObject(QPDFObjectHandle object); - void writeObjectStreamOffsets(std::vector& offsets, int first_obj); + void writeObjectStreamOffsets(std::vector& offsets, int first_obj); void writeObjectStream(QPDFObjectHandle object); void writeObject(QPDFObjectHandle object, int object_stream_index = -1); void writeTrailer(trailer_e which, int size, @@ -229,7 +230,7 @@ class QPDFWriter void unparseObject(QPDFObjectHandle object, int level, unsigned int flags, // for stream dictionaries - int stream_length, bool compress); + size_t stream_length, bool compress); void unparseChild(QPDFObjectHandle child, int level, int flags); void initializeSpecialStreams(); void preserveObjectStreams(); @@ -266,8 +267,8 @@ class QPDFWriter int prev, bool suppress_offsets, int hint_id, - int hint_offset, - int hint_length); + off_t hint_offset, + off_t hint_length); int writeXRefStream(int objid, int max_id, int max_offset, trailer_e which, int first, int last, int size); int writeXRefStream(int objid, int max_id, int max_offset, @@ -275,8 +276,8 @@ class QPDFWriter // for linearization int prev, int hint_id, - int hint_offset, - int hint_length, + off_t hint_offset, + off_t hint_length, bool skip_compression); int calculateXrefStreamPadding(int xref_bytes); @@ -295,7 +296,7 @@ class QPDFWriter // stack items are of type Pl_Buffer, the buffer is retrieved. void popPipelineStack(PointerHolder* bp = 0); - void adjustAESStreamLength(unsigned long& length); + void adjustAESStreamLength(size_t& length); void pushEncryptionFilter(); void pushDiscardFilter(); @@ -336,7 +337,7 @@ class QPDFWriter std::map lengths; int next_objid; int cur_stream_length_id; - unsigned long cur_stream_length; + size_t cur_stream_length; bool added_newline; int max_ostream_index; std::set normalized_streams; diff --git a/include/qpdf/QPDFXRefEntry.hh b/include/qpdf/QPDFXRefEntry.hh index 35843970..c362cc97 100644 --- a/include/qpdf/QPDFXRefEntry.hh +++ b/include/qpdf/QPDFXRefEntry.hh @@ -23,12 +23,12 @@ class QPDFXRefEntry QPDF_DLL QPDFXRefEntry(); QPDF_DLL - QPDFXRefEntry(int type, int field1, int field2); + QPDFXRefEntry(int type, off_t field1, int field2); QPDF_DLL int getType() const; QPDF_DLL - int getOffset() const; // only for type 1 + off_t getOffset() const; // only for type 1 QPDF_DLL int getObjStreamNumber() const; // only for type 2 QPDF_DLL @@ -36,7 +36,7 @@ class QPDFXRefEntry private: int type; - int field1; + off_t field1; int field2; }; diff --git a/include/qpdf/QUtil.hh b/include/qpdf/QUtil.hh index 7f5a38df..37307101 100644 --- a/include/qpdf/QUtil.hh +++ b/include/qpdf/QUtil.hh @@ -9,6 +9,7 @@ #define __QUTIL_HH__ #include +#include #include #include #include @@ -20,7 +21,7 @@ namespace QUtil // This is a collection of useful utility functions that don't // really go anywhere else. QPDF_DLL - std::string int_to_string(int, int length = 0); + std::string int_to_string(long long, int length = 0); QPDF_DLL std::string double_to_string(double, int decimal_places = 0); @@ -44,6 +45,12 @@ namespace QUtil QPDF_DLL FILE* fopen_wrapper(std::string const&, FILE*); + // Wrap around off_t versions of fseek and ftell if available + QPDF_DLL + int fseek_off_t(FILE* stream, off_t offset, int whence); + QPDF_DLL + off_t ftell_off_t(FILE* stream); + QPDF_DLL char* copy_string(std::string const&); diff --git a/include/qpdf/qpdf-c.h b/include/qpdf/qpdf-c.h index 168da154..77af4741 100644 --- a/include/qpdf/qpdf-c.h +++ b/include/qpdf/qpdf-c.h @@ -71,6 +71,7 @@ #include #include +#include #ifdef __cplusplus extern "C" { @@ -300,7 +301,7 @@ extern "C" { * if a subsequent call to qpdf_init_write or * qpdf_init_write_memory is called. */ QPDF_DLL - unsigned long qpdf_get_buffer_length(qpdf_data qpdf); + size_t qpdf_get_buffer_length(qpdf_data qpdf); QPDF_DLL unsigned char const* qpdf_get_buffer(qpdf_data qpdf); diff --git a/libqpdf/BitWriter.cc b/libqpdf/BitWriter.cc index 5b3051d9..441501cb 100644 --- a/libqpdf/BitWriter.cc +++ b/libqpdf/BitWriter.cc @@ -12,7 +12,7 @@ BitWriter::BitWriter(Pipeline* pl) : } void -BitWriter::writeBits(unsigned long val, int bits) +BitWriter::writeBits(unsigned long val, unsigned int bits) { write_bits(this->ch, this->bit_offset, val, bits, this->pl); } diff --git a/libqpdf/Buffer.cc b/libqpdf/Buffer.cc index 71e219a1..94e69a56 100644 --- a/libqpdf/Buffer.cc +++ b/libqpdf/Buffer.cc @@ -7,12 +7,12 @@ Buffer::Buffer() init(0, 0, true); } -Buffer::Buffer(unsigned long size) +Buffer::Buffer(size_t size) { init(size, 0, true); } -Buffer::Buffer(unsigned char* buf, unsigned long size) +Buffer::Buffer(unsigned char* buf, size_t size) { init(size, buf, false); } @@ -36,7 +36,7 @@ Buffer::~Buffer() } void -Buffer::init(unsigned long size, unsigned char* buf, bool own_memory) +Buffer::init(size_t size, unsigned char* buf, bool own_memory) { this->own_memory = own_memory; this->size = size; @@ -75,7 +75,7 @@ Buffer::destroy() this->buf = 0; } -unsigned long +size_t Buffer::getSize() const { return this->size; diff --git a/libqpdf/MD5.cc b/libqpdf/MD5.cc index f00dbe4b..70be696d 100644 --- a/libqpdf/MD5.cc +++ b/libqpdf/MD5.cc @@ -308,7 +308,7 @@ void MD5::reset() void MD5::encodeString(char const* str) { - unsigned int len = strlen(str); + unsigned int len = (unsigned int)strlen(str); update((unsigned char *)str, len); final(); @@ -316,7 +316,7 @@ void MD5::encodeString(char const* str) void MD5::appendString(char const* input_string) { - update((unsigned char *)input_string, strlen(input_string)); + update((unsigned char *)input_string, (unsigned int) strlen(input_string)); } void MD5::encodeDataIncrementally(char const* data, int len) @@ -332,7 +332,7 @@ void MD5::encodeFile(char const *filename, int up_to_size) std::string("MD5: open ") + filename, fopen(filename, "rb")); - int len; + size_t len; int so_far = 0; int to_try = 1024; do @@ -344,7 +344,7 @@ void MD5::encodeFile(char const *filename, int up_to_size) len = fread(buffer, 1, to_try, file); if (len > 0) { - update(buffer, len); + update(buffer, (unsigned int) len); so_far += len; if ((up_to_size >= 0) && (so_far >= up_to_size)) { diff --git a/libqpdf/PCRE.cc b/libqpdf/PCRE.cc index 2e808aa7..1e5585b0 100644 --- a/libqpdf/PCRE.cc +++ b/libqpdf/PCRE.cc @@ -166,7 +166,7 @@ PCRE::match(char const* subject, int options, int startoffset, int size) { if (size == -1) { - size = strlen(subject); + size = (int) strlen(subject); } Match result(this->nbackrefs, subject); diff --git a/libqpdf/Pl_AES_PDF.cc b/libqpdf/Pl_AES_PDF.cc index a43d7e69..0f73c09c 100644 --- a/libqpdf/Pl_AES_PDF.cc +++ b/libqpdf/Pl_AES_PDF.cc @@ -60,9 +60,9 @@ Pl_AES_PDF::useStaticIV() } void -Pl_AES_PDF::write(unsigned char* data, int len) +Pl_AES_PDF::write(unsigned char* data, size_t len) { - unsigned int bytes_left = len; + size_t bytes_left = len; unsigned char* p = data; while (bytes_left > 0) @@ -72,8 +72,8 @@ Pl_AES_PDF::write(unsigned char* data, int len) flush(false); } - unsigned int available = this->buf_size - this->offset; - int bytes = (bytes_left < available ? bytes_left : available); + size_t available = this->buf_size - this->offset; + size_t bytes = (bytes_left < available ? bytes_left : available); bytes_left -= bytes; std::memcpy(this->inbuf + this->offset, p, bytes); this->offset += bytes; @@ -93,7 +93,7 @@ Pl_AES_PDF::finish() // Pad as described in section 3.5.1 of version 1.7 of the PDF // specification, including providing an entire block of padding // if the input was a multiple of 16 bytes. - unsigned char pad = this->buf_size - this->offset; + unsigned char pad = (unsigned char) (this->buf_size - this->offset); memset(this->inbuf + this->offset, pad, pad); this->offset = this->buf_size; flush(false); diff --git a/libqpdf/Pl_ASCII85Decoder.cc b/libqpdf/Pl_ASCII85Decoder.cc index ed73ff09..5c9c9f56 100644 --- a/libqpdf/Pl_ASCII85Decoder.cc +++ b/libqpdf/Pl_ASCII85Decoder.cc @@ -16,13 +16,13 @@ Pl_ASCII85Decoder::~Pl_ASCII85Decoder() } void -Pl_ASCII85Decoder::write(unsigned char* buf, int len) +Pl_ASCII85Decoder::write(unsigned char* buf, size_t len) { if (eod > 1) { return; } - for (int i = 0; i < len; ++i) + for (size_t i = 0; i < len; ++i) { if (eod > 1) { diff --git a/libqpdf/Pl_ASCIIHexDecoder.cc b/libqpdf/Pl_ASCIIHexDecoder.cc index 83f7376f..ca153e89 100644 --- a/libqpdf/Pl_ASCIIHexDecoder.cc +++ b/libqpdf/Pl_ASCIIHexDecoder.cc @@ -17,13 +17,13 @@ Pl_ASCIIHexDecoder::~Pl_ASCIIHexDecoder() } void -Pl_ASCIIHexDecoder::write(unsigned char* buf, int len) +Pl_ASCIIHexDecoder::write(unsigned char* buf, size_t len) { if (this->eod) { return; } - for (int i = 0; i < len; ++i) + for (size_t i = 0; i < len; ++i) { char ch = toupper(buf[i]); switch (ch) diff --git a/libqpdf/Pl_Buffer.cc b/libqpdf/Pl_Buffer.cc index 38af153d..600ee7de 100644 --- a/libqpdf/Pl_Buffer.cc +++ b/libqpdf/Pl_Buffer.cc @@ -15,7 +15,7 @@ Pl_Buffer::~Pl_Buffer() } void -Pl_Buffer::write(unsigned char* buf, int len) +Pl_Buffer::write(unsigned char* buf, size_t len) { Buffer* b = new Buffer(len); memcpy(b->getBuffer(), buf, len); diff --git a/libqpdf/Pl_Count.cc b/libqpdf/Pl_Count.cc index c682b3e7..78516343 100644 --- a/libqpdf/Pl_Count.cc +++ b/libqpdf/Pl_Count.cc @@ -12,7 +12,7 @@ Pl_Count::~Pl_Count() } void -Pl_Count::write(unsigned char* buf, int len) +Pl_Count::write(unsigned char* buf, size_t len) { if (len) { @@ -28,7 +28,7 @@ Pl_Count::finish() getNext()->finish(); } -int +off_t Pl_Count::getCount() const { return this->count; diff --git a/libqpdf/Pl_Discard.cc b/libqpdf/Pl_Discard.cc index 7b9407a1..34d49f3a 100644 --- a/libqpdf/Pl_Discard.cc +++ b/libqpdf/Pl_Discard.cc @@ -12,7 +12,7 @@ Pl_Discard::~Pl_Discard() } void -Pl_Discard::write(unsigned char* buf, int len) +Pl_Discard::write(unsigned char* buf, size_t len) { } diff --git a/libqpdf/Pl_Flate.cc b/libqpdf/Pl_Flate.cc index d166e9ab..30616707 100644 --- a/libqpdf/Pl_Flate.cc +++ b/libqpdf/Pl_Flate.cc @@ -40,7 +40,7 @@ Pl_Flate::~Pl_Flate() } void -Pl_Flate::write(unsigned char* data, int len) +Pl_Flate::write(unsigned char* data, size_t len) { if (this->outbuf == 0) { @@ -48,7 +48,19 @@ Pl_Flate::write(unsigned char* data, int len) this->identifier + ": Pl_Flate: write() called after finish() called"); } - handleData(data, len, Z_NO_FLUSH); + + // Write in chunks in case len is too big to fit in an int. + // Assume int is at least 32 bits. + static size_t const max_bytes = 1 << 30; + size_t bytes_left = len; + unsigned char* buf = data; + while (bytes_left > 0) + { + size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left); + handleData(buf, (int)bytes, Z_NO_FLUSH); + bytes_left -= bytes; + buf += bytes; + } } void diff --git a/libqpdf/Pl_LZWDecoder.cc b/libqpdf/Pl_LZWDecoder.cc index 811415bc..646e45de 100644 --- a/libqpdf/Pl_LZWDecoder.cc +++ b/libqpdf/Pl_LZWDecoder.cc @@ -25,9 +25,9 @@ Pl_LZWDecoder::~Pl_LZWDecoder() } void -Pl_LZWDecoder::write(unsigned char* bytes, int len) +Pl_LZWDecoder::write(unsigned char* bytes, size_t len) { - for (int i = 0; i < len; ++i) + for (size_t i = 0; i < len; ++i) { this->buf[next++] = bytes[i]; if (this->next == 3) @@ -131,7 +131,7 @@ Pl_LZWDecoder::addToTable(unsigned char next) assert(idx < table.size()); Buffer& b = table[idx]; last_data = b.getBuffer(); - last_size = b.getSize(); + last_size = (unsigned int) b.getSize(); } Buffer entry(1 + last_size); @@ -170,7 +170,7 @@ Pl_LZWDecoder::handleCode(int code) // be what we read last plus the first character of what // we're reading now. unsigned char next = '\0'; - unsigned int table_size = table.size(); + unsigned int table_size = (unsigned int) table.size(); if (code < 256) { // just read < 256; last time's next was code @@ -178,7 +178,7 @@ Pl_LZWDecoder::handleCode(int code) } else if (code > 257) { - unsigned int idx = code - 258; + size_t idx = code - 258; if (idx > table_size) { throw std::runtime_error("LZWDecoder: bad code received"); diff --git a/libqpdf/Pl_MD5.cc b/libqpdf/Pl_MD5.cc index 29787625..44911b42 100644 --- a/libqpdf/Pl_MD5.cc +++ b/libqpdf/Pl_MD5.cc @@ -12,14 +12,27 @@ Pl_MD5::~Pl_MD5() } void -Pl_MD5::write(unsigned char* buf, int len) +Pl_MD5::write(unsigned char* buf, size_t len) { if (! this->in_progress) { this->md5.reset(); this->in_progress = true; } - this->md5.encodeDataIncrementally((char*) buf, len); + + // Write in chunks in case len is too big to fit in an int. + // Assume int is at least 32 bits. + static size_t const max_bytes = 1 << 30; + size_t bytes_left = len; + unsigned char* data = buf; + while (bytes_left > 0) + { + size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left); + this->md5.encodeDataIncrementally((char*) data, (int)bytes); + bytes_left -= bytes; + data += bytes; + } + this->getNext()->write(buf, len); } diff --git a/libqpdf/Pl_PNGFilter.cc b/libqpdf/Pl_PNGFilter.cc index bbe10c93..19b90c03 100644 --- a/libqpdf/Pl_PNGFilter.cc +++ b/libqpdf/Pl_PNGFilter.cc @@ -29,10 +29,10 @@ Pl_PNGFilter::~Pl_PNGFilter() } void -Pl_PNGFilter::write(unsigned char* data, int len) +Pl_PNGFilter::write(unsigned char* data, size_t len) { - int left = this->incoming - this->pos; - unsigned int offset = 0; + size_t left = this->incoming - this->pos; + size_t offset = 0; while (len >= left) { // finish off current row diff --git a/libqpdf/Pl_QPDFTokenizer.cc b/libqpdf/Pl_QPDFTokenizer.cc index 3bd3fb6c..ea13fb72 100644 --- a/libqpdf/Pl_QPDFTokenizer.cc +++ b/libqpdf/Pl_QPDFTokenizer.cc @@ -22,7 +22,7 @@ Pl_QPDFTokenizer::~Pl_QPDFTokenizer() } void -Pl_QPDFTokenizer::writeNext(char const* buf, int len) +Pl_QPDFTokenizer::writeNext(char const* buf, size_t len) { if (len) { @@ -159,10 +159,10 @@ Pl_QPDFTokenizer::checkUnread() } void -Pl_QPDFTokenizer::write(unsigned char* buf, int len) +Pl_QPDFTokenizer::write(unsigned char* buf, size_t len) { checkUnread(); - for (int i = 0; i < len; ++i) + for (size_t i = 0; i < len; ++i) { processChar(buf[i]); checkUnread(); diff --git a/libqpdf/Pl_RC4.cc b/libqpdf/Pl_RC4.cc index f98c8744..74bb16b9 100644 --- a/libqpdf/Pl_RC4.cc +++ b/libqpdf/Pl_RC4.cc @@ -3,7 +3,7 @@ Pl_RC4::Pl_RC4(char const* identifier, Pipeline* next, unsigned char const* key_data, int key_len, - int out_bufsize) : + size_t out_bufsize) : Pipeline(identifier, next), out_bufsize(out_bufsize), rc4(key_data, key_len) @@ -21,7 +21,7 @@ Pl_RC4::~Pl_RC4() } void -Pl_RC4::write(unsigned char* data, int len) +Pl_RC4::write(unsigned char* data, size_t len) { if (this->outbuf == 0) { @@ -30,14 +30,15 @@ Pl_RC4::write(unsigned char* data, int len) ": Pl_RC4: write() called after finish() called"); } - int bytes_left = len; + size_t bytes_left = len; unsigned char* p = data; while (bytes_left > 0) { - int bytes = (bytes_left < this->out_bufsize ? bytes_left : out_bufsize); + size_t bytes = + (bytes_left < this->out_bufsize ? bytes_left : out_bufsize); bytes_left -= bytes; - rc4.process(p, bytes, outbuf); + rc4.process(p, (int)bytes, outbuf); p += bytes; getNext()->write(outbuf, bytes); } diff --git a/libqpdf/Pl_StdioFile.cc b/libqpdf/Pl_StdioFile.cc index bca4d4e8..e87de10c 100644 --- a/libqpdf/Pl_StdioFile.cc +++ b/libqpdf/Pl_StdioFile.cc @@ -14,7 +14,7 @@ Pl_StdioFile::~Pl_StdioFile() } void -Pl_StdioFile::write(unsigned char* buf, int len) +Pl_StdioFile::write(unsigned char* buf, size_t len) { size_t so_far = 0; while (len > 0) diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index e1a5a688..7ed00c98 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -117,7 +117,7 @@ QPDF::FileInputSource::getName() const off_t QPDF::FileInputSource::tell() { - return ftell(this->file); + return QUtil::ftell_off_t(this->file); } void @@ -126,7 +126,7 @@ QPDF::FileInputSource::seek(off_t offset, int whence) QUtil::os_wrapper(std::string("seek to ") + this->filename + ", offset " + QUtil::int_to_string(offset) + " (" + QUtil::int_to_string(whence) + ")", - fseek(this->file, offset, whence)); + QUtil::fseek_off_t(this->file, offset, whence)); } void @@ -136,9 +136,9 @@ QPDF::FileInputSource::rewind() } size_t -QPDF::FileInputSource::read(char* buffer, int length) +QPDF::FileInputSource::read(char* buffer, size_t length) { - this->last_offset = ftell(this->file); + this->last_offset = QUtil::ftell_off_t(this->file); size_t len = fread(buffer, 1, length, this->file); if ((len == 0) && ferror(this->file)) { @@ -197,7 +197,7 @@ QPDF::BufferInputSource::seek(off_t offset, int whence) break; case SEEK_END: - this->cur_offset = this->buf->getSize() + offset; + this->cur_offset = (off_t)this->buf->getSize() + offset; break; case SEEK_CUR: @@ -218,9 +218,9 @@ QPDF::BufferInputSource::rewind() } size_t -QPDF::BufferInputSource::read(char* buffer, int length) +QPDF::BufferInputSource::read(char* buffer, size_t length) { - off_t end_pos = this->buf->getSize(); + off_t end_pos = (off_t) this->buf->getSize(); if (this->cur_offset >= end_pos) { this->last_offset = end_pos; @@ -228,7 +228,7 @@ QPDF::BufferInputSource::read(char* buffer, int length) } this->last_offset = this->cur_offset; - size_t len = std::min((int)(end_pos - this->cur_offset), length); + size_t len = std::min((size_t)(end_pos - this->cur_offset), length); memcpy(buffer, buf->getBuffer() + this->cur_offset, len); this->cur_offset += len; return len; @@ -432,7 +432,7 @@ QPDF::parse(char const* password) throw QPDFExc(qpdf_e_damaged_pdf, this->file->getName(), "", 0, "can't find startxref"); } - off_t xref_offset = atoi(m2.getMatch(1).c_str()); + off_t xref_offset = atol(m2.getMatch(1).c_str()); read_xref(xref_offset); } catch (QPDFExc& e) @@ -878,10 +878,10 @@ QPDF::processXRefStream(off_t xref_offset, QPDFObjectHandle& xref_obj) entry_size += W[i]; } - int expected_size = entry_size * num_entries; + size_t expected_size = entry_size * num_entries; PointerHolder bp = xref_obj.getStreamData(); - int actual_size = bp->getSize(); + size_t actual_size = bp->getSize(); if (expected_size != actual_size) { @@ -1396,7 +1396,7 @@ QPDF::readObjectInternal(PointerHolder input, // objects since resolving a previously unresolved // indirect object will change file position. off_t stream_offset = input->tell(); - int length = 0; + size_t length = 0; try { @@ -1419,7 +1419,7 @@ QPDF::readObjectInternal(PointerHolder input, } length = length_obj.getIntValue(); - input->seek(stream_offset + length, SEEK_SET); + input->seek(stream_offset + (off_t)length, SEEK_SET); if (! (readToken(input) == QPDFTokenizer::Token( QPDFTokenizer::tt_word, "endstream"))) @@ -1457,7 +1457,7 @@ QPDF::readObjectInternal(PointerHolder input, return object; } -int +size_t QPDF::recoverStreamLength(PointerHolder input, int objid, int generation, off_t stream_offset) { @@ -1474,7 +1474,7 @@ QPDF::recoverStreamLength(PointerHolder input, input->seek(stream_offset, SEEK_SET); std::string last_line; off_t last_line_offset = 0; - int length = 0; + size_t length = 0; while (input->tell() < eof) { std::string line = input->readLine(); diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index 8567eef9..55f1bf6f 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -604,7 +604,7 @@ QPDFObjectHandle::newDictionary( QPDFObjectHandle QPDFObjectHandle::newStream(QPDF* qpdf, int objid, int generation, QPDFObjectHandle stream_dict, - off_t offset, int length) + off_t offset, size_t length) { return QPDFObjectHandle(new QPDF_Stream( qpdf, objid, generation, diff --git a/libqpdf/QPDFTokenizer.cc b/libqpdf/QPDFTokenizer.cc index caf02df4..a60e8605 100644 --- a/libqpdf/QPDFTokenizer.cc +++ b/libqpdf/QPDFTokenizer.cc @@ -175,7 +175,7 @@ QPDFTokenizer::presentCharacter(char ch) string_ignoring_newline = false; } - unsigned int bs_num_count = strlen(bs_num_register); + size_t bs_num_count = strlen(bs_num_register); bool ch_is_octal = ((ch >= '0') && (ch <= '7')); if ((bs_num_count == 3) || ((bs_num_count > 0) && (! ch_is_octal))) { diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc index 95fba4e0..832b3c86 100644 --- a/libqpdf/QPDFWriter.cc +++ b/libqpdf/QPDFWriter.cc @@ -651,7 +651,7 @@ QPDFWriter::popPipelineStack(PointerHolder* bp) } void -QPDFWriter::adjustAESStreamLength(unsigned long& length) +QPDFWriter::adjustAESStreamLength(size_t& length) { if (this->encrypted && (! this->cur_data_key.empty()) && this->encrypt_use_aes) @@ -679,7 +679,7 @@ QPDFWriter::pushEncryptionFilter() { p = new Pl_RC4("rc4 stream encryption", this->pipeline, (unsigned char*) this->cur_data_key.c_str(), - this->cur_data_key.length()); + (int)this->cur_data_key.length()); } pushPipeline(p); } @@ -879,9 +879,9 @@ QPDFWriter::writeTrailer(trailer_e which, int size, bool xref_stream, int prev) if (which == t_lin_first) { writeString(" /Prev "); - int pos = this->pipeline->getCount(); + off_t pos = this->pipeline->getCount(); writeString(QUtil::int_to_string(prev)); - int nspaces = pos + 11 - this->pipeline->getCount(); + int nspaces = (int)(pos - this->pipeline->getCount() + 11); assert(nspaces >= 0); writePad(nspaces); } @@ -926,7 +926,8 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level, void QPDFWriter::unparseObject(QPDFObjectHandle object, int level, - unsigned int flags, int stream_length, bool compress) + unsigned int flags, size_t stream_length, + bool compress) { unsigned int child_flags = flags & ~f_stream; @@ -1137,16 +1138,16 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level, Buffer* buf = bufpl.getBuffer(); val = QPDF_String( std::string((char*)buf->getBuffer(), - (size_t)buf->getSize())).unparse(true); + buf->getSize())).unparse(true); delete buf; } else { char* tmp = QUtil::copy_string(val); - unsigned int vlen = val.length(); + size_t vlen = val.length(); RC4 rc4((unsigned char const*)this->cur_data_key.c_str(), - this->cur_data_key.length()); - rc4.process((unsigned char*)tmp, vlen); + (int)this->cur_data_key.length()); + rc4.process((unsigned char*)tmp, (int)vlen); val = QPDF_String(std::string(tmp, vlen)).unparse(); delete [] tmp; } @@ -1164,7 +1165,7 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level, } void -QPDFWriter::writeObjectStreamOffsets(std::vector& offsets, +QPDFWriter::writeObjectStreamOffsets(std::vector& offsets, int first_obj) { for (unsigned int i = 0; i < offsets.size(); ++i) @@ -1190,8 +1191,8 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) int old_id = object.getObjectID(); int new_id = obj_renumber[old_id]; - std::vector offsets; - int first = 0; + std::vector offsets; + off_t first = 0; // Generate stream itself. We have to do this in two passes so we // can calculate offsets in the first pass. @@ -1209,7 +1210,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) // Adjust offsets to skip over comment before first object first = offsets[0]; - for (std::vector::iterator iter = offsets.begin(); + for (std::vector::iterator iter = offsets.begin(); iter != offsets.end(); ++iter) { *iter -= first; @@ -1280,7 +1281,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) writeStringQDF("\n "); writeString(" /Type /ObjStm"); writeStringQDF("\n "); - unsigned long length = stream_buffer->getSize(); + size_t length = stream_buffer->getSize(); adjustAESStreamLength(length); writeString(" /Length " + QUtil::int_to_string(length)); writeStringQDF("\n "); @@ -1523,8 +1524,9 @@ QPDFWriter::generateObjectStreams() // This code doesn't do anything with /Extends. std::vector const& eligible = this->pdf.getCompressibleObjects(); - unsigned int n_object_streams = (eligible.size() + 99) / 100; - unsigned int n_per = eligible.size() / n_object_streams; + unsigned int n_object_streams = + (unsigned int)((eligible.size() + 99) / 100); + unsigned int n_per = (unsigned int)(eligible.size() / n_object_streams); if (n_per * n_object_streams < eligible.size()) { ++n_per; @@ -1777,7 +1779,7 @@ QPDFWriter::writeHintStream(int hint_id) openObject(hint_id); setDataKey(hint_id); - unsigned long hlen = hint_buffer->getSize(); + size_t hlen = hint_buffer->getSize(); writeString("<< /Filter /FlateDecode /S "); writeString(QUtil::int_to_string(S)); @@ -1817,13 +1819,13 @@ QPDFWriter::writeXRefTable(trailer_e which, int first, int last, int size) int QPDFWriter::writeXRefTable(trailer_e which, int first, int last, int size, int prev, bool suppress_offsets, - int hint_id, int hint_offset, int hint_length) + int hint_id, off_t hint_offset, off_t hint_length) { writeString("xref\n"); writeString(QUtil::int_to_string(first)); writeString(" "); writeString(QUtil::int_to_string(last - first + 1)); - int space_before_zero = this->pipeline->getCount(); + off_t space_before_zero = this->pipeline->getCount(); writeString("\n"); for (int i = first; i <= last; ++i) { @@ -1865,10 +1867,10 @@ int QPDFWriter::writeXRefStream(int xref_id, int max_id, int max_offset, trailer_e which, int first, int last, int size, int prev, int hint_id, - int hint_offset, int hint_length, + off_t hint_offset, off_t hint_length, bool skip_compression) { - int xref_offset = this->pipeline->getCount(); + off_t xref_offset = this->pipeline->getCount(); int space_before_zero = xref_offset - 1; // field 1 contains offsets and object stream identifiers @@ -2021,7 +2023,8 @@ QPDFWriter::writeLinearized() // // Second half objects - int second_half_uncompressed = part7.size() + part8.size() + part9.size(); + int second_half_uncompressed = + (int)(part7.size() + part8.size() + part9.size()); int second_half_first_obj = 1; int after_second_half = 1 + second_half_uncompressed; this->next_objid = after_second_half; @@ -2077,13 +2080,13 @@ QPDFWriter::writeLinearized() int part4_end_marker = part4.back().getObjectID(); int part6_end_marker = part6.back().getObjectID(); - int space_before_zero = 0; - int file_size = 0; - int part6_end_offset = 0; - int first_half_max_obj_offset = 0; - int second_xref_offset = 0; - int first_xref_end = 0; - int second_xref_end = 0; + off_t space_before_zero = 0; + off_t file_size = 0; + off_t part6_end_offset = 0; + off_t first_half_max_obj_offset = 0; + off_t second_xref_offset = 0; + off_t first_xref_end = 0; + off_t second_xref_end = 0; this->next_objid = part4_first_obj; enqueuePart(part4); @@ -2097,7 +2100,7 @@ QPDFWriter::writeLinearized() enqueuePart(part9); assert(this->next_objid == after_second_half); - int hint_length = 0; + off_t hint_length = 0; PointerHolder hint_buffer; // Write file in two passes. Part numbers refer to PDF spec 1.4. @@ -2118,14 +2121,14 @@ QPDFWriter::writeLinearized() // space if all numerical values in the parameter dictionary // are 10 digits long plus a few extra characters for safety. - int pos = this->pipeline->getCount(); + off_t pos = this->pipeline->getCount(); openObject(lindict_id); writeString("<<"); if (pass == 2) { std::vector const& pages = pdf.getAllPages(); int first_page_object = obj_renumber[pages[0].getObjectID()]; - int npages = pages.size(); + int npages = (int)pages.size(); writeString(" /Linearized 1 /L "); writeString(QUtil::int_to_string(file_size + hint_length)); @@ -2147,15 +2150,15 @@ QPDFWriter::writeLinearized() writeString(" >>"); closeObject(lindict_id); static int const pad = 150; - int spaces = (pos + pad - this->pipeline->getCount()); + int spaces = (pos - this->pipeline->getCount() + pad); assert(spaces >= 0); writePad(spaces); writeString("\n"); // Part 3: first page cross reference table and trailer. - int first_xref_offset = this->pipeline->getCount(); - int hint_offset = 0; + off_t first_xref_offset = this->pipeline->getCount(); + off_t hint_offset = 0; if (pass == 2) { hint_offset = this->xref[hint_id].getOffset(); @@ -2183,7 +2186,7 @@ QPDFWriter::writeLinearized() hint_length + second_xref_offset, hint_id, hint_offset, hint_length, (pass == 1)); - int endpos = this->pipeline->getCount(); + off_t endpos = this->pipeline->getCount(); if (pass == 1) { // Pad so we have enough room for the real xref @@ -2260,7 +2263,7 @@ QPDFWriter::writeLinearized() t_lin_second, 0, second_half_end, second_trailer_size, 0, 0, 0, 0, (pass == 1)); - int endpos = this->pipeline->getCount(); + off_t endpos = this->pipeline->getCount(); if (pass == 1) { @@ -2274,14 +2277,14 @@ QPDFWriter::writeLinearized() else { // Make the file size the same. - int pos = this->pipeline->getCount(); + off_t pos = this->pipeline->getCount(); writePad(second_xref_end + hint_length - 1 - pos); writeString("\n"); // If this assertion fails, maybe we didn't have // enough padding above. assert(this->pipeline->getCount() == - second_xref_end + hint_length); + (off_t)(second_xref_end + hint_length)); } } else @@ -2309,7 +2312,7 @@ QPDFWriter::writeLinearized() activatePipelineStack(); writeHintStream(hint_id); popPipelineStack(&hint_buffer); - hint_length = hint_buffer->getSize(); + hint_length = (off_t)hint_buffer->getSize(); // Restore hint offset this->xref[hint_id] = QPDFXRefEntry(1, hint_offset, 0); diff --git a/libqpdf/QPDFXRefEntry.cc b/libqpdf/QPDFXRefEntry.cc index 9a08c829..dea3aab6 100644 --- a/libqpdf/QPDFXRefEntry.cc +++ b/libqpdf/QPDFXRefEntry.cc @@ -9,7 +9,7 @@ QPDFXRefEntry::QPDFXRefEntry() : { } -QPDFXRefEntry::QPDFXRefEntry(int type, int field1, int field2) : +QPDFXRefEntry::QPDFXRefEntry(int type, off_t field1, int field2) : type(type), field1(field1), field2(field2) @@ -27,7 +27,7 @@ QPDFXRefEntry::getType() const return this->type; } -int +off_t QPDFXRefEntry::getOffset() const { if (this->type != 1) @@ -46,7 +46,7 @@ QPDFXRefEntry::getObjStreamNumber() const throw std::logic_error( "getObjStreamNumber called for xref entry of type != 2"); } - return this->field1; + return (int) this->field1; } int diff --git a/libqpdf/QPDF_Array.cc b/libqpdf/QPDF_Array.cc index ab61f307..def219dd 100644 --- a/libqpdf/QPDF_Array.cc +++ b/libqpdf/QPDF_Array.cc @@ -37,7 +37,7 @@ QPDF_Array::unparse() int QPDF_Array::getNItems() const { - return this->items.size(); + return (int)this->items.size(); } QPDFObjectHandle diff --git a/libqpdf/QPDF_Stream.cc b/libqpdf/QPDF_Stream.cc index dc8c7f93..dc6692bb 100644 --- a/libqpdf/QPDF_Stream.cc +++ b/libqpdf/QPDF_Stream.cc @@ -22,7 +22,7 @@ std::map QPDF_Stream::filter_abbreviations; QPDF_Stream::QPDF_Stream(QPDF* qpdf, int objid, int generation, QPDFObjectHandle stream_dict, - off_t offset, int length) : + off_t offset, size_t length) : qpdf(qpdf), objid(objid), generation(generation), @@ -379,8 +379,8 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool filter, Pl_Count count("stream provider count", pipeline); this->stream_provider->provideStreamData( this->objid, this->generation, &count); - size_t actual_length = count.getCount(); - size_t desired_length = + off_t actual_length = count.getCount(); + off_t desired_length = this->stream_dict.getKey("/Length").getIntValue(); if (actual_length == desired_length) { @@ -446,5 +446,5 @@ QPDF_Stream::replaceFilterData(QPDFObjectHandle const& filter, this->stream_dict.replaceOrRemoveKey("/Filter", filter); this->stream_dict.replaceOrRemoveKey("/DecodeParms", decode_parms); this->stream_dict.replaceKey("/Length", - QPDFObjectHandle::newInteger(length)); + QPDFObjectHandle::newInteger((int)length)); } diff --git a/libqpdf/QPDF_String.cc b/libqpdf/QPDF_String.cc index 274b2375..2ac2ed32 100644 --- a/libqpdf/QPDF_String.cc +++ b/libqpdf/QPDF_String.cc @@ -157,7 +157,7 @@ std::string QPDF_String::getUTF8Val() const { std::string result; - unsigned int len = this->val.length(); + size_t len = this->val.length(); if ((len >= 2) && (len % 2 == 0) && (this->val[0] == '\xfe') && (this->val[1] == '\xff')) { diff --git a/libqpdf/QPDF_encryption.cc b/libqpdf/QPDF_encryption.cc index 15acf067..ee5d5685 100644 --- a/libqpdf/QPDF_encryption.cc +++ b/libqpdf/QPDF_encryption.cc @@ -29,7 +29,7 @@ static unsigned int const key_bytes = 32; void pad_or_truncate_password(std::string const& password, char k1[key_bytes]) { - int password_bytes = std::min((size_t) key_bytes, password.length()); + int password_bytes = std::min(key_bytes, (unsigned int)password.length()); int pad_bytes = key_bytes - password_bytes; memcpy(k1, password.c_str(), password_bytes); memcpy(k1 + password_bytes, padding_string, pad_bytes); @@ -121,7 +121,7 @@ QPDF::compute_data_key(std::string const& encryption_key, } MD5 md5; - md5.encodeDataIncrementally(result.c_str(), result.length()); + md5.encodeDataIncrementally(result.c_str(), (int)result.length()); MD5::Digest digest; md5.digest(digest); return std::string((char*) digest, @@ -144,7 +144,7 @@ QPDF::compute_encryption_key( pbytes[2] = (char) ((data.P >> 16) & 0xff); pbytes[3] = (char) ((data.P >> 24) & 0xff); md5.encodeDataIncrementally(pbytes, 4); - md5.encodeDataIncrementally(data.id1.c_str(), data.id1.length()); + md5.encodeDataIncrementally(data.id1.c_str(), (int)data.id1.length()); if ((data.R >= 4) && (! data.encrypt_metadata)) { char bytes[4]; @@ -218,7 +218,7 @@ compute_U_value_R3(std::string const& user_password, MD5 md5; md5.encodeDataIncrementally( pad_or_truncate_password("").c_str(), key_bytes); - md5.encodeDataIncrementally(data.id1.c_str(), data.id1.length()); + md5.encodeDataIncrementally(data.id1.c_str(), (int)data.id1.length()); MD5::Digest digest; md5.digest(digest); iterate_rc4(digest, sizeof(MD5::Digest), @@ -583,16 +583,16 @@ QPDF::decryptString(std::string& str, int objid, int generation) pl.write((unsigned char*)str.c_str(), str.length()); pl.finish(); PointerHolder buf = bufpl.getBuffer(); - str = std::string((char*)buf->getBuffer(), (size_t)buf->getSize()); + str = std::string((char*)buf->getBuffer(), buf->getSize()); } else { QTC::TC("qpdf", "QPDF_encryption rc4 decode string"); - unsigned int vlen = str.length(); + unsigned int vlen = (int)str.length(); // Using PointerHolder guarantees that tmp will // be freed even if rc4.process throws an exception. PointerHolder tmp(true, QUtil::copy_string(str)); - RC4 rc4((unsigned char const*)key.c_str(), key.length()); + RC4 rc4((unsigned char const*)key.c_str(), (int)key.length()); rc4.process((unsigned char*)tmp.getPointer(), vlen); str = std::string(tmp.getPointer(), vlen); } @@ -704,7 +704,7 @@ QPDF::decryptStream(Pipeline*& pipeline, int objid, int generation, { QTC::TC("qpdf", "QPDF_encryption rc4 decode stream"); pipeline = new Pl_RC4("RC4 stream decryption", pipeline, - (unsigned char*) key.c_str(), key.length()); + (unsigned char*) key.c_str(), (int)key.length()); } heap.push_back(pipeline); } diff --git a/libqpdf/QPDF_linearization.cc b/libqpdf/QPDF_linearization.cc index 9891890f..d4e98dde 100644 --- a/libqpdf/QPDF_linearization.cc +++ b/libqpdf/QPDF_linearization.cc @@ -289,7 +289,7 @@ QPDF::readLinearizationData() PointerHolder hbp = pb.getBuffer(); Buffer* hb = hbp.getPointer(); unsigned char const* h_buf = hb->getBuffer(); - int h_size = hb->getSize(); + int h_size = (int)hb->getSize(); readHPageOffset(BitStream(h_buf, h_size)); @@ -345,7 +345,7 @@ QPDF::readHintStream(Pipeline& pl, off_t offset, size_t length) { QTC::TC("qpdf", "QPDF hint table length direct"); } - off_t computed_end = offset + length; + off_t computed_end = offset + (off_t)length; if ((computed_end < min_end_offset) || (computed_end > max_end_offset)) { @@ -488,7 +488,7 @@ QPDF::checkLinearizationInternal() } // N: number of pages - int npages = pages.size(); + int npages = (int)pages.size(); if (p.npages != npages) { // Not tested in the test suite @@ -736,7 +736,7 @@ QPDF::checkHPageOffset(std::list& errors, // under a page's /Resources dictionary in with shared objects // even when they are private. - unsigned int npages = pages.size(); + unsigned int npages = (unsigned int)pages.size(); int table_offset = adjusted_offset( this->page_offset_hints.first_page_offset); ObjGen first_page_og(pages[0].getObjectID(), pages[0].getGeneration()); @@ -1425,7 +1425,7 @@ QPDF::calculateLinearizationData(std::map const& object_stream_data) pages.push_back(getUncompressedObject(*iter, object_stream_data)); } } - unsigned int npages = pages.size(); + unsigned int npages = (unsigned int)pages.size(); // We will be initializing some values of the computed hint // tables. Specifically, we can initialize any items that deal @@ -1495,7 +1495,7 @@ QPDF::calculateLinearizationData(std::map const& object_stream_data) // in garbage values for all the shared object identifiers on the // first page. - this->c_page_offset_data.entries[0].nobjects = this->part6.size(); + this->c_page_offset_data.entries[0].nobjects = (int)this->part6.size(); // Part 7: other pages' private objects @@ -1646,9 +1646,11 @@ QPDF::calculateLinearizationData(std::map const& object_stream_data) // Make sure we got everything exactly once. - unsigned int num_placed = this->part4.size() + this->part6.size() + - this->part7.size() + this->part8.size() + this->part9.size(); - unsigned int num_wanted = this->object_to_obj_users.size(); + unsigned int num_placed = + (unsigned int)(this->part4.size() + this->part6.size() + + this->part7.size() + this->part8.size() + + this->part9.size()); + unsigned int num_wanted = (unsigned int)this->object_to_obj_users.size(); if (num_placed != num_wanted) { throw std::logic_error( @@ -1672,10 +1674,11 @@ QPDF::calculateLinearizationData(std::map const& object_stream_data) // can map from object number only without regards to generation. std::map obj_to_index; - this->c_shared_object_data.nshared_first_page = this->part6.size(); + this->c_shared_object_data.nshared_first_page = + (unsigned int)this->part6.size(); this->c_shared_object_data.nshared_total = this->c_shared_object_data.nshared_first_page + - this->part8.size(); + (unsigned int) this->part8.size(); std::vector& shared = this->c_shared_object_data.entries; @@ -1684,7 +1687,7 @@ QPDF::calculateLinearizationData(std::map const& object_stream_data) { QPDFObjectHandle& oh = *iter; int obj = oh.getObjectID(); - obj_to_index[obj] = shared.size(); + obj_to_index[obj] = (int)shared.size(); shared.push_back(CHSharedObjectEntry(obj)); } QTC::TC("qpdf", "QPDF lin part 8 empty", this->part8.empty() ? 1 : 0); @@ -1698,7 +1701,7 @@ QPDF::calculateLinearizationData(std::map const& object_stream_data) { QPDFObjectHandle& oh = *iter; int obj = oh.getObjectID(); - obj_to_index[obj] = shared.size(); + obj_to_index[obj] = (int)shared.size(); shared.push_back(CHSharedObjectEntry(obj)); } } @@ -1814,7 +1817,7 @@ QPDF::calculateHPageOffset( // values. std::vector const& pages = getAllPages(); - unsigned int npages = pages.size(); + unsigned int npages = (unsigned int)pages.size(); CHPageOffset& cph = this->c_page_offset_data; std::vector& cphe = cph.entries; @@ -2019,7 +2022,7 @@ QPDF::writeHPageOffset(BitWriter& w) w.writeBits(t.nbits_shared_numerator, 16); // 12 w.writeBits(t.shared_denominator, 16); // 13 - unsigned int nitems = getAllPages().size(); + unsigned int nitems = (unsigned int)getAllPages().size(); std::vector& entries = t.entries; write_vector_int(w, nitems, entries, @@ -2110,12 +2113,12 @@ QPDF::generateHintStream(std::map const& xref, BitWriter w(&c); writeHPageOffset(w); - S = c.getCount(); + S = (int)c.getCount(); writeHSharedObject(w); O = 0; if (this->outline_hints.nobjects > 0) { - O = c.getCount(); + O = (int)c.getCount(); writeHGeneric(w, this->outline_hints); } c.finish(); diff --git a/libqpdf/QUtil.cc b/libqpdf/QUtil.cc index 1bdae0fe..e1071940 100644 --- a/libqpdf/QUtil.cc +++ b/libqpdf/QUtil.cc @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -14,7 +15,7 @@ #endif std::string -QUtil::int_to_string(int num, int fullpad) +QUtil::int_to_string(long long num, int fullpad) { // This routine will need to be recompiled if an int can be longer than // 49 digits. @@ -28,14 +29,20 @@ QUtil::int_to_string(int num, int fullpad) "limit"); } +#ifdef HAVE_PRINTF_LL +# define PRINTF_LL "ll" +#else +# define PRINTF_LL "l" +#endif if (fullpad) { - sprintf(t, "%0*d", fullpad, num); + sprintf(t, "%0*" PRINTF_LL "d", fullpad, num); } else { - sprintf(t, "%d", num); + sprintf(t, "%" PRINTF_LL "d", num); } +#undef PRINTF_LL return std::string(t); } @@ -101,6 +108,26 @@ QUtil::fopen_wrapper(std::string const& description, FILE* f) return f; } +int +QUtil::fseek_off_t(FILE* stream, off_t offset, int whence) +{ +#if HAVE_FSEEKO + return fseeko(stream, offset, whence); +#else + return fseek(stream, offset, whence); +#endif +} + +off_t +QUtil::ftell_off_t(FILE* stream) +{ +#if HAVE_FSEEKO + return ftello(stream); +#else + return ftell(stream); +#endif +} + char* QUtil::copy_string(std::string const& str) { diff --git a/libqpdf/RC4.cc b/libqpdf/RC4.cc index c51ebacd..b992937f 100644 --- a/libqpdf/RC4.cc +++ b/libqpdf/RC4.cc @@ -15,7 +15,7 @@ RC4::RC4(unsigned char const* key_data, int key_len) { if (key_len == -1) { - key_len = strlen((char*)key_data); + key_len = (int)strlen((char*)key_data); } for (int i = 0; i < 256; ++i) diff --git a/libqpdf/bits.icc b/libqpdf/bits.icc index e6abdf0e..31765986 100644 --- a/libqpdf/bits.icc +++ b/libqpdf/bits.icc @@ -95,7 +95,7 @@ read_bits(unsigned char const*& p, unsigned int& bit_offset, #ifdef BITS_WRITE static void write_bits(unsigned char& ch, unsigned int& bit_offset, - unsigned long val, unsigned bits, Pipeline* pipeline) + unsigned long val, unsigned int bits, Pipeline* pipeline) { if (bits > 32) { diff --git a/libqpdf/qpdf-c.cc b/libqpdf/qpdf-c.cc index 784351bc..2be301bb 100644 --- a/libqpdf/qpdf-c.cc +++ b/libqpdf/qpdf-c.cc @@ -462,10 +462,10 @@ static void qpdf_get_buffer_internal(qpdf_data qpdf) } } -unsigned long qpdf_get_buffer_length(qpdf_data qpdf) +size_t qpdf_get_buffer_length(qpdf_data qpdf) { qpdf_get_buffer_internal(qpdf); - unsigned long result = 0L; + size_t result = 0; if (qpdf->output_buffer) { result = qpdf->output_buffer->getSize(); diff --git a/libqpdf/qpdf/BitWriter.hh b/libqpdf/qpdf/BitWriter.hh index 3ca05e10..5eae398f 100644 --- a/libqpdf/qpdf/BitWriter.hh +++ b/libqpdf/qpdf/BitWriter.hh @@ -15,7 +15,7 @@ class BitWriter QPDF_DLL BitWriter(Pipeline* pl); QPDF_DLL - void writeBits(unsigned long val, int bits); + void writeBits(unsigned long val, unsigned int bits); // Force any partial byte to be written to the pipeline. QPDF_DLL void flush(); diff --git a/libqpdf/qpdf/Pl_AES_PDF.hh b/libqpdf/qpdf/Pl_AES_PDF.hh index 178ea1e1..3947506b 100644 --- a/libqpdf/qpdf/Pl_AES_PDF.hh +++ b/libqpdf/qpdf/Pl_AES_PDF.hh @@ -22,7 +22,7 @@ class Pl_AES_PDF: public Pipeline virtual ~Pl_AES_PDF(); QPDF_DLL - virtual void write(unsigned char* data, int len); + virtual void write(unsigned char* data, size_t len); QPDF_DLL virtual void finish(); @@ -43,7 +43,7 @@ class Pl_AES_PDF: public Pipeline bool encrypt; bool cbc_mode; bool first; - unsigned int offset; + size_t offset; // offset into memory buffer unsigned char key[key_size]; uint32_t rk[key_size + 28]; unsigned char inbuf[buf_size]; diff --git a/libqpdf/qpdf/Pl_ASCII85Decoder.hh b/libqpdf/qpdf/Pl_ASCII85Decoder.hh index 333e370c..001da867 100644 --- a/libqpdf/qpdf/Pl_ASCII85Decoder.hh +++ b/libqpdf/qpdf/Pl_ASCII85Decoder.hh @@ -11,7 +11,7 @@ class Pl_ASCII85Decoder: public Pipeline QPDF_DLL virtual ~Pl_ASCII85Decoder(); QPDF_DLL - virtual void write(unsigned char* buf, int len); + virtual void write(unsigned char* buf, size_t len); QPDF_DLL virtual void finish(); @@ -19,8 +19,8 @@ class Pl_ASCII85Decoder: public Pipeline void flush(); char inbuf[5]; - int pos; - int eod; + size_t pos; + size_t eod; }; #endif // __PL_ASCII85DECODER_HH__ diff --git a/libqpdf/qpdf/Pl_ASCIIHexDecoder.hh b/libqpdf/qpdf/Pl_ASCIIHexDecoder.hh index 12808dc8..1d33afde 100644 --- a/libqpdf/qpdf/Pl_ASCIIHexDecoder.hh +++ b/libqpdf/qpdf/Pl_ASCIIHexDecoder.hh @@ -11,7 +11,7 @@ class Pl_ASCIIHexDecoder: public Pipeline QPDF_DLL virtual ~Pl_ASCIIHexDecoder(); QPDF_DLL - virtual void write(unsigned char* buf, int len); + virtual void write(unsigned char* buf, size_t len); QPDF_DLL virtual void finish(); @@ -19,7 +19,7 @@ class Pl_ASCIIHexDecoder: public Pipeline void flush(); char inbuf[3]; - int pos; + size_t pos; bool eod; }; diff --git a/libqpdf/qpdf/Pl_LZWDecoder.hh b/libqpdf/qpdf/Pl_LZWDecoder.hh index b74d69e2..4121f6f2 100644 --- a/libqpdf/qpdf/Pl_LZWDecoder.hh +++ b/libqpdf/qpdf/Pl_LZWDecoder.hh @@ -15,7 +15,7 @@ class Pl_LZWDecoder: public Pipeline QPDF_DLL virtual ~Pl_LZWDecoder(); QPDF_DLL - virtual void write(unsigned char* buf, int len); + virtual void write(unsigned char* buf, size_t len); QPDF_DLL virtual void finish(); diff --git a/libqpdf/qpdf/Pl_MD5.hh b/libqpdf/qpdf/Pl_MD5.hh index 28c9f87d..13a0927d 100644 --- a/libqpdf/qpdf/Pl_MD5.hh +++ b/libqpdf/qpdf/Pl_MD5.hh @@ -20,7 +20,7 @@ class Pl_MD5: public Pipeline QPDF_DLL virtual ~Pl_MD5(); QPDF_DLL - virtual void write(unsigned char*, int); + virtual void write(unsigned char*, size_t); QPDF_DLL virtual void finish(); QPDF_DLL diff --git a/libqpdf/qpdf/Pl_PNGFilter.hh b/libqpdf/qpdf/Pl_PNGFilter.hh index d7c761bd..7d7ebe76 100644 --- a/libqpdf/qpdf/Pl_PNGFilter.hh +++ b/libqpdf/qpdf/Pl_PNGFilter.hh @@ -30,7 +30,7 @@ class Pl_PNGFilter: public Pipeline virtual ~Pl_PNGFilter(); QPDF_DLL - virtual void write(unsigned char* data, int len); + virtual void write(unsigned char* data, size_t len); QPDF_DLL virtual void finish(); @@ -45,8 +45,8 @@ class Pl_PNGFilter: public Pipeline unsigned char* prev_row; unsigned char* buf1; unsigned char* buf2; - int pos; - int incoming; + size_t pos; + size_t incoming; }; #endif // __PL_PNGFILTER_HH__ diff --git a/libqpdf/qpdf/Pl_QPDFTokenizer.hh b/libqpdf/qpdf/Pl_QPDFTokenizer.hh index 3f816f5d..0d041577 100644 --- a/libqpdf/qpdf/Pl_QPDFTokenizer.hh +++ b/libqpdf/qpdf/Pl_QPDFTokenizer.hh @@ -18,13 +18,13 @@ class Pl_QPDFTokenizer: public Pipeline public: Pl_QPDFTokenizer(char const* identifier, Pipeline* next); virtual ~Pl_QPDFTokenizer(); - virtual void write(unsigned char* buf, int len); + virtual void write(unsigned char* buf, size_t len); virtual void finish(); private: void processChar(char ch); void checkUnread(); - void writeNext(char const*, int len); + void writeNext(char const*, size_t len); void writeToken(QPDFTokenizer::Token&); QPDFTokenizer tokenizer; diff --git a/libqpdf/qpdf/Pl_RC4.hh b/libqpdf/qpdf/Pl_RC4.hh index 1a7c94ea..bb892f12 100644 --- a/libqpdf/qpdf/Pl_RC4.hh +++ b/libqpdf/qpdf/Pl_RC4.hh @@ -14,18 +14,18 @@ class Pl_RC4: public Pipeline QPDF_DLL Pl_RC4(char const* identifier, Pipeline* next, unsigned char const* key_data, int key_len = -1, - int out_bufsize = def_bufsize); + size_t out_bufsize = def_bufsize); QPDF_DLL virtual ~Pl_RC4(); QPDF_DLL - virtual void write(unsigned char* data, int len); + virtual void write(unsigned char* data, size_t len); QPDF_DLL virtual void finish(); private: unsigned char* outbuf; - int out_bufsize; + size_t out_bufsize; RC4 rc4; }; diff --git a/libqpdf/qpdf/QPDF_Stream.hh b/libqpdf/qpdf/QPDF_Stream.hh index 144a9274..f6886b62 100644 --- a/libqpdf/qpdf/QPDF_Stream.hh +++ b/libqpdf/qpdf/QPDF_Stream.hh @@ -13,7 +13,7 @@ class QPDF_Stream: public QPDFObject public: QPDF_Stream(QPDF*, int objid, int generation, QPDFObjectHandle stream_dict, - off_t offset, int length); + off_t offset, size_t length); virtual ~QPDF_Stream(); virtual std::string unparse(); QPDFObjectHandle getDict() const; @@ -51,7 +51,7 @@ class QPDF_Stream: public QPDFObject int generation; QPDFObjectHandle stream_dict; off_t offset; - int length; + size_t length; PointerHolder stream_data; PointerHolder stream_provider; }; diff --git a/libtests/aes.cc b/libtests/aes.cc index 418c3297..ad2f0dd8 100644 --- a/libtests/aes.cc +++ b/libtests/aes.cc @@ -46,7 +46,7 @@ int main(int argc, char* argv[]) usage(); } - unsigned int hexkeylen = strlen(hexkey); + unsigned int hexkeylen = (unsigned int)strlen(hexkey); unsigned int keylen = hexkeylen / 2; if (keylen != Pl_AES_PDF::key_size) { @@ -93,7 +93,7 @@ int main(int argc, char* argv[]) bool done = false; while (! done) { - int len = fread(buf, 1, sizeof(buf), infile); + size_t len = fread(buf, 1, sizeof(buf), infile); if (len <= 0) { done = true; diff --git a/libtests/ascii85.cc b/libtests/ascii85.cc index 497df79a..7fd7f69b 100644 --- a/libtests/ascii85.cc +++ b/libtests/ascii85.cc @@ -15,7 +15,7 @@ int main() bool done = false; while (! done) { - int len = fread(buf, 1, sizeof(buf), stdin); + size_t len = fread(buf, 1, sizeof(buf), stdin); if (len <= 0) { done = true; diff --git a/libtests/bits.cc b/libtests/bits.cc index b1857988..7837ac68 100644 --- a/libtests/bits.cc +++ b/libtests/bits.cc @@ -46,7 +46,7 @@ print_buffer(Pl_Buffer* bp) bp->finish(); Buffer* b = bp->getBuffer(); unsigned char const* p = b->getBuffer(); - unsigned long l = b->getSize(); + size_t l = b->getSize(); for (unsigned long i = 0; i < l; ++i) { printf("%02x%s", (unsigned int)(p[i]), diff --git a/libtests/hex.cc b/libtests/hex.cc index 0a08fcb8..4e3eefde 100644 --- a/libtests/hex.cc +++ b/libtests/hex.cc @@ -15,7 +15,7 @@ int main() bool done = false; while (! done) { - int len = fread(buf, 1, sizeof(buf), stdin); + size_t len = fread(buf, 1, sizeof(buf), stdin); if (len <= 0) { done = true; diff --git a/libtests/lzw.cc b/libtests/lzw.cc index 5bfdbbd5..6fd8ca91 100644 --- a/libtests/lzw.cc +++ b/libtests/lzw.cc @@ -38,7 +38,7 @@ int main(int argc, char* argv[]) bool done = false; while (! done) { - int len = fread(buf, 1, sizeof(buf), infile); + size_t len = fread(buf, 1, sizeof(buf), infile); if (len <= 0) { done = true; diff --git a/libtests/md5.cc b/libtests/md5.cc index 9b1ae483..ed6a7d7a 100644 --- a/libtests/md5.cc +++ b/libtests/md5.cc @@ -54,7 +54,7 @@ int main(int, char*[]) bool done = false; while (! done) { - int len = fread(buf, 1, sizeof(buf), f); + size_t len = fread(buf, 1, sizeof(buf), f); if (len <= 0) { done = true; diff --git a/libtests/rc4.cc b/libtests/rc4.cc index 8f809ec1..1328fc85 100644 --- a/libtests/rc4.cc +++ b/libtests/rc4.cc @@ -17,8 +17,8 @@ int main(int argc, char* argv[]) char* hexkey = argv[1]; char* infilename = argv[2]; char* outfilename = argv[3]; - int hexkeylen = strlen(hexkey); - int keylen = hexkeylen / 2; + unsigned int hexkeylen = (unsigned int)strlen(hexkey); + unsigned int keylen = hexkeylen / 2; unsigned char* key = new unsigned char[keylen + 1]; key[keylen] = '\0'; @@ -56,7 +56,7 @@ int main(int argc, char* argv[]) bool done = false; while (! done) { - int len = fread(buf, 1, sizeof(buf), infile); + size_t len = fread(buf, 1, sizeof(buf), infile); if (len <= 0) { done = true; diff --git a/make/msvc.mk b/make/msvc.mk index 875e5934..8ad7f589 100644 --- a/make/msvc.mk +++ b/make/msvc.mk @@ -19,6 +19,16 @@ endef CFLAGS := $(filter-out -g,$(CFLAGS)) CXXFLAGS := $(filter-out -g,$(CXXFLAGS)) +# /WX makes all warnings errors. +CFLAGS += /WX +CXXFLAGS += /WX + +# /w14267 makes warning 4267 a level 1 warning. This warning reports +# potential issues between size_t, off_t, and non-compatible integer +# types. +CFLAGS += /w14267 +CXXFLAGS += /w14267 + clean:: $(RM) *.pdb @@ -35,7 +45,7 @@ endef # 1 2 # Usage: $(call c_compile,src,includes) define c_compile - cl /nologo /O2 /Zi /Gy /EHsc /MD $(CPPFLAGS) $(CXXFLAGS) \ + cl /nologo /O2 /Zi /Gy /EHsc /MD $(CPPFLAGS) $(CFLAGS) \ $(foreach I,$(2),-I$(I)) \ /c $(1) /Fo$(call c_src_to_obj,$(1)) endef diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc index bc9bdfc9..a4d1023d 100644 --- a/qpdf/test_driver.cc +++ b/qpdf/test_driver.cc @@ -74,7 +74,7 @@ void runtest(int n, char const* filename) FILE* f = QUtil::fopen_wrapper(std::string("open ") + filename, fopen(filename, "rb")); fseek(f, 0, SEEK_END); - size_t size = (size_t) ftell(f); + size_t size = (size_t) QUtil::ftell_off_t(f); fseek(f, 0, SEEK_SET); file_buf = PointerHolder(true, new char[size]); char* buf_p = file_buf.getPointer(); diff --git a/zlib-flate/zlib-flate.cc b/zlib-flate/zlib-flate.cc index 67cd925d..9d4a62e2 100644 --- a/zlib-flate/zlib-flate.cc +++ b/zlib-flate/zlib-flate.cc @@ -70,7 +70,7 @@ int main(int argc, char* argv[]) bool done = false; while (! done) { - int len = fread(buf, 1, sizeof(buf), stdin); + size_t len = fread(buf, 1, sizeof(buf), stdin); if (len <= 0) { done = true; -- cgit v1.2.3-54-g00ecf