Commit 30027481f7f9e9191f7c8deea51850b7a76b1b1f
1 parent
babb4794
Remove all old-style casts from C++ code
Showing
43 changed files
with
346 additions
and
276 deletions
examples/pdf-create.cc
| @@ -39,7 +39,7 @@ ImageProvider::provideStreamData(int objid, int generation, | @@ -39,7 +39,7 @@ ImageProvider::provideStreamData(int objid, int generation, | ||
| 39 | { | 39 | { |
| 40 | for (int i = 0; i < width * height; ++i) | 40 | for (int i = 0; i < width * height; ++i) |
| 41 | { | 41 | { |
| 42 | - pipeline->write((unsigned char*)"\xff\x7f\x00", 3); | 42 | + pipeline->write(QUtil::unsigned_char_pointer("\xff\x7f\x00"), 3); |
| 43 | } | 43 | } |
| 44 | pipeline->finish(); | 44 | pipeline->finish(); |
| 45 | } | 45 | } |
examples/pdf-invert-images.cc
| @@ -53,7 +53,7 @@ ImageInverter::provideStreamData(int objid, int generation, | @@ -53,7 +53,7 @@ ImageInverter::provideStreamData(int objid, int generation, | ||
| 53 | unsigned char ch; | 53 | unsigned char ch; |
| 54 | for (size_t i = 0; i < size; ++i) | 54 | for (size_t i = 0; i < size; ++i) |
| 55 | { | 55 | { |
| 56 | - ch = (unsigned char)0xff - buf[i]; | 56 | + ch = static_cast<unsigned char>(0xff) - buf[i]; |
| 57 | pipeline->write(&ch, 1); | 57 | pipeline->write(&ch, 1); |
| 58 | } | 58 | } |
| 59 | pipeline->finish(); | 59 | pipeline->finish(); |
examples/pdf-parse-content.cc
| @@ -69,7 +69,7 @@ int main(int argc, char* argv[]) | @@ -69,7 +69,7 @@ int main(int argc, char* argv[]) | ||
| 69 | QPDF pdf; | 69 | QPDF pdf; |
| 70 | pdf.processFile(filename); | 70 | pdf.processFile(filename); |
| 71 | std::vector<QPDFObjectHandle> pages = pdf.getAllPages(); | 71 | std::vector<QPDFObjectHandle> pages = pdf.getAllPages(); |
| 72 | - if ((pageno < 1) || (pageno > (int)pages.size())) | 72 | + if ((pageno < 1) || (static_cast<size_t>(pageno) > pages.size())) |
| 73 | { | 73 | { |
| 74 | usage(); | 74 | usage(); |
| 75 | } | 75 | } |
include/qpdf/QPDF.hh
| @@ -931,7 +931,7 @@ class QPDF | @@ -931,7 +931,7 @@ class QPDF | ||
| 931 | void readHPageOffset(BitStream); | 931 | void readHPageOffset(BitStream); |
| 932 | void readHSharedObject(BitStream); | 932 | void readHSharedObject(BitStream); |
| 933 | void readHGeneric(BitStream, HGeneric&); | 933 | void readHGeneric(BitStream, HGeneric&); |
| 934 | - int maxEnd(ObjUser const& ou); | 934 | + qpdf_offset_t maxEnd(ObjUser const& ou); |
| 935 | qpdf_offset_t getLinearizationOffset(ObjGen const&); | 935 | qpdf_offset_t getLinearizationOffset(ObjGen const&); |
| 936 | QPDFObjectHandle getUncompressedObject( | 936 | QPDFObjectHandle getUncompressedObject( |
| 937 | QPDFObjectHandle&, std::map<int, int> const& object_stream_data); | 937 | QPDFObjectHandle&, std::map<int, int> const& object_stream_data); |
include/qpdf/QUtil.hh
| @@ -27,6 +27,17 @@ namespace QUtil | @@ -27,6 +27,17 @@ namespace QUtil | ||
| 27 | QPDF_DLL | 27 | QPDF_DLL |
| 28 | long long string_to_ll(char const* str); | 28 | long long string_to_ll(char const* str); |
| 29 | 29 | ||
| 30 | + // Pipeline's write method wants unsigned char*, but we often have | ||
| 31 | + // some other type of string. These methods do combinations of | ||
| 32 | + // const_cast and reinterpret_cast to give us an unsigned char*. | ||
| 33 | + // They should only be used when it is known that it is safe. | ||
| 34 | + // None of the pipelines in qpdf modify the data passed to them, | ||
| 35 | + // so within qpdf, it should always be safe. | ||
| 36 | + QPDF_DLL | ||
| 37 | + unsigned char* unsigned_char_pointer(std::string const& str); | ||
| 38 | + QPDF_DLL | ||
| 39 | + unsigned char* unsigned_char_pointer(char const* str); | ||
| 40 | + | ||
| 30 | // Throw std::runtime_error with a string formed by appending to | 41 | // Throw std::runtime_error with a string formed by appending to |
| 31 | // "description: " the standard string corresponding to the | 42 | // "description: " the standard string corresponding to the |
| 32 | // current value of errno. | 43 | // current value of errno. |
libqpdf/BufferInputSource.cc
| @@ -20,7 +20,7 @@ BufferInputSource::BufferInputSource(std::string const& description, | @@ -20,7 +20,7 @@ BufferInputSource::BufferInputSource(std::string const& description, | ||
| 20 | { | 20 | { |
| 21 | this->buf = new Buffer(contents.length()); | 21 | this->buf = new Buffer(contents.length()); |
| 22 | unsigned char* bp = buf->getBuffer(); | 22 | unsigned char* bp = buf->getBuffer(); |
| 23 | - memcpy(bp, (char*)contents.c_str(), contents.length()); | 23 | + memcpy(bp, contents.c_str(), contents.length()); |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | BufferInputSource::~BufferInputSource() | 26 | BufferInputSource::~BufferInputSource() |
| @@ -38,7 +38,7 @@ BufferInputSource::findAndSkipNextEOL() | @@ -38,7 +38,7 @@ BufferInputSource::findAndSkipNextEOL() | ||
| 38 | { | 38 | { |
| 39 | throw std::logic_error("INTERNAL ERROR: BufferInputSource offset < 0"); | 39 | throw std::logic_error("INTERNAL ERROR: BufferInputSource offset < 0"); |
| 40 | } | 40 | } |
| 41 | - qpdf_offset_t end_pos = (qpdf_offset_t) this->buf->getSize(); | 41 | + qpdf_offset_t end_pos = this->buf->getSize(); |
| 42 | if (this->cur_offset >= end_pos) | 42 | if (this->cur_offset >= end_pos) |
| 43 | { | 43 | { |
| 44 | this->last_offset = end_pos; | 44 | this->last_offset = end_pos; |
| @@ -47,12 +47,12 @@ BufferInputSource::findAndSkipNextEOL() | @@ -47,12 +47,12 @@ BufferInputSource::findAndSkipNextEOL() | ||
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | qpdf_offset_t result = 0; | 49 | qpdf_offset_t result = 0; |
| 50 | - size_t len = (size_t)(end_pos - this->cur_offset); | 50 | + size_t len = end_pos - this->cur_offset; |
| 51 | unsigned char const* buffer = this->buf->getBuffer(); | 51 | unsigned char const* buffer = this->buf->getBuffer(); |
| 52 | 52 | ||
| 53 | - void* start = (void*)(buffer + this->cur_offset); | ||
| 54 | - unsigned char* p1 = (unsigned char*)memchr(start, '\r', len); | ||
| 55 | - unsigned char* p2 = (unsigned char*)memchr(start, '\n', len); | 53 | + void* start = const_cast<unsigned char*>(buffer) + this->cur_offset; |
| 54 | + unsigned char* p1 = static_cast<unsigned char*>(memchr(start, '\r', len)); | ||
| 55 | + unsigned char* p2 = static_cast<unsigned char*>(memchr(start, '\n', len)); | ||
| 56 | unsigned char* p = (p1 && p2) ? std::min(p1, p2) : p1 ? p1 : p2; | 56 | unsigned char* p = (p1 && p2) ? std::min(p1, p2) : p1 ? p1 : p2; |
| 57 | if (p) | 57 | if (p) |
| 58 | { | 58 | { |
| @@ -96,7 +96,7 @@ BufferInputSource::seek(qpdf_offset_t offset, int whence) | @@ -96,7 +96,7 @@ BufferInputSource::seek(qpdf_offset_t offset, int whence) | ||
| 96 | break; | 96 | break; |
| 97 | 97 | ||
| 98 | case SEEK_END: | 98 | case SEEK_END: |
| 99 | - this->cur_offset = (qpdf_offset_t)this->buf->getSize() + offset; | 99 | + this->cur_offset = this->buf->getSize() + offset; |
| 100 | break; | 100 | break; |
| 101 | 101 | ||
| 102 | case SEEK_CUR: | 102 | case SEEK_CUR: |
| @@ -129,7 +129,7 @@ BufferInputSource::read(char* buffer, size_t length) | @@ -129,7 +129,7 @@ BufferInputSource::read(char* buffer, size_t length) | ||
| 129 | { | 129 | { |
| 130 | throw std::logic_error("INTERNAL ERROR: BufferInputSource offset < 0"); | 130 | throw std::logic_error("INTERNAL ERROR: BufferInputSource offset < 0"); |
| 131 | } | 131 | } |
| 132 | - qpdf_offset_t end_pos = (qpdf_offset_t) this->buf->getSize(); | 132 | + qpdf_offset_t end_pos = this->buf->getSize(); |
| 133 | if (this->cur_offset >= end_pos) | 133 | if (this->cur_offset >= end_pos) |
| 134 | { | 134 | { |
| 135 | this->last_offset = end_pos; | 135 | this->last_offset = end_pos; |
| @@ -137,7 +137,8 @@ BufferInputSource::read(char* buffer, size_t length) | @@ -137,7 +137,8 @@ BufferInputSource::read(char* buffer, size_t length) | ||
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | this->last_offset = this->cur_offset; | 139 | this->last_offset = this->cur_offset; |
| 140 | - size_t len = std::min((size_t)(end_pos - this->cur_offset), length); | 140 | + size_t len = std::min( |
| 141 | + static_cast<size_t>(end_pos - this->cur_offset), length); | ||
| 141 | memcpy(buffer, buf->getBuffer() + this->cur_offset, len); | 142 | memcpy(buffer, buf->getBuffer() + this->cur_offset, len); |
| 142 | this->cur_offset += len; | 143 | this->cur_offset += len; |
| 143 | return len; | 144 | return len; |
libqpdf/FileInputSource.cc
| @@ -62,8 +62,8 @@ FileInputSource::findAndSkipNextEOL() | @@ -62,8 +62,8 @@ FileInputSource::findAndSkipNextEOL() | ||
| 62 | } | 62 | } |
| 63 | else | 63 | else |
| 64 | { | 64 | { |
| 65 | - char* p1 = (char*)memchr((void*)buf, '\r', len); | ||
| 66 | - char* p2 = (char*)memchr((void*)buf, '\n', len); | 65 | + char* p1 = static_cast<char*>(memchr(buf, '\r', len)); |
| 66 | + char* p2 = static_cast<char*>(memchr(buf, '\n', len)); | ||
| 67 | char* p = (p1 && p2) ? std::min(p1, p2) : p1 ? p1 : p2; | 67 | char* p = (p1 && p2) ? std::min(p1, p2) : p1 ? p1 : p2; |
| 68 | if (p) | 68 | if (p) |
| 69 | { | 69 | { |
| @@ -137,5 +137,5 @@ void | @@ -137,5 +137,5 @@ void | ||
| 137 | FileInputSource::unreadCh(char ch) | 137 | FileInputSource::unreadCh(char ch) |
| 138 | { | 138 | { |
| 139 | QUtil::os_wrapper(this->filename + ": unread character", | 139 | QUtil::os_wrapper(this->filename + ": unread character", |
| 140 | - ungetc((unsigned char)ch, this->file)); | 140 | + ungetc(static_cast<unsigned char>(ch), this->file)); |
| 141 | } | 141 | } |
libqpdf/MD5.cc
| @@ -71,22 +71,22 @@ static unsigned char PADDING[64] = { | @@ -71,22 +71,22 @@ static unsigned char PADDING[64] = { | ||
| 71 | // FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. | 71 | // FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. |
| 72 | // Rotation is separate from addition to prevent recomputation. | 72 | // Rotation is separate from addition to prevent recomputation. |
| 73 | #define FF(a, b, c, d, x, s, ac) { \ | 73 | #define FF(a, b, c, d, x, s, ac) { \ |
| 74 | - (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ | 74 | + (a) += F ((b), (c), (d)) + (x) + static_cast<UINT4>(ac); \ |
| 75 | (a) = ROTATE_LEFT ((a), (s)); \ | 75 | (a) = ROTATE_LEFT ((a), (s)); \ |
| 76 | (a) += (b); \ | 76 | (a) += (b); \ |
| 77 | } | 77 | } |
| 78 | #define GG(a, b, c, d, x, s, ac) { \ | 78 | #define GG(a, b, c, d, x, s, ac) { \ |
| 79 | - (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ | 79 | + (a) += G ((b), (c), (d)) + (x) + static_cast<UINT4>(ac); \ |
| 80 | (a) = ROTATE_LEFT ((a), (s)); \ | 80 | (a) = ROTATE_LEFT ((a), (s)); \ |
| 81 | (a) += (b); \ | 81 | (a) += (b); \ |
| 82 | } | 82 | } |
| 83 | #define HH(a, b, c, d, x, s, ac) { \ | 83 | #define HH(a, b, c, d, x, s, ac) { \ |
| 84 | - (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ | 84 | + (a) += H ((b), (c), (d)) + (x) + static_cast<UINT4>(ac); \ |
| 85 | (a) = ROTATE_LEFT ((a), (s)); \ | 85 | (a) = ROTATE_LEFT ((a), (s)); \ |
| 86 | (a) += (b); \ | 86 | (a) += (b); \ |
| 87 | } | 87 | } |
| 88 | #define II(a, b, c, d, x, s, ac) { \ | 88 | #define II(a, b, c, d, x, s, ac) { \ |
| 89 | - (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ | 89 | + (a) += I ((b), (c), (d)) + (x) + static_cast<UINT4>(ac); \ |
| 90 | (a) = ROTATE_LEFT ((a), (s)); \ | 90 | (a) = ROTATE_LEFT ((a), (s)); \ |
| 91 | (a) += (b); \ | 91 | (a) += (b); \ |
| 92 | } | 92 | } |
| @@ -115,21 +115,20 @@ void MD5::update(unsigned char *input, | @@ -115,21 +115,20 @@ void MD5::update(unsigned char *input, | ||
| 115 | unsigned int i, index, partLen; | 115 | unsigned int i, index, partLen; |
| 116 | 116 | ||
| 117 | // Compute number of bytes mod 64 | 117 | // Compute number of bytes mod 64 |
| 118 | - index = (unsigned int)((count[0] >> 3) & 0x3F); | 118 | + index = static_cast<unsigned int>((count[0] >> 3) & 0x3f); |
| 119 | 119 | ||
| 120 | // Update number of bits | 120 | // Update number of bits |
| 121 | - if ((count[0] += ((UINT4)inputLen << 3)) | ||
| 122 | - < ((UINT4)inputLen << 3)) | 121 | + if ((count[0] += (static_cast<UINT4>(inputLen) << 3)) < |
| 122 | + (static_cast<UINT4>(inputLen) << 3)) | ||
| 123 | count[1]++; | 123 | count[1]++; |
| 124 | - count[1] += ((UINT4)inputLen >> 29); | 124 | + count[1] += (static_cast<UINT4>(inputLen) >> 29); |
| 125 | 125 | ||
| 126 | partLen = 64 - index; | 126 | partLen = 64 - index; |
| 127 | 127 | ||
| 128 | // Transform as many times as possible. | 128 | // Transform as many times as possible. |
| 129 | 129 | ||
| 130 | if (inputLen >= partLen) { | 130 | if (inputLen >= partLen) { |
| 131 | - memcpy | ||
| 132 | - ((POINTER)&buffer[index], (POINTER)input, partLen); | 131 | + memcpy(&buffer[index], input, partLen); |
| 133 | transform(state, buffer); | 132 | transform(state, buffer); |
| 134 | 133 | ||
| 135 | for (i = partLen; i + 63 < inputLen; i += 64) | 134 | for (i = partLen; i + 63 < inputLen; i += 64) |
| @@ -141,9 +140,7 @@ void MD5::update(unsigned char *input, | @@ -141,9 +140,7 @@ void MD5::update(unsigned char *input, | ||
| 141 | i = 0; | 140 | i = 0; |
| 142 | 141 | ||
| 143 | // Buffer remaining input | 142 | // Buffer remaining input |
| 144 | - memcpy | ||
| 145 | - ((POINTER)&buffer[index], (POINTER)&input[i], | ||
| 146 | - inputLen-i); | 143 | + memcpy(&buffer[index], &input[i], inputLen-i); |
| 147 | } | 144 | } |
| 148 | 145 | ||
| 149 | // MD5 finalization. Ends an MD5 message-digest operation, writing the | 146 | // MD5 finalization. Ends an MD5 message-digest operation, writing the |
| @@ -163,7 +160,7 @@ void MD5::final() | @@ -163,7 +160,7 @@ void MD5::final() | ||
| 163 | 160 | ||
| 164 | // Pad out to 56 mod 64. | 161 | // Pad out to 56 mod 64. |
| 165 | 162 | ||
| 166 | - index = (unsigned int)((count[0] >> 3) & 0x3f); | 163 | + index = static_cast<unsigned int>((count[0] >> 3) & 0x3f); |
| 167 | padLen = (index < 56) ? (56 - index) : (120 - index); | 164 | padLen = (index < 56) ? (56 - index) : (120 - index); |
| 168 | update(PADDING, padLen); | 165 | update(PADDING, padLen); |
| 169 | 166 | ||
| @@ -266,7 +263,7 @@ void MD5::transform(UINT4 state[4], unsigned char block[64]) | @@ -266,7 +263,7 @@ void MD5::transform(UINT4 state[4], unsigned char block[64]) | ||
| 266 | 263 | ||
| 267 | // Zeroize sensitive information. | 264 | // Zeroize sensitive information. |
| 268 | 265 | ||
| 269 | - memset ((POINTER)x, 0, sizeof (x)); | 266 | + memset (x, 0, sizeof (x)); |
| 270 | } | 267 | } |
| 271 | 268 | ||
| 272 | // Encodes input (UINT4) into output (unsigned char). Assumes len is a | 269 | // Encodes input (UINT4) into output (unsigned char). Assumes len is a |
| @@ -276,10 +273,10 @@ void MD5::encode(unsigned char *output, UINT4 *input, unsigned int len) | @@ -276,10 +273,10 @@ void MD5::encode(unsigned char *output, UINT4 *input, unsigned int len) | ||
| 276 | unsigned int i, j; | 273 | unsigned int i, j; |
| 277 | 274 | ||
| 278 | for (i = 0, j = 0; j < len; i++, j += 4) { | 275 | for (i = 0, j = 0; j < len; i++, j += 4) { |
| 279 | - output[j] = (unsigned char)(input[i] & 0xff); | ||
| 280 | - output[j+1] = (unsigned char)((input[i] >> 8) & 0xff); | ||
| 281 | - output[j+2] = (unsigned char)((input[i] >> 16) & 0xff); | ||
| 282 | - output[j+3] = (unsigned char)((input[i] >> 24) & 0xff); | 276 | + output[j] = static_cast<unsigned char>(input[i] & 0xff); |
| 277 | + output[j+1] = static_cast<unsigned char>((input[i] >> 8) & 0xff); | ||
| 278 | + output[j+2] = static_cast<unsigned char>((input[i] >> 16) & 0xff); | ||
| 279 | + output[j+3] = static_cast<unsigned char>((input[i] >> 24) & 0xff); | ||
| 283 | } | 280 | } |
| 284 | } | 281 | } |
| 285 | 282 | ||
| @@ -290,8 +287,11 @@ void MD5::decode(UINT4 *output, unsigned char *input, unsigned int len) | @@ -290,8 +287,11 @@ void MD5::decode(UINT4 *output, unsigned char *input, unsigned int len) | ||
| 290 | unsigned int i, j; | 287 | unsigned int i, j; |
| 291 | 288 | ||
| 292 | for (i = 0, j = 0; j < len; i++, j += 4) | 289 | for (i = 0, j = 0; j < len; i++, j += 4) |
| 293 | - output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) | | ||
| 294 | - (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24); | 290 | + output[i] = |
| 291 | + static_cast<UINT4>(input[j]) | | ||
| 292 | + (static_cast<UINT4>(input[j+1]) << 8) | | ||
| 293 | + (static_cast<UINT4>(input[j+2]) << 16) | | ||
| 294 | + (static_cast<UINT4>(input[j+3]) << 24); | ||
| 295 | } | 295 | } |
| 296 | 296 | ||
| 297 | // Public functions | 297 | // Public functions |
| @@ -308,20 +308,20 @@ void MD5::reset() | @@ -308,20 +308,20 @@ 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 = (unsigned int)strlen(str); | 311 | + unsigned int len = strlen(str); |
| 312 | 312 | ||
| 313 | - update((unsigned char *)str, len); | 313 | + update(QUtil::unsigned_char_pointer(str), len); |
| 314 | final(); | 314 | final(); |
| 315 | } | 315 | } |
| 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, (unsigned int) strlen(input_string)); | 319 | + update(QUtil::unsigned_char_pointer(input_string), 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) |
| 323 | { | 323 | { |
| 324 | - update((unsigned char *)data, len); | 324 | + update(QUtil::unsigned_char_pointer(data), len); |
| 325 | } | 325 | } |
| 326 | 326 | ||
| 327 | void MD5::encodeFile(char const *filename, int up_to_size) | 327 | 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,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, (unsigned int) len); | 347 | + update(buffer, 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 | { |
| @@ -386,7 +386,8 @@ void MD5::print() | @@ -386,7 +386,8 @@ void MD5::print() | ||
| 386 | std::string MD5::unparse() | 386 | std::string MD5::unparse() |
| 387 | { | 387 | { |
| 388 | final(); | 388 | final(); |
| 389 | - return QUtil::hex_encode(std::string((char*)digest_val, 16)); | 389 | + return QUtil::hex_encode( |
| 390 | + std::string(reinterpret_cast<char*>(digest_val), 16)); | ||
| 390 | } | 391 | } |
| 391 | 392 | ||
| 392 | std::string | 393 | std::string |
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 = (int) strlen(subject); | 169 | + size = strlen(subject); |
| 170 | } | 170 | } |
| 171 | 171 | ||
| 172 | Match result(this->nbackrefs, subject); | 172 | Match result(this->nbackrefs, subject); |
libqpdf/Pl_AES_PDF.cc
| @@ -122,7 +122,8 @@ Pl_AES_PDF::finish() | @@ -122,7 +122,8 @@ Pl_AES_PDF::finish() | ||
| 122 | // Pad as described in section 3.5.1 of version 1.7 of the PDF | 122 | // Pad as described in section 3.5.1 of version 1.7 of the PDF |
| 123 | // specification, including providing an entire block of padding | 123 | // specification, including providing an entire block of padding |
| 124 | // if the input was a multiple of 16 bytes. | 124 | // if the input was a multiple of 16 bytes. |
| 125 | - unsigned char pad = (unsigned char) (this->buf_size - this->offset); | 125 | + unsigned char pad = |
| 126 | + static_cast<unsigned char>(this->buf_size - this->offset); | ||
| 126 | memset(this->inbuf + this->offset, pad, pad); | 127 | memset(this->inbuf + this->offset, pad, pad); |
| 127 | this->offset = this->buf_size; | 128 | this->offset = this->buf_size; |
| 128 | flush(false); | 129 | flush(false); |
libqpdf/Pl_ASCII85Decoder.cc
| @@ -68,7 +68,9 @@ Pl_ASCII85Decoder::write(unsigned char* buf, size_t len) | @@ -68,7 +68,9 @@ Pl_ASCII85Decoder::write(unsigned char* buf, size_t len) | ||
| 68 | else | 68 | else |
| 69 | { | 69 | { |
| 70 | QTC::TC("libtests", "Pl_ASCII85Decoder read z"); | 70 | QTC::TC("libtests", "Pl_ASCII85Decoder read z"); |
| 71 | - getNext()->write((unsigned char*)"\000\000\000\000", 4); | 71 | + unsigned char zeroes[4]; |
| 72 | + memset(zeroes, '\0', 4); | ||
| 73 | + getNext()->write(zeroes, 4); | ||
| 72 | } | 74 | } |
| 73 | break; | 75 | break; |
| 74 | 76 |
libqpdf/Pl_ASCIIHexDecoder.cc
| @@ -91,7 +91,7 @@ Pl_ASCIIHexDecoder::flush() | @@ -91,7 +91,7 @@ Pl_ASCIIHexDecoder::flush() | ||
| 91 | b[i] = this->inbuf[i] - '0'; | 91 | b[i] = this->inbuf[i] - '0'; |
| 92 | } | 92 | } |
| 93 | } | 93 | } |
| 94 | - unsigned char ch = (unsigned char)((b[0] << 4) + b[1]); | 94 | + unsigned char ch = static_cast<unsigned char>((b[0] << 4) + b[1]); |
| 95 | 95 | ||
| 96 | QTC::TC("libtests", "Pl_ASCIIHexDecoder partial flush", | 96 | QTC::TC("libtests", "Pl_ASCIIHexDecoder partial flush", |
| 97 | (this->pos == 2) ? 0 : 1); | 97 | (this->pos == 2) ? 0 : 1); |
libqpdf/Pl_Flate.cc
| @@ -18,10 +18,10 @@ Pl_Flate::Pl_Flate(char const* identifier, Pipeline* next, | @@ -18,10 +18,10 @@ Pl_Flate::Pl_Flate(char const* identifier, Pipeline* next, | ||
| 18 | // Windows environment. | 18 | // Windows environment. |
| 19 | this->zdata = new z_stream; | 19 | this->zdata = new z_stream; |
| 20 | 20 | ||
| 21 | - z_stream& zstream = *((z_stream*) this->zdata); | ||
| 22 | - zstream.zalloc = (alloc_func)0; | ||
| 23 | - zstream.zfree = (free_func)0; | ||
| 24 | - zstream.opaque = (voidpf)0; | 21 | + z_stream& zstream = *(static_cast<z_stream*>(this->zdata)); |
| 22 | + zstream.zalloc = 0; | ||
| 23 | + zstream.zfree = 0; | ||
| 24 | + zstream.opaque = 0; | ||
| 25 | zstream.next_in = 0; | 25 | zstream.next_in = 0; |
| 26 | zstream.avail_in = 0; | 26 | zstream.avail_in = 0; |
| 27 | zstream.next_out = this->outbuf; | 27 | zstream.next_out = this->outbuf; |
| @@ -35,7 +35,7 @@ Pl_Flate::~Pl_Flate() | @@ -35,7 +35,7 @@ Pl_Flate::~Pl_Flate() | ||
| 35 | delete [] this->outbuf; | 35 | delete [] this->outbuf; |
| 36 | this->outbuf = 0; | 36 | this->outbuf = 0; |
| 37 | } | 37 | } |
| 38 | - delete (z_stream*)this->zdata; | 38 | + delete static_cast<z_stream*>(this->zdata); |
| 39 | this->zdata = 0; | 39 | this->zdata = 0; |
| 40 | } | 40 | } |
| 41 | 41 | ||
| @@ -57,7 +57,7 @@ Pl_Flate::write(unsigned char* data, size_t len) | @@ -57,7 +57,7 @@ Pl_Flate::write(unsigned char* data, size_t len) | ||
| 57 | while (bytes_left > 0) | 57 | while (bytes_left > 0) |
| 58 | { | 58 | { |
| 59 | size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left); | 59 | size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left); |
| 60 | - handleData(buf, (int)bytes, Z_NO_FLUSH); | 60 | + handleData(buf, bytes, Z_NO_FLUSH); |
| 61 | bytes_left -= bytes; | 61 | bytes_left -= bytes; |
| 62 | buf += bytes; | 62 | buf += bytes; |
| 63 | } | 63 | } |
| @@ -66,13 +66,20 @@ Pl_Flate::write(unsigned char* data, size_t len) | @@ -66,13 +66,20 @@ Pl_Flate::write(unsigned char* data, size_t len) | ||
| 66 | void | 66 | void |
| 67 | Pl_Flate::handleData(unsigned char* data, int len, int flush) | 67 | Pl_Flate::handleData(unsigned char* data, int len, int flush) |
| 68 | { | 68 | { |
| 69 | - z_stream& zstream = *((z_stream*) this->zdata); | 69 | + z_stream& zstream = *(static_cast<z_stream*>(this->zdata)); |
| 70 | zstream.next_in = data; | 70 | zstream.next_in = data; |
| 71 | zstream.avail_in = len; | 71 | zstream.avail_in = len; |
| 72 | 72 | ||
| 73 | if (! this->initialized) | 73 | if (! this->initialized) |
| 74 | { | 74 | { |
| 75 | int err = Z_OK; | 75 | int err = Z_OK; |
| 76 | + | ||
| 77 | + // deflateInit and inflateInit are macros that use old-style | ||
| 78 | + // casts. | ||
| 79 | +#ifdef __GNUC__ | ||
| 80 | +# pragma GCC diagnostic push | ||
| 81 | +# pragma GCC diagnostic ignored "-Wold-style-cast" | ||
| 82 | +#endif | ||
| 76 | if (this->action == a_deflate) | 83 | if (this->action == a_deflate) |
| 77 | { | 84 | { |
| 78 | err = deflateInit(&zstream, Z_DEFAULT_COMPRESSION); | 85 | err = deflateInit(&zstream, Z_DEFAULT_COMPRESSION); |
| @@ -81,6 +88,10 @@ Pl_Flate::handleData(unsigned char* data, int len, int flush) | @@ -81,6 +88,10 @@ Pl_Flate::handleData(unsigned char* data, int len, int flush) | ||
| 81 | { | 88 | { |
| 82 | err = inflateInit(&zstream); | 89 | err = inflateInit(&zstream); |
| 83 | } | 90 | } |
| 91 | +#ifdef __GNUC__ | ||
| 92 | +# pragma GCC diagnostic pop | ||
| 93 | +#endif | ||
| 94 | + | ||
| 84 | checkError("Init", err); | 95 | checkError("Init", err); |
| 85 | this->initialized = true; | 96 | this->initialized = true; |
| 86 | } | 97 | } |
| @@ -146,7 +157,7 @@ Pl_Flate::finish() | @@ -146,7 +157,7 @@ Pl_Flate::finish() | ||
| 146 | { | 157 | { |
| 147 | if (this->initialized) | 158 | if (this->initialized) |
| 148 | { | 159 | { |
| 149 | - z_stream& zstream = *((z_stream*) this->zdata); | 160 | + z_stream& zstream = *(static_cast<z_stream*>(this->zdata)); |
| 150 | unsigned char buf[1]; | 161 | unsigned char buf[1]; |
| 151 | buf[0] = '\0'; | 162 | buf[0] = '\0'; |
| 152 | handleData(buf, 0, Z_FINISH); | 163 | handleData(buf, 0, Z_FINISH); |
| @@ -171,7 +182,7 @@ Pl_Flate::finish() | @@ -171,7 +182,7 @@ Pl_Flate::finish() | ||
| 171 | void | 182 | void |
| 172 | Pl_Flate::checkError(char const* prefix, int error_code) | 183 | Pl_Flate::checkError(char const* prefix, int error_code) |
| 173 | { | 184 | { |
| 174 | - z_stream& zstream = *((z_stream*) this->zdata); | 185 | + z_stream& zstream = *(static_cast<z_stream*>(this->zdata)); |
| 175 | if (error_code != Z_OK) | 186 | if (error_code != Z_OK) |
| 176 | { | 187 | { |
| 177 | char const* action_str = (action == a_deflate ? "deflate" : "inflate"); | 188 | char const* action_str = (action == a_deflate ? "deflate" : "inflate"); |
libqpdf/Pl_LZWDecoder.cc
| @@ -98,7 +98,7 @@ Pl_LZWDecoder::getFirstChar(int code) | @@ -98,7 +98,7 @@ Pl_LZWDecoder::getFirstChar(int code) | ||
| 98 | unsigned char result = '\0'; | 98 | unsigned char result = '\0'; |
| 99 | if (code < 256) | 99 | if (code < 256) |
| 100 | { | 100 | { |
| 101 | - result = (unsigned char) code; | 101 | + result = static_cast<unsigned char>(code); |
| 102 | } | 102 | } |
| 103 | else | 103 | else |
| 104 | { | 104 | { |
| @@ -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 = (unsigned int) b.getSize(); | 134 | + last_size = 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 = (unsigned int) table.size(); | 173 | + unsigned int table_size = 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 |
| @@ -214,7 +214,7 @@ Pl_LZWDecoder::handleCode(int code) | @@ -214,7 +214,7 @@ Pl_LZWDecoder::handleCode(int code) | ||
| 214 | 214 | ||
| 215 | if (code < 256) | 215 | if (code < 256) |
| 216 | { | 216 | { |
| 217 | - unsigned char ch = (unsigned char) code; | 217 | + unsigned char ch = static_cast<unsigned char>(code); |
| 218 | getNext()->write(&ch, 1); | 218 | getNext()->write(&ch, 1); |
| 219 | } | 219 | } |
| 220 | else | 220 | else |
libqpdf/Pl_MD5.cc
| @@ -28,7 +28,8 @@ Pl_MD5::write(unsigned char* buf, size_t len) | @@ -28,7 +28,8 @@ Pl_MD5::write(unsigned char* buf, size_t len) | ||
| 28 | while (bytes_left > 0) | 28 | while (bytes_left > 0) |
| 29 | { | 29 | { |
| 30 | size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left); | 30 | size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left); |
| 31 | - this->md5.encodeDataIncrementally((char*) data, (int)bytes); | 31 | + this->md5.encodeDataIncrementally( |
| 32 | + reinterpret_cast<char*>(data), bytes); | ||
| 32 | bytes_left -= bytes; | 33 | bytes_left -= bytes; |
| 33 | data += bytes; | 34 | data += bytes; |
| 34 | } | 35 | } |
libqpdf/Pl_PNGFilter.cc
| @@ -73,7 +73,7 @@ Pl_PNGFilter::processRow() | @@ -73,7 +73,7 @@ Pl_PNGFilter::processRow() | ||
| 73 | void | 73 | void |
| 74 | Pl_PNGFilter::decodeRow() | 74 | Pl_PNGFilter::decodeRow() |
| 75 | { | 75 | { |
| 76 | - int filter = (int) this->cur_row[0]; | 76 | + int filter = this->cur_row[0]; |
| 77 | if (this->prev_row) | 77 | if (this->prev_row) |
| 78 | { | 78 | { |
| 79 | switch (filter) | 79 | switch (filter) |
libqpdf/Pl_RC4.cc
| @@ -38,7 +38,7 @@ Pl_RC4::write(unsigned char* data, size_t len) | @@ -38,7 +38,7 @@ Pl_RC4::write(unsigned char* data, size_t len) | ||
| 38 | size_t bytes = | 38 | size_t bytes = |
| 39 | (bytes_left < this->out_bufsize ? bytes_left : out_bufsize); | 39 | (bytes_left < this->out_bufsize ? bytes_left : out_bufsize); |
| 40 | bytes_left -= bytes; | 40 | bytes_left -= bytes; |
| 41 | - rc4.process(p, (int)bytes, outbuf); | 41 | + rc4.process(p, bytes, outbuf); |
| 42 | p += bytes; | 42 | p += bytes; |
| 43 | getNext()->write(outbuf, bytes); | 43 | getNext()->write(outbuf, bytes); |
| 44 | } | 44 | } |
libqpdf/Pl_SHA2.cc
| @@ -128,13 +128,16 @@ Pl_SHA2::getRawDigest() | @@ -128,13 +128,16 @@ Pl_SHA2::getRawDigest() | ||
| 128 | switch (bits) | 128 | switch (bits) |
| 129 | { | 129 | { |
| 130 | case 256: | 130 | case 256: |
| 131 | - result = std::string((char*)this->sha256sum, sizeof(this->sha256sum)); | 131 | + result = std::string(reinterpret_cast<char*>(this->sha256sum), |
| 132 | + sizeof(this->sha256sum)); | ||
| 132 | break; | 133 | break; |
| 133 | case 384: | 134 | case 384: |
| 134 | - result = std::string((char*)this->sha384sum, sizeof(this->sha384sum)); | 135 | + result = std::string(reinterpret_cast<char*>(this->sha384sum), |
| 136 | + sizeof(this->sha384sum)); | ||
| 135 | break; | 137 | break; |
| 136 | case 512: | 138 | case 512: |
| 137 | - result = std::string((char*)this->sha512sum, sizeof(this->sha512sum)); | 139 | + result = std::string(reinterpret_cast<char*>(this->sha512sum), |
| 140 | + sizeof(this->sha512sum)); | ||
| 138 | break; | 141 | break; |
| 139 | default: | 142 | default: |
| 140 | badBits(); | 143 | badBits(); |
libqpdf/QPDF.cc
| @@ -159,9 +159,10 @@ QPDF::processMemoryFile(char const* description, | @@ -159,9 +159,10 @@ QPDF::processMemoryFile(char const* description, | ||
| 159 | char const* password) | 159 | char const* password) |
| 160 | { | 160 | { |
| 161 | processInputSource( | 161 | processInputSource( |
| 162 | - new BufferInputSource(description, | ||
| 163 | - new Buffer((unsigned char*)buf, length), | ||
| 164 | - true), | 162 | + new BufferInputSource( |
| 163 | + description, | ||
| 164 | + new Buffer(QUtil::unsigned_char_pointer(buf), length), | ||
| 165 | + true), | ||
| 165 | password); | 166 | password); |
| 166 | } | 167 | } |
| 167 | 168 | ||
| @@ -280,7 +281,7 @@ QPDF::parse(char const* password) | @@ -280,7 +281,7 @@ QPDF::parse(char const* password) | ||
| 280 | // where the regexp matches. | 281 | // where the regexp matches. |
| 281 | char* p = buf; | 282 | char* p = buf; |
| 282 | char const* candidate = ""; | 283 | char const* candidate = ""; |
| 283 | - while ((p = (char*)memchr(p, 's', tbuf_size - (p - buf))) != 0) | 284 | + while ((p = static_cast<char*>(memchr(p, 's', tbuf_size - (p - buf)))) != 0) |
| 284 | { | 285 | { |
| 285 | if (eof_re.match(p)) | 286 | if (eof_re.match(p)) |
| 286 | { | 287 | { |
| @@ -796,7 +797,7 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj) | @@ -796,7 +797,7 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj) | ||
| 796 | for (int k = 0; k < W[j]; ++k) | 797 | for (int k = 0; k < W[j]; ++k) |
| 797 | { | 798 | { |
| 798 | fields[j] <<= 8; | 799 | fields[j] <<= 8; |
| 799 | - fields[j] += (int)(*p++); | 800 | + fields[j] += static_cast<int>(*p++); |
| 800 | } | 801 | } |
| 801 | } | 802 | } |
| 802 | 803 | ||
| @@ -828,7 +829,8 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj) | @@ -828,7 +829,8 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj) | ||
| 828 | // This is needed by checkLinearization() | 829 | // This is needed by checkLinearization() |
| 829 | this->first_xref_item_offset = xref_offset; | 830 | this->first_xref_item_offset = xref_offset; |
| 830 | } | 831 | } |
| 831 | - insertXrefEntry(obj, (int)fields[0], fields[1], (int)fields[2]); | 832 | + insertXrefEntry(obj, static_cast<int>(fields[0]), |
| 833 | + fields[1], static_cast<int>(fields[2])); | ||
| 832 | } | 834 | } |
| 833 | 835 | ||
| 834 | if (! this->trailer.isInitialized()) | 836 | if (! this->trailer.isInitialized()) |
| @@ -1096,8 +1098,7 @@ QPDF::readObject(PointerHolder<InputSource> input, | @@ -1096,8 +1098,7 @@ QPDF::readObject(PointerHolder<InputSource> input, | ||
| 1096 | } | 1098 | } |
| 1097 | 1099 | ||
| 1098 | length = length_obj.getIntValue(); | 1100 | length = length_obj.getIntValue(); |
| 1099 | - input->seek( | ||
| 1100 | - stream_offset + (qpdf_offset_t)length, SEEK_SET); | 1101 | + input->seek(stream_offset + length, SEEK_SET); |
| 1101 | if (! (readToken(input) == | 1102 | if (! (readToken(input) == |
| 1102 | QPDFTokenizer::Token( | 1103 | QPDFTokenizer::Token( |
| 1103 | QPDFTokenizer::tt_word, "endstream"))) | 1104 | QPDFTokenizer::tt_word, "endstream"))) |
| @@ -1395,7 +1396,7 @@ QPDF::readObjectAtOffset(bool try_recovery, | @@ -1395,7 +1396,7 @@ QPDF::readObjectAtOffset(bool try_recovery, | ||
| 1395 | char ch; | 1396 | char ch; |
| 1396 | if (this->file->read(&ch, 1)) | 1397 | if (this->file->read(&ch, 1)) |
| 1397 | { | 1398 | { |
| 1398 | - if (! isspace((unsigned char)ch)) | 1399 | + if (! isspace(static_cast<unsigned char>(ch))) |
| 1399 | { | 1400 | { |
| 1400 | this->file->seek(-1, SEEK_CUR); | 1401 | this->file->seek(-1, SEEK_CUR); |
| 1401 | break; | 1402 | break; |
| @@ -2064,7 +2065,7 @@ QPDF::pipeStreamData(int objid, int generation, | @@ -2064,7 +2065,7 @@ QPDF::pipeStreamData(int objid, int generation, | ||
| 2064 | "unexpected EOF reading stream data"); | 2065 | "unexpected EOF reading stream data"); |
| 2065 | } | 2066 | } |
| 2066 | length -= len; | 2067 | length -= len; |
| 2067 | - pipeline->write((unsigned char*)buf, len); | 2068 | + pipeline->write(QUtil::unsigned_char_pointer(buf), len); |
| 2068 | } | 2069 | } |
| 2069 | } | 2070 | } |
| 2070 | catch (QPDFExc& e) | 2071 | catch (QPDFExc& e) |
libqpdf/QPDFObjectHandle.cc
| @@ -508,7 +508,7 @@ QPDFObjectHandle::replaceStreamData(std::string const& data, | @@ -508,7 +508,7 @@ QPDFObjectHandle::replaceStreamData(std::string const& data, | ||
| 508 | assertStream(); | 508 | assertStream(); |
| 509 | PointerHolder<Buffer> b = new Buffer(data.length()); | 509 | PointerHolder<Buffer> b = new Buffer(data.length()); |
| 510 | unsigned char* bp = b->getBuffer(); | 510 | unsigned char* bp = b->getBuffer(); |
| 511 | - memcpy(bp, (char*)data.c_str(), data.length()); | 511 | + memcpy(bp, data.c_str(), data.length()); |
| 512 | dynamic_cast<QPDF_Stream*>(obj.getPointer())->replaceStreamData( | 512 | dynamic_cast<QPDF_Stream*>(obj.getPointer())->replaceStreamData( |
| 513 | b, filter, decode_parms); | 513 | b, filter, decode_parms); |
| 514 | } | 514 | } |
| @@ -690,7 +690,7 @@ QPDFObjectHandle::parse(std::string const& object_str, | @@ -690,7 +690,7 @@ QPDFObjectHandle::parse(std::string const& object_str, | ||
| 690 | bool empty = false; | 690 | bool empty = false; |
| 691 | QPDFObjectHandle result = | 691 | QPDFObjectHandle result = |
| 692 | parse(input, object_description, tokenizer, empty, 0, 0); | 692 | parse(input, object_description, tokenizer, empty, 0, 0); |
| 693 | - size_t offset = (size_t) input->tell(); | 693 | + size_t offset = input->tell(); |
| 694 | while (offset < object_str.length()) | 694 | while (offset < object_str.length()) |
| 695 | { | 695 | { |
| 696 | if (! isspace(object_str[offset])) | 696 | if (! isspace(object_str[offset])) |
| @@ -748,7 +748,7 @@ QPDFObjectHandle::parseContentStream_internal(QPDFObjectHandle stream, | @@ -748,7 +748,7 @@ QPDFObjectHandle::parseContentStream_internal(QPDFObjectHandle stream, | ||
| 748 | QPDFTokenizer tokenizer; | 748 | QPDFTokenizer tokenizer; |
| 749 | tokenizer.allowEOF(); | 749 | tokenizer.allowEOF(); |
| 750 | bool empty = false; | 750 | bool empty = false; |
| 751 | - while ((size_t) input->tell() < length) | 751 | + while (static_cast<size_t>(input->tell()) < length) |
| 752 | { | 752 | { |
| 753 | QPDFObjectHandle obj = | 753 | QPDFObjectHandle obj = |
| 754 | parseInternal(input, "content", tokenizer, empty, | 754 | parseInternal(input, "content", tokenizer, empty, |
libqpdf/QPDFTokenizer.cc
| @@ -80,7 +80,7 @@ QPDFTokenizer::resolveLiteral() | @@ -80,7 +80,7 @@ QPDFTokenizer::resolveLiteral() | ||
| 80 | num[0] = p[1]; | 80 | num[0] = p[1]; |
| 81 | num[1] = p[2]; | 81 | num[1] = p[2]; |
| 82 | num[2] = '\0'; | 82 | num[2] = '\0'; |
| 83 | - char ch = (char)(strtol(num, 0, 16)); | 83 | + char ch = static_cast<char>(strtol(num, 0, 16)); |
| 84 | if (ch == '\0') | 84 | if (ch == '\0') |
| 85 | { | 85 | { |
| 86 | type = tt_bad; | 86 | type = tt_bad; |
| @@ -273,7 +273,7 @@ QPDFTokenizer::presentCharacter(char ch) | @@ -273,7 +273,7 @@ QPDFTokenizer::presentCharacter(char ch) | ||
| 273 | { | 273 | { |
| 274 | // We've accumulated \ddd. PDF Spec says to ignore | 274 | // We've accumulated \ddd. PDF Spec says to ignore |
| 275 | // high-order overflow. | 275 | // high-order overflow. |
| 276 | - val += (char) strtol(bs_num_register, 0, 8); | 276 | + val += static_cast<char>(strtol(bs_num_register, 0, 8)); |
| 277 | memset(bs_num_register, '\0', sizeof(bs_num_register)); | 277 | memset(bs_num_register, '\0', sizeof(bs_num_register)); |
| 278 | bs_num_count = 0; | 278 | bs_num_count = 0; |
| 279 | } | 279 | } |
| @@ -399,7 +399,7 @@ QPDFTokenizer::presentCharacter(char ch) | @@ -399,7 +399,7 @@ QPDFTokenizer::presentCharacter(char ch) | ||
| 399 | { | 399 | { |
| 400 | num[0] = val[i]; | 400 | num[0] = val[i]; |
| 401 | num[1] = val[i+1]; | 401 | num[1] = val[i+1]; |
| 402 | - char nch = (char)(strtol(num, 0, 16)); | 402 | + char nch = static_cast<char>(strtol(num, 0, 16)); |
| 403 | nval += nch; | 403 | nval += nch; |
| 404 | } | 404 | } |
| 405 | val = nval; | 405 | val = nval; |
| @@ -511,7 +511,7 @@ QPDFTokenizer::readToken(PointerHolder<InputSource> input, | @@ -511,7 +511,7 @@ QPDFTokenizer::readToken(PointerHolder<InputSource> input, | ||
| 511 | } | 511 | } |
| 512 | else | 512 | else |
| 513 | { | 513 | { |
| 514 | - if (is_space((unsigned char)ch) && | 514 | + if (is_space(static_cast<unsigned char>(ch)) && |
| 515 | (input->getLastOffset() == offset)) | 515 | (input->getLastOffset() == offset)) |
| 516 | { | 516 | { |
| 517 | ++offset; | 517 | ++offset; |
libqpdf/QPDFWriter.cc
| @@ -772,7 +772,7 @@ QPDFWriter::writeBinary(unsigned long long val, unsigned int bytes) | @@ -772,7 +772,7 @@ QPDFWriter::writeBinary(unsigned long long val, unsigned int bytes) | ||
| 772 | unsigned char data[sizeof(unsigned long long)]; | 772 | unsigned char data[sizeof(unsigned long long)]; |
| 773 | for (unsigned int i = 0; i < bytes; ++i) | 773 | for (unsigned int i = 0; i < bytes; ++i) |
| 774 | { | 774 | { |
| 775 | - data[bytes - i - 1] = (unsigned char)(val & 0xff); | 775 | + data[bytes - i - 1] = static_cast<unsigned char>(val & 0xff); |
| 776 | val >>= 8; | 776 | val >>= 8; |
| 777 | } | 777 | } |
| 778 | this->pipeline->write(data, bytes); | 778 | this->pipeline->write(data, bytes); |
| @@ -781,7 +781,7 @@ QPDFWriter::writeBinary(unsigned long long val, unsigned int bytes) | @@ -781,7 +781,7 @@ QPDFWriter::writeBinary(unsigned long long val, unsigned int bytes) | ||
| 781 | void | 781 | void |
| 782 | QPDFWriter::writeString(std::string const& str) | 782 | QPDFWriter::writeString(std::string const& str) |
| 783 | { | 783 | { |
| 784 | - this->pipeline->write((unsigned char*)str.c_str(), str.length()); | 784 | + this->pipeline->write(QUtil::unsigned_char_pointer(str), str.length()); |
| 785 | } | 785 | } |
| 786 | 786 | ||
| 787 | void | 787 | void |
| @@ -887,14 +887,14 @@ QPDFWriter::pushEncryptionFilter() | @@ -887,14 +887,14 @@ QPDFWriter::pushEncryptionFilter() | ||
| 887 | { | 887 | { |
| 888 | p = new Pl_AES_PDF( | 888 | p = new Pl_AES_PDF( |
| 889 | "aes stream encryption", this->pipeline, true, | 889 | "aes stream encryption", this->pipeline, true, |
| 890 | - (unsigned char*) this->cur_data_key.c_str(), | ||
| 891 | - (unsigned int)this->cur_data_key.length()); | 890 | + QUtil::unsigned_char_pointer(this->cur_data_key), |
| 891 | + this->cur_data_key.length()); | ||
| 892 | } | 892 | } |
| 893 | else | 893 | else |
| 894 | { | 894 | { |
| 895 | p = new Pl_RC4("rc4 stream encryption", this->pipeline, | 895 | p = new Pl_RC4("rc4 stream encryption", this->pipeline, |
| 896 | - (unsigned char*) this->cur_data_key.c_str(), | ||
| 897 | - (unsigned int)this->cur_data_key.length()); | 896 | + QUtil::unsigned_char_pointer(this->cur_data_key), |
| 897 | + this->cur_data_key.length()); | ||
| 898 | } | 898 | } |
| 899 | pushPipeline(p); | 899 | pushPipeline(p); |
| 900 | } | 900 | } |
| @@ -1087,7 +1087,7 @@ QPDFWriter::writeTrailer(trailer_e which, int size, bool xref_stream, | @@ -1087,7 +1087,7 @@ QPDFWriter::writeTrailer(trailer_e which, int size, bool xref_stream, | ||
| 1087 | writeString(" /Prev "); | 1087 | writeString(" /Prev "); |
| 1088 | qpdf_offset_t pos = this->pipeline->getCount(); | 1088 | qpdf_offset_t pos = this->pipeline->getCount(); |
| 1089 | writeString(QUtil::int_to_string(prev)); | 1089 | writeString(QUtil::int_to_string(prev)); |
| 1090 | - int nspaces = (int)(pos - this->pipeline->getCount() + 21); | 1090 | + int nspaces = pos - this->pipeline->getCount() + 21; |
| 1091 | assert(nspaces >= 0); | 1091 | assert(nspaces >= 0); |
| 1092 | writePad(nspaces); | 1092 | writePad(nspaces); |
| 1093 | } | 1093 | } |
| @@ -1504,14 +1504,15 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level, | @@ -1504,14 +1504,15 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level, | ||
| 1504 | if (this->encrypt_use_aes) | 1504 | if (this->encrypt_use_aes) |
| 1505 | { | 1505 | { |
| 1506 | Pl_Buffer bufpl("encrypted string"); | 1506 | Pl_Buffer bufpl("encrypted string"); |
| 1507 | - Pl_AES_PDF pl("aes encrypt string", &bufpl, true, | ||
| 1508 | - (unsigned char const*)this->cur_data_key.c_str(), | ||
| 1509 | - (unsigned int)this->cur_data_key.length()); | ||
| 1510 | - pl.write((unsigned char*) val.c_str(), val.length()); | 1507 | + Pl_AES_PDF pl( |
| 1508 | + "aes encrypt string", &bufpl, true, | ||
| 1509 | + QUtil::unsigned_char_pointer(this->cur_data_key), | ||
| 1510 | + this->cur_data_key.length()); | ||
| 1511 | + pl.write(QUtil::unsigned_char_pointer(val), val.length()); | ||
| 1511 | pl.finish(); | 1512 | pl.finish(); |
| 1512 | Buffer* buf = bufpl.getBuffer(); | 1513 | Buffer* buf = bufpl.getBuffer(); |
| 1513 | val = QPDF_String( | 1514 | val = QPDF_String( |
| 1514 | - std::string((char*)buf->getBuffer(), | 1515 | + std::string(reinterpret_cast<char*>(buf->getBuffer()), |
| 1515 | buf->getSize())).unparse(true); | 1516 | buf->getSize())).unparse(true); |
| 1516 | delete buf; | 1517 | delete buf; |
| 1517 | } | 1518 | } |
| @@ -1519,9 +1520,9 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level, | @@ -1519,9 +1520,9 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level, | ||
| 1519 | { | 1520 | { |
| 1520 | char* tmp = QUtil::copy_string(val); | 1521 | char* tmp = QUtil::copy_string(val); |
| 1521 | size_t vlen = val.length(); | 1522 | size_t vlen = val.length(); |
| 1522 | - RC4 rc4((unsigned char const*)this->cur_data_key.c_str(), | ||
| 1523 | - (int)this->cur_data_key.length()); | ||
| 1524 | - rc4.process((unsigned char*)tmp, (int)vlen); | 1523 | + RC4 rc4(QUtil::unsigned_char_pointer(this->cur_data_key), |
| 1524 | + this->cur_data_key.length()); | ||
| 1525 | + rc4.process(QUtil::unsigned_char_pointer(tmp), vlen); | ||
| 1525 | val = QPDF_String(std::string(tmp, vlen)).unparse(); | 1526 | val = QPDF_String(std::string(tmp, vlen)).unparse(); |
| 1526 | delete [] tmp; | 1527 | delete [] tmp; |
| 1527 | } | 1528 | } |
| @@ -1788,7 +1789,7 @@ QPDFWriter::generateID() | @@ -1788,7 +1789,7 @@ QPDFWriter::generateID() | ||
| 1788 | 0x23, 0x84, 0x62, 0x64, | 1789 | 0x23, 0x84, 0x62, 0x64, |
| 1789 | 0x33, 0x83, 0x27, 0x95, | 1790 | 0x33, 0x83, 0x27, 0x95, |
| 1790 | 0x00}; | 1791 | 0x00}; |
| 1791 | - result = (char*)tmp; | 1792 | + result = reinterpret_cast<char*>(tmp); |
| 1792 | } | 1793 | } |
| 1793 | else | 1794 | else |
| 1794 | { | 1795 | { |
| @@ -1799,7 +1800,7 @@ QPDFWriter::generateID() | @@ -1799,7 +1800,7 @@ QPDFWriter::generateID() | ||
| 1799 | // the file yet. This scheme should be fine though. | 1800 | // the file yet. This scheme should be fine though. |
| 1800 | 1801 | ||
| 1801 | std::string seed; | 1802 | std::string seed; |
| 1802 | - seed += QUtil::int_to_string((int)QUtil::get_current_time()); | 1803 | + seed += QUtil::int_to_string(QUtil::get_current_time()); |
| 1803 | seed += " QPDF "; | 1804 | seed += " QPDF "; |
| 1804 | seed += this->filename; | 1805 | seed += this->filename; |
| 1805 | seed += " "; | 1806 | seed += " "; |
| @@ -1823,7 +1824,8 @@ QPDFWriter::generateID() | @@ -1823,7 +1824,8 @@ QPDFWriter::generateID() | ||
| 1823 | m.encodeString(seed.c_str()); | 1824 | m.encodeString(seed.c_str()); |
| 1824 | MD5::Digest digest; | 1825 | MD5::Digest digest; |
| 1825 | m.digest(digest); | 1826 | m.digest(digest); |
| 1826 | - result = std::string((char*)digest, sizeof(MD5::Digest)); | 1827 | + result = std::string(reinterpret_cast<char*>(digest), |
| 1828 | + sizeof(MD5::Digest)); | ||
| 1827 | } | 1829 | } |
| 1828 | 1830 | ||
| 1829 | // If /ID already exists, follow the spec: use the original first | 1831 | // If /ID already exists, follow the spec: use the original first |
| @@ -1899,9 +1901,8 @@ QPDFWriter::generateObjectStreams() | @@ -1899,9 +1901,8 @@ QPDFWriter::generateObjectStreams() | ||
| 1899 | // This code doesn't do anything with /Extends. | 1901 | // This code doesn't do anything with /Extends. |
| 1900 | 1902 | ||
| 1901 | std::vector<int> const& eligible = this->pdf.getCompressibleObjects(); | 1903 | std::vector<int> const& eligible = this->pdf.getCompressibleObjects(); |
| 1902 | - unsigned int n_object_streams = | ||
| 1903 | - (unsigned int)((eligible.size() + 99) / 100); | ||
| 1904 | - unsigned int n_per = (unsigned int)(eligible.size() / n_object_streams); | 1904 | + unsigned int n_object_streams = (eligible.size() + 99) / 100; |
| 1905 | + unsigned int n_per = eligible.size() / n_object_streams; | ||
| 1905 | if (n_per * n_object_streams < eligible.size()) | 1906 | if (n_per * n_object_streams < eligible.size()) |
| 1906 | { | 1907 | { |
| 1907 | ++n_per; | 1908 | ++n_per; |
| @@ -2206,7 +2207,8 @@ QPDFWriter::write() | @@ -2206,7 +2207,8 @@ QPDFWriter::write() | ||
| 2206 | this->object_stream_to_objects[stream].insert(obj); | 2207 | this->object_stream_to_objects[stream].insert(obj); |
| 2207 | this->max_ostream_index = | 2208 | this->max_ostream_index = |
| 2208 | std::max(this->max_ostream_index, | 2209 | std::max(this->max_ostream_index, |
| 2209 | - (int)this->object_stream_to_objects[stream].size() - 1); | 2210 | + static_cast<int>( |
| 2211 | + this->object_stream_to_objects[stream].size()) - 1); | ||
| 2210 | } | 2212 | } |
| 2211 | 2213 | ||
| 2212 | if (! this->object_stream_to_objects.empty()) | 2214 | if (! this->object_stream_to_objects.empty()) |
| @@ -2553,8 +2555,7 @@ QPDFWriter::writeLinearized() | @@ -2553,8 +2555,7 @@ QPDFWriter::writeLinearized() | ||
| 2553 | // | 2555 | // |
| 2554 | 2556 | ||
| 2555 | // Second half objects | 2557 | // Second half objects |
| 2556 | - int second_half_uncompressed = | ||
| 2557 | - (int)(part7.size() + part8.size() + part9.size()); | 2558 | + int second_half_uncompressed = part7.size() + part8.size() + part9.size(); |
| 2558 | int second_half_first_obj = 1; | 2559 | int second_half_first_obj = 1; |
| 2559 | int after_second_half = 1 + second_half_uncompressed; | 2560 | int after_second_half = 1 + second_half_uncompressed; |
| 2560 | this->next_objid = after_second_half; | 2561 | this->next_objid = after_second_half; |
| @@ -2661,7 +2662,7 @@ QPDFWriter::writeLinearized() | @@ -2661,7 +2662,7 @@ QPDFWriter::writeLinearized() | ||
| 2661 | { | 2662 | { |
| 2662 | std::vector<QPDFObjectHandle> const& pages = pdf.getAllPages(); | 2663 | std::vector<QPDFObjectHandle> const& pages = pdf.getAllPages(); |
| 2663 | int first_page_object = obj_renumber[pages[0].getObjectID()]; | 2664 | int first_page_object = obj_renumber[pages[0].getObjectID()]; |
| 2664 | - int npages = (int)pages.size(); | 2665 | + int npages = pages.size(); |
| 2665 | 2666 | ||
| 2666 | writeString(" /Linearized 1 /L "); | 2667 | writeString(" /Linearized 1 /L "); |
| 2667 | writeString(QUtil::int_to_string(file_size + hint_length)); | 2668 | writeString(QUtil::int_to_string(file_size + hint_length)); |
| @@ -2821,7 +2822,7 @@ QPDFWriter::writeLinearized() | @@ -2821,7 +2822,7 @@ QPDFWriter::writeLinearized() | ||
| 2821 | // If this assertion fails, maybe we didn't have | 2822 | // If this assertion fails, maybe we didn't have |
| 2822 | // enough padding above. | 2823 | // enough padding above. |
| 2823 | assert(this->pipeline->getCount() == | 2824 | assert(this->pipeline->getCount() == |
| 2824 | - (qpdf_offset_t)(second_xref_end + hint_length)); | 2825 | + second_xref_end + hint_length); |
| 2825 | } | 2826 | } |
| 2826 | } | 2827 | } |
| 2827 | else | 2828 | else |
| @@ -2849,7 +2850,7 @@ QPDFWriter::writeLinearized() | @@ -2849,7 +2850,7 @@ QPDFWriter::writeLinearized() | ||
| 2849 | activatePipelineStack(); | 2850 | activatePipelineStack(); |
| 2850 | writeHintStream(hint_id); | 2851 | writeHintStream(hint_id); |
| 2851 | popPipelineStack(&hint_buffer); | 2852 | popPipelineStack(&hint_buffer); |
| 2852 | - hint_length = (qpdf_offset_t)hint_buffer->getSize(); | 2853 | + hint_length = hint_buffer->getSize(); |
| 2853 | 2854 | ||
| 2854 | // Restore hint offset | 2855 | // Restore hint offset |
| 2855 | this->xref[hint_id] = QPDFXRefEntry(1, hint_offset, 0); | 2856 | this->xref[hint_id] = QPDFXRefEntry(1, hint_offset, 0); |
libqpdf/QPDFXRefEntry.cc
| @@ -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 (int) this->field1; | 49 | + return this->field1; |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | int | 52 | int |
libqpdf/QPDF_Array.cc
| @@ -49,13 +49,13 @@ QPDF_Array::getTypeName() const | @@ -49,13 +49,13 @@ QPDF_Array::getTypeName() const | ||
| 49 | int | 49 | int |
| 50 | QPDF_Array::getNItems() const | 50 | QPDF_Array::getNItems() const |
| 51 | { | 51 | { |
| 52 | - return (int)this->items.size(); | 52 | + return this->items.size(); |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | QPDFObjectHandle | 55 | QPDFObjectHandle |
| 56 | QPDF_Array::getItem(int n) const | 56 | QPDF_Array::getItem(int n) const |
| 57 | { | 57 | { |
| 58 | - if ((n < 0) || (n >= (int)this->items.size())) | 58 | + if ((n < 0) || (n >= static_cast<int>(this->items.size()))) |
| 59 | { | 59 | { |
| 60 | throw std::logic_error( | 60 | throw std::logic_error( |
| 61 | "INTERNAL ERROR: bounds error accessing QPDF_Array element"); | 61 | "INTERNAL ERROR: bounds error accessing QPDF_Array element"); |
| @@ -87,7 +87,7 @@ void | @@ -87,7 +87,7 @@ void | ||
| 87 | QPDF_Array::insertItem(int at, QPDFObjectHandle const& item) | 87 | QPDF_Array::insertItem(int at, QPDFObjectHandle const& item) |
| 88 | { | 88 | { |
| 89 | // As special case, also allow insert beyond the end | 89 | // As special case, also allow insert beyond the end |
| 90 | - if ((at < 0) || (at > (int)this->items.size())) | 90 | + if ((at < 0) || (at > static_cast<int>(this->items.size()))) |
| 91 | { | 91 | { |
| 92 | throw std::logic_error( | 92 | throw std::logic_error( |
| 93 | "INTERNAL ERROR: bounds error accessing QPDF_Array element"); | 93 | "INTERNAL ERROR: bounds error accessing QPDF_Array element"); |
libqpdf/QPDF_Stream.cc
| @@ -519,7 +519,7 @@ QPDF_Stream::replaceFilterData(QPDFObjectHandle const& filter, | @@ -519,7 +519,7 @@ QPDF_Stream::replaceFilterData(QPDFObjectHandle const& filter, | ||
| 519 | else | 519 | else |
| 520 | { | 520 | { |
| 521 | this->stream_dict.replaceKey( | 521 | this->stream_dict.replaceKey( |
| 522 | - "/Length", QPDFObjectHandle::newInteger((int)length)); | 522 | + "/Length", QPDFObjectHandle::newInteger(length)); |
| 523 | } | 523 | } |
| 524 | } | 524 | } |
| 525 | 525 |
libqpdf/QPDF_String.cc
| @@ -140,7 +140,7 @@ QPDF_String::unparse(bool force_binary) | @@ -140,7 +140,7 @@ QPDF_String::unparse(bool force_binary) | ||
| 140 | } | 140 | } |
| 141 | else | 141 | else |
| 142 | { | 142 | { |
| 143 | - sprintf(num, "\\%03o", (unsigned char)ch); | 143 | + sprintf(num, "\\%03o", static_cast<unsigned char>(ch)); |
| 144 | result += num; | 144 | result += num; |
| 145 | } | 145 | } |
| 146 | break; | 146 | break; |
| @@ -181,8 +181,8 @@ QPDF_String::getUTF8Val() const | @@ -181,8 +181,8 @@ QPDF_String::getUTF8Val() const | ||
| 181 | // discarded, and a low codepoint not preceded by a high | 181 | // discarded, and a low codepoint not preceded by a high |
| 182 | // codepoint will just get its low 10 bits output. | 182 | // codepoint will just get its low 10 bits output. |
| 183 | unsigned short bits = | 183 | unsigned short bits = |
| 184 | - (((unsigned char) this->val[i]) << 8) + | ||
| 185 | - ((unsigned char) this->val[i+1]); | 184 | + (static_cast<unsigned char>(this->val[i]) << 8) + |
| 185 | + static_cast<unsigned char>(this->val[i+1]); | ||
| 186 | if ((bits & 0xFC00) == 0xD800) | 186 | if ((bits & 0xFC00) == 0xD800) |
| 187 | { | 187 | { |
| 188 | codepoint = 0x10000 + ((bits & 0x3FF) << 10); | 188 | codepoint = 0x10000 + ((bits & 0x3FF) << 10); |
| @@ -209,7 +209,7 @@ QPDF_String::getUTF8Val() const | @@ -209,7 +209,7 @@ QPDF_String::getUTF8Val() const | ||
| 209 | { | 209 | { |
| 210 | for (unsigned int i = 0; i < len; ++i) | 210 | for (unsigned int i = 0; i < len; ++i) |
| 211 | { | 211 | { |
| 212 | - result += QUtil::toUTF8((unsigned char) this->val[i]); | 212 | + result += QUtil::toUTF8(static_cast<unsigned char>(this->val[i])); |
| 213 | } | 213 | } |
| 214 | } | 214 | } |
| 215 | return result; | 215 | return result; |
libqpdf/QPDF_encryption.cc
| @@ -129,7 +129,8 @@ QPDF::EncryptionData::setV5EncryptionParameters( | @@ -129,7 +129,8 @@ QPDF::EncryptionData::setV5EncryptionParameters( | ||
| 129 | static void | 129 | static void |
| 130 | pad_or_truncate_password_V4(std::string const& password, char k1[key_bytes]) | 130 | pad_or_truncate_password_V4(std::string const& password, char k1[key_bytes]) |
| 131 | { | 131 | { |
| 132 | - int password_bytes = std::min(key_bytes, (unsigned int)password.length()); | 132 | + int password_bytes = std::min(static_cast<size_t>(key_bytes), |
| 133 | + password.length()); | ||
| 133 | int pad_bytes = key_bytes - password_bytes; | 134 | int pad_bytes = key_bytes - password_bytes; |
| 134 | memcpy(k1, password.c_str(), password_bytes); | 135 | memcpy(k1, password.c_str(), password_bytes); |
| 135 | memcpy(k1 + password_bytes, padding_string, pad_bytes); | 136 | memcpy(k1 + password_bytes, padding_string, pad_bytes); |
| @@ -176,7 +177,8 @@ pad_or_truncate_password_V4(std::string const& password) | @@ -176,7 +177,8 @@ pad_or_truncate_password_V4(std::string const& password) | ||
| 176 | static std::string | 177 | static std::string |
| 177 | truncate_password_V5(std::string const& password) | 178 | truncate_password_V5(std::string const& password) |
| 178 | { | 179 | { |
| 179 | - return password.substr(0, std::min((size_t)127, password.length())); | 180 | + return password.substr( |
| 181 | + 0, std::min(static_cast<size_t>(127), password.length())); | ||
| 180 | } | 182 | } |
| 181 | 183 | ||
| 182 | static void | 184 | static void |
| @@ -187,7 +189,8 @@ iterate_md5_digest(MD5& md5, MD5::Digest& digest, int iterations) | @@ -187,7 +189,8 @@ iterate_md5_digest(MD5& md5, MD5::Digest& digest, int iterations) | ||
| 187 | for (int i = 0; i < iterations; ++i) | 189 | for (int i = 0; i < iterations; ++i) |
| 188 | { | 190 | { |
| 189 | MD5 m; | 191 | MD5 m; |
| 190 | - m.encodeDataIncrementally((char*)digest, sizeof(digest)); | 192 | + m.encodeDataIncrementally(reinterpret_cast<char*>(digest), |
| 193 | + sizeof(digest)); | ||
| 191 | m.digest(digest); | 194 | m.digest(digest); |
| 192 | } | 195 | } |
| 193 | } | 196 | } |
| @@ -223,8 +226,8 @@ process_with_aes(std::string const& key, | @@ -223,8 +226,8 @@ process_with_aes(std::string const& key, | ||
| 223 | { | 226 | { |
| 224 | Pl_Buffer buffer("buffer"); | 227 | Pl_Buffer buffer("buffer"); |
| 225 | Pl_AES_PDF aes("aes", &buffer, encrypt, | 228 | Pl_AES_PDF aes("aes", &buffer, encrypt, |
| 226 | - (unsigned char const*)key.c_str(), | ||
| 227 | - (unsigned int)key.length()); | 229 | + QUtil::unsigned_char_pointer(key), |
| 230 | + key.length()); | ||
| 228 | if (iv) | 231 | if (iv) |
| 229 | { | 232 | { |
| 230 | aes.setIV(iv, iv_length); | 233 | aes.setIV(iv, iv_length); |
| @@ -236,7 +239,7 @@ process_with_aes(std::string const& key, | @@ -236,7 +239,7 @@ process_with_aes(std::string const& key, | ||
| 236 | aes.disablePadding(); | 239 | aes.disablePadding(); |
| 237 | for (unsigned int i = 0; i < repetitions; ++i) | 240 | for (unsigned int i = 0; i < repetitions; ++i) |
| 238 | { | 241 | { |
| 239 | - aes.write((unsigned char*)data.c_str(), data.length()); | 242 | + aes.write(QUtil::unsigned_char_pointer(data), data.length()); |
| 240 | } | 243 | } |
| 241 | aes.finish(); | 244 | aes.finish(); |
| 242 | PointerHolder<Buffer> bufp = buffer.getBuffer(); | 245 | PointerHolder<Buffer> bufp = buffer.getBuffer(); |
| @@ -248,7 +251,7 @@ process_with_aes(std::string const& key, | @@ -248,7 +251,7 @@ process_with_aes(std::string const& key, | ||
| 248 | { | 251 | { |
| 249 | outlength = std::min(outlength, bufp->getSize()); | 252 | outlength = std::min(outlength, bufp->getSize()); |
| 250 | } | 253 | } |
| 251 | - return std::string((char const*)bufp->getBuffer(), outlength); | 254 | + return std::string(reinterpret_cast<char*>(bufp->getBuffer()), outlength); |
| 252 | } | 255 | } |
| 253 | 256 | ||
| 254 | static std::string | 257 | static std::string |
| @@ -258,9 +261,9 @@ hash_V5(std::string const& password, | @@ -258,9 +261,9 @@ hash_V5(std::string const& password, | ||
| 258 | QPDF::EncryptionData const& data) | 261 | QPDF::EncryptionData const& data) |
| 259 | { | 262 | { |
| 260 | Pl_SHA2 hash(256); | 263 | Pl_SHA2 hash(256); |
| 261 | - hash.write((unsigned char*)password.c_str(), password.length()); | ||
| 262 | - hash.write((unsigned char*)salt.c_str(), salt.length()); | ||
| 263 | - hash.write((unsigned char*)udata.c_str(), udata.length()); | 264 | + hash.write(QUtil::unsigned_char_pointer(password), password.length()); |
| 265 | + hash.write(QUtil::unsigned_char_pointer(salt), salt.length()); | ||
| 266 | + hash.write(QUtil::unsigned_char_pointer(udata), udata.length()); | ||
| 264 | hash.finish(); | 267 | hash.finish(); |
| 265 | std::string K = hash.getRawDigest(); | 268 | std::string K = hash.getRawDigest(); |
| 266 | 269 | ||
| @@ -299,7 +302,7 @@ hash_V5(std::string const& password, | @@ -299,7 +302,7 @@ hash_V5(std::string const& password, | ||
| 299 | assert(K.length() >= 32); | 302 | assert(K.length() >= 32); |
| 300 | std::string E = process_with_aes( | 303 | std::string E = process_with_aes( |
| 301 | K.substr(0, 16), true, K1, 0, 64, | 304 | K.substr(0, 16), true, K1, 0, 64, |
| 302 | - (unsigned char*)K.substr(16, 16).c_str(), 16); | 305 | + QUtil::unsigned_char_pointer(K.substr(16, 16)), 16); |
| 303 | 306 | ||
| 304 | // E_mod_3 is supposed to be mod 3 of the first 16 bytes | 307 | // E_mod_3 is supposed to be mod 3 of the first 16 bytes |
| 305 | // of E taken as as a (128-bit) big-endian number. Since | 308 | // of E taken as as a (128-bit) big-endian number. Since |
| @@ -309,22 +312,22 @@ hash_V5(std::string const& password, | @@ -309,22 +312,22 @@ hash_V5(std::string const& password, | ||
| 309 | int E_mod_3 = 0; | 312 | int E_mod_3 = 0; |
| 310 | for (unsigned int i = 0; i < 16; ++i) | 313 | for (unsigned int i = 0; i < 16; ++i) |
| 311 | { | 314 | { |
| 312 | - E_mod_3 += (unsigned char)E[i]; | 315 | + E_mod_3 += static_cast<unsigned char>(E[i]); |
| 313 | } | 316 | } |
| 314 | E_mod_3 %= 3; | 317 | E_mod_3 %= 3; |
| 315 | int next_hash = ((E_mod_3 == 0) ? 256 : | 318 | int next_hash = ((E_mod_3 == 0) ? 256 : |
| 316 | (E_mod_3 == 1) ? 384 : | 319 | (E_mod_3 == 1) ? 384 : |
| 317 | 512); | 320 | 512); |
| 318 | Pl_SHA2 hash(next_hash); | 321 | Pl_SHA2 hash(next_hash); |
| 319 | - hash.write((unsigned char*)E.c_str(), E.length()); | 322 | + hash.write(QUtil::unsigned_char_pointer(E), E.length()); |
| 320 | hash.finish(); | 323 | hash.finish(); |
| 321 | K = hash.getRawDigest(); | 324 | K = hash.getRawDigest(); |
| 322 | 325 | ||
| 323 | if (round_number >= 64) | 326 | if (round_number >= 64) |
| 324 | { | 327 | { |
| 325 | - unsigned int ch = (unsigned int)((unsigned char) *(E.rbegin())); | 328 | + unsigned int ch = static_cast<unsigned char>(*(E.rbegin())); |
| 326 | 329 | ||
| 327 | - if (ch <= (unsigned int)(round_number - 32)) | 330 | + if (ch <= static_cast<unsigned int>(round_number - 32)) |
| 328 | { | 331 | { |
| 329 | done = true; | 332 | done = true; |
| 330 | } | 333 | } |
| @@ -353,22 +356,22 @@ QPDF::compute_data_key(std::string const& encryption_key, | @@ -353,22 +356,22 @@ QPDF::compute_data_key(std::string const& encryption_key, | ||
| 353 | } | 356 | } |
| 354 | 357 | ||
| 355 | // Append low three bytes of object ID and low two bytes of generation | 358 | // Append low three bytes of object ID and low two bytes of generation |
| 356 | - result += (char) (objid & 0xff); | ||
| 357 | - result += (char) ((objid >> 8) & 0xff); | ||
| 358 | - result += (char) ((objid >> 16) & 0xff); | ||
| 359 | - result += (char) (generation & 0xff); | ||
| 360 | - result += (char) ((generation >> 8) & 0xff); | 359 | + result += static_cast<char>(objid & 0xff); |
| 360 | + result += static_cast<char>((objid >> 8) & 0xff); | ||
| 361 | + result += static_cast<char>((objid >> 16) & 0xff); | ||
| 362 | + result += static_cast<char>(generation & 0xff); | ||
| 363 | + result += static_cast<char>((generation >> 8) & 0xff); | ||
| 361 | if (use_aes) | 364 | if (use_aes) |
| 362 | { | 365 | { |
| 363 | result += "sAlT"; | 366 | result += "sAlT"; |
| 364 | } | 367 | } |
| 365 | 368 | ||
| 366 | MD5 md5; | 369 | MD5 md5; |
| 367 | - md5.encodeDataIncrementally(result.c_str(), (int)result.length()); | 370 | + md5.encodeDataIncrementally(result.c_str(), result.length()); |
| 368 | MD5::Digest digest; | 371 | MD5::Digest digest; |
| 369 | md5.digest(digest); | 372 | md5.digest(digest); |
| 370 | - return std::string((char*) digest, | ||
| 371 | - std::min(result.length(), (size_t) 16)); | 373 | + return std::string(reinterpret_cast<char*>(digest), |
| 374 | + std::min(result.length(), static_cast<size_t>(16))); | ||
| 372 | } | 375 | } |
| 373 | 376 | ||
| 374 | std::string | 377 | std::string |
| @@ -409,13 +412,13 @@ QPDF::compute_encryption_key_from_password( | @@ -409,13 +412,13 @@ QPDF::compute_encryption_key_from_password( | ||
| 409 | md5.encodeDataIncrementally(data.getO().c_str(), key_bytes); | 412 | md5.encodeDataIncrementally(data.getO().c_str(), key_bytes); |
| 410 | char pbytes[4]; | 413 | char pbytes[4]; |
| 411 | int P = data.getP(); | 414 | int P = data.getP(); |
| 412 | - pbytes[0] = (char) (P & 0xff); | ||
| 413 | - pbytes[1] = (char) ((P >> 8) & 0xff); | ||
| 414 | - pbytes[2] = (char) ((P >> 16) & 0xff); | ||
| 415 | - pbytes[3] = (char) ((P >> 24) & 0xff); | 415 | + pbytes[0] = static_cast<char>(P & 0xff); |
| 416 | + pbytes[1] = static_cast<char>((P >> 8) & 0xff); | ||
| 417 | + pbytes[2] = static_cast<char>((P >> 16) & 0xff); | ||
| 418 | + pbytes[3] = static_cast<char>((P >> 24) & 0xff); | ||
| 416 | md5.encodeDataIncrementally(pbytes, 4); | 419 | md5.encodeDataIncrementally(pbytes, 4); |
| 417 | md5.encodeDataIncrementally(data.getId1().c_str(), | 420 | md5.encodeDataIncrementally(data.getId1().c_str(), |
| 418 | - (int)data.getId1().length()); | 421 | + data.getId1().length()); |
| 419 | if ((data.getR() >= 4) && (! data.getEncryptMetadata())) | 422 | if ((data.getR() >= 4) && (! data.getEncryptMetadata())) |
| 420 | { | 423 | { |
| 421 | char bytes[4]; | 424 | char bytes[4]; |
| @@ -424,7 +427,7 @@ QPDF::compute_encryption_key_from_password( | @@ -424,7 +427,7 @@ QPDF::compute_encryption_key_from_password( | ||
| 424 | } | 427 | } |
| 425 | MD5::Digest digest; | 428 | MD5::Digest digest; |
| 426 | iterate_md5_digest(md5, digest, ((data.getR() >= 3) ? 50 : 0)); | 429 | iterate_md5_digest(md5, digest, ((data.getR() >= 3) ? 50 : 0)); |
| 427 | - return std::string((char*)digest, data.getLengthBytes()); | 430 | + return std::string(reinterpret_cast<char*>(digest), data.getLengthBytes()); |
| 428 | } | 431 | } |
| 429 | 432 | ||
| 430 | static void | 433 | static void |
| @@ -463,7 +466,7 @@ compute_O_value(std::string const& user_password, | @@ -463,7 +466,7 @@ compute_O_value(std::string const& user_password, | ||
| 463 | 466 | ||
| 464 | char upass[key_bytes]; | 467 | char upass[key_bytes]; |
| 465 | pad_or_truncate_password_V4(user_password, upass); | 468 | pad_or_truncate_password_V4(user_password, upass); |
| 466 | - iterate_rc4((unsigned char*) upass, key_bytes, | 469 | + iterate_rc4(QUtil::unsigned_char_pointer(upass), key_bytes, |
| 467 | O_key, data.getLengthBytes(), | 470 | O_key, data.getLengthBytes(), |
| 468 | (data.getR() >= 3) ? 20 : 1, false); | 471 | (data.getR() >= 3) ? 20 : 1, false); |
| 469 | return std::string(upass, key_bytes); | 472 | return std::string(upass, key_bytes); |
| @@ -479,8 +482,9 @@ compute_U_value_R2(std::string const& user_password, | @@ -479,8 +482,9 @@ compute_U_value_R2(std::string const& user_password, | ||
| 479 | std::string k1 = QPDF::compute_encryption_key(user_password, data); | 482 | std::string k1 = QPDF::compute_encryption_key(user_password, data); |
| 480 | char udata[key_bytes]; | 483 | char udata[key_bytes]; |
| 481 | pad_or_truncate_password_V4("", udata); | 484 | pad_or_truncate_password_V4("", udata); |
| 482 | - iterate_rc4((unsigned char*) udata, key_bytes, | ||
| 483 | - (unsigned char*)k1.c_str(), data.getLengthBytes(), 1, false); | 485 | + iterate_rc4(QUtil::unsigned_char_pointer(udata), key_bytes, |
| 486 | + QUtil::unsigned_char_pointer(k1), | ||
| 487 | + data.getLengthBytes(), 1, false); | ||
| 484 | return std::string(udata, key_bytes); | 488 | return std::string(udata, key_bytes); |
| 485 | } | 489 | } |
| 486 | 490 | ||
| @@ -496,18 +500,19 @@ compute_U_value_R3(std::string const& user_password, | @@ -496,18 +500,19 @@ compute_U_value_R3(std::string const& user_password, | ||
| 496 | md5.encodeDataIncrementally( | 500 | md5.encodeDataIncrementally( |
| 497 | pad_or_truncate_password_V4("").c_str(), key_bytes); | 501 | pad_or_truncate_password_V4("").c_str(), key_bytes); |
| 498 | md5.encodeDataIncrementally(data.getId1().c_str(), | 502 | md5.encodeDataIncrementally(data.getId1().c_str(), |
| 499 | - (int)data.getId1().length()); | 503 | + data.getId1().length()); |
| 500 | MD5::Digest digest; | 504 | MD5::Digest digest; |
| 501 | md5.digest(digest); | 505 | md5.digest(digest); |
| 502 | iterate_rc4(digest, sizeof(MD5::Digest), | 506 | iterate_rc4(digest, sizeof(MD5::Digest), |
| 503 | - (unsigned char*) k1.c_str(), data.getLengthBytes(), 20, false); | 507 | + QUtil::unsigned_char_pointer(k1), |
| 508 | + data.getLengthBytes(), 20, false); | ||
| 504 | char result[key_bytes]; | 509 | char result[key_bytes]; |
| 505 | memcpy(result, digest, sizeof(MD5::Digest)); | 510 | memcpy(result, digest, sizeof(MD5::Digest)); |
| 506 | // pad with arbitrary data -- make it consistent for the sake of | 511 | // pad with arbitrary data -- make it consistent for the sake of |
| 507 | // testing | 512 | // testing |
| 508 | for (unsigned int i = sizeof(MD5::Digest); i < key_bytes; ++i) | 513 | for (unsigned int i = sizeof(MD5::Digest); i < key_bytes; ++i) |
| 509 | { | 514 | { |
| 510 | - result[i] = (char)((i * i) % 0xff); | 515 | + result[i] = static_cast<char>((i * i) % 0xff); |
| 511 | } | 516 | } |
| 512 | return std::string(result, key_bytes); | 517 | return std::string(result, key_bytes); |
| 513 | } | 518 | } |
| @@ -572,11 +577,11 @@ check_owner_password_V4(std::string& user_password, | @@ -572,11 +577,11 @@ check_owner_password_V4(std::string& user_password, | ||
| 572 | unsigned char key[OU_key_bytes_V4]; | 577 | unsigned char key[OU_key_bytes_V4]; |
| 573 | compute_O_rc4_key(user_password, owner_password, data, key); | 578 | compute_O_rc4_key(user_password, owner_password, data, key); |
| 574 | unsigned char O_data[key_bytes]; | 579 | unsigned char O_data[key_bytes]; |
| 575 | - memcpy(O_data, (unsigned char*) data.getO().c_str(), key_bytes); | 580 | + memcpy(O_data, QUtil::unsigned_char_pointer(data.getO()), key_bytes); |
| 576 | iterate_rc4(O_data, key_bytes, key, data.getLengthBytes(), | 581 | iterate_rc4(O_data, key_bytes, key, data.getLengthBytes(), |
| 577 | (data.getR() >= 3) ? 20 : 1, true); | 582 | (data.getR() >= 3) ? 20 : 1, true); |
| 578 | std::string new_user_password = | 583 | std::string new_user_password = |
| 579 | - std::string((char*)O_data, key_bytes); | 584 | + std::string(reinterpret_cast<char*>(O_data), key_bytes); |
| 580 | bool result = false; | 585 | bool result = false; |
| 581 | if (check_user_password(new_user_password, data)) | 586 | if (check_user_password(new_user_password, data)) |
| 582 | { | 587 | { |
| @@ -632,7 +637,8 @@ compute_U_UE_value_V5(std::string const& user_password, | @@ -632,7 +637,8 @@ compute_U_UE_value_V5(std::string const& user_password, | ||
| 632 | { | 637 | { |
| 633 | // Algorithm 3.8 from the PDF 1.7 extension level 3 | 638 | // Algorithm 3.8 from the PDF 1.7 extension level 3 |
| 634 | char k[16]; | 639 | char k[16]; |
| 635 | - QUtil::initializeWithRandomBytes((unsigned char*) k, sizeof(k)); | 640 | + QUtil::initializeWithRandomBytes( |
| 641 | + QUtil::unsigned_char_pointer(k), sizeof(k)); | ||
| 636 | std::string validation_salt(k, 8); | 642 | std::string validation_salt(k, 8); |
| 637 | std::string key_salt(k + 8, 8); | 643 | std::string key_salt(k + 8, 8); |
| 638 | U = hash_V5(user_password, validation_salt, "", data) + | 644 | U = hash_V5(user_password, validation_salt, "", data) + |
| @@ -650,7 +656,8 @@ compute_O_OE_value_V5(std::string const& owner_password, | @@ -650,7 +656,8 @@ compute_O_OE_value_V5(std::string const& owner_password, | ||
| 650 | { | 656 | { |
| 651 | // Algorithm 3.9 from the PDF 1.7 extension level 3 | 657 | // Algorithm 3.9 from the PDF 1.7 extension level 3 |
| 652 | char k[16]; | 658 | char k[16]; |
| 653 | - QUtil::initializeWithRandomBytes((unsigned char*) k, sizeof(k)); | 659 | + QUtil::initializeWithRandomBytes( |
| 660 | + QUtil::unsigned_char_pointer(k), sizeof(k)); | ||
| 654 | std::string validation_salt(k, 8); | 661 | std::string validation_salt(k, 8); |
| 655 | std::string key_salt(k + 8, 8); | 662 | std::string key_salt(k + 8, 8); |
| 656 | O = hash_V5(owner_password, validation_salt, U, data) + | 663 | O = hash_V5(owner_password, validation_salt, U, data) + |
| @@ -668,7 +675,7 @@ compute_Perms_value_V5_clear(std::string const& encryption_key, | @@ -668,7 +675,7 @@ compute_Perms_value_V5_clear(std::string const& encryption_key, | ||
| 668 | unsigned long long extended_perms = 0xffffffff00000000LL | data.getP(); | 675 | unsigned long long extended_perms = 0xffffffff00000000LL | data.getP(); |
| 669 | for (int i = 0; i < 8; ++i) | 676 | for (int i = 0; i < 8; ++i) |
| 670 | { | 677 | { |
| 671 | - k[i] = (unsigned char) (extended_perms & 0xff); | 678 | + k[i] = static_cast<unsigned char>(extended_perms & 0xff); |
| 672 | extended_perms >>= 8; | 679 | extended_perms >>= 8; |
| 673 | } | 680 | } |
| 674 | k[8] = data.getEncryptMetadata() ? 'T' : 'F'; | 681 | k[8] = data.getEncryptMetadata() ? 'T' : 'F'; |
| @@ -685,8 +692,9 @@ compute_Perms_value_V5(std::string const& encryption_key, | @@ -685,8 +692,9 @@ compute_Perms_value_V5(std::string const& encryption_key, | ||
| 685 | // Algorithm 3.10 from the PDF 1.7 extension level 3 | 692 | // Algorithm 3.10 from the PDF 1.7 extension level 3 |
| 686 | unsigned char k[16]; | 693 | unsigned char k[16]; |
| 687 | compute_Perms_value_V5_clear(encryption_key, data, k); | 694 | compute_Perms_value_V5_clear(encryption_key, data, k); |
| 688 | - return process_with_aes(encryption_key, true, | ||
| 689 | - std::string((char const*) k, sizeof(k))); | 695 | + return process_with_aes( |
| 696 | + encryption_key, true, | ||
| 697 | + std::string(reinterpret_cast<char*>(k), sizeof(k))); | ||
| 690 | } | 698 | } |
| 691 | 699 | ||
| 692 | std::string | 700 | std::string |
| @@ -834,7 +842,7 @@ QPDF::initializeEncryption() | @@ -834,7 +842,7 @@ QPDF::initializeEncryption() | ||
| 834 | int R = encryption_dict.getKey("/R").getIntValue(); | 842 | int R = encryption_dict.getKey("/R").getIntValue(); |
| 835 | std::string O = encryption_dict.getKey("/O").getStringValue(); | 843 | std::string O = encryption_dict.getKey("/O").getStringValue(); |
| 836 | std::string U = encryption_dict.getKey("/U").getStringValue(); | 844 | std::string U = encryption_dict.getKey("/U").getStringValue(); |
| 837 | - unsigned int P = (unsigned int) encryption_dict.getKey("/P").getIntValue(); | 845 | + unsigned int P = encryption_dict.getKey("/P").getIntValue(); |
| 838 | 846 | ||
| 839 | // If supporting new encryption R/V values, remember to update | 847 | // If supporting new encryption R/V values, remember to update |
| 840 | // error message inside this if statement. | 848 | // error message inside this if statement. |
| @@ -1084,22 +1092,23 @@ QPDF::decryptString(std::string& str, int objid, int generation) | @@ -1084,22 +1092,23 @@ QPDF::decryptString(std::string& str, int objid, int generation) | ||
| 1084 | QTC::TC("qpdf", "QPDF_encryption aes decode string"); | 1092 | QTC::TC("qpdf", "QPDF_encryption aes decode string"); |
| 1085 | Pl_Buffer bufpl("decrypted string"); | 1093 | Pl_Buffer bufpl("decrypted string"); |
| 1086 | Pl_AES_PDF pl("aes decrypt string", &bufpl, false, | 1094 | Pl_AES_PDF pl("aes decrypt string", &bufpl, false, |
| 1087 | - (unsigned char const*)key.c_str(), | ||
| 1088 | - (unsigned int)key.length()); | ||
| 1089 | - pl.write((unsigned char*)str.c_str(), str.length()); | 1095 | + QUtil::unsigned_char_pointer(key), |
| 1096 | + key.length()); | ||
| 1097 | + pl.write(QUtil::unsigned_char_pointer(str), str.length()); | ||
| 1090 | pl.finish(); | 1098 | pl.finish(); |
| 1091 | PointerHolder<Buffer> buf = bufpl.getBuffer(); | 1099 | PointerHolder<Buffer> buf = bufpl.getBuffer(); |
| 1092 | - str = std::string((char*)buf->getBuffer(), buf->getSize()); | 1100 | + str = std::string(reinterpret_cast<char*>(buf->getBuffer()), |
| 1101 | + buf->getSize()); | ||
| 1093 | } | 1102 | } |
| 1094 | else | 1103 | else |
| 1095 | { | 1104 | { |
| 1096 | QTC::TC("qpdf", "QPDF_encryption rc4 decode string"); | 1105 | QTC::TC("qpdf", "QPDF_encryption rc4 decode string"); |
| 1097 | - unsigned int vlen = (int)str.length(); | 1106 | + unsigned int vlen = str.length(); |
| 1098 | // Using PointerHolder guarantees that tmp will | 1107 | // Using PointerHolder guarantees that tmp will |
| 1099 | // be freed even if rc4.process throws an exception. | 1108 | // be freed even if rc4.process throws an exception. |
| 1100 | PointerHolder<char> tmp(true, QUtil::copy_string(str)); | 1109 | PointerHolder<char> tmp(true, QUtil::copy_string(str)); |
| 1101 | - RC4 rc4((unsigned char const*)key.c_str(), (int)key.length()); | ||
| 1102 | - rc4.process((unsigned char*)tmp.getPointer(), vlen); | 1110 | + RC4 rc4(QUtil::unsigned_char_pointer(key), key.length()); |
| 1111 | + rc4.process(QUtil::unsigned_char_pointer(tmp.getPointer()), vlen); | ||
| 1103 | str = std::string(tmp.getPointer(), vlen); | 1112 | str = std::string(tmp.getPointer(), vlen); |
| 1104 | } | 1113 | } |
| 1105 | } | 1114 | } |
| @@ -1240,15 +1249,15 @@ QPDF::decryptStream(Pipeline*& pipeline, int objid, int generation, | @@ -1240,15 +1249,15 @@ QPDF::decryptStream(Pipeline*& pipeline, int objid, int generation, | ||
| 1240 | { | 1249 | { |
| 1241 | QTC::TC("qpdf", "QPDF_encryption aes decode stream"); | 1250 | QTC::TC("qpdf", "QPDF_encryption aes decode stream"); |
| 1242 | pipeline = new Pl_AES_PDF("AES stream decryption", pipeline, | 1251 | pipeline = new Pl_AES_PDF("AES stream decryption", pipeline, |
| 1243 | - false, (unsigned char*) key.c_str(), | ||
| 1244 | - (unsigned int) key.length()); | 1252 | + false, QUtil::unsigned_char_pointer(key), |
| 1253 | + key.length()); | ||
| 1245 | } | 1254 | } |
| 1246 | else | 1255 | else |
| 1247 | { | 1256 | { |
| 1248 | QTC::TC("qpdf", "QPDF_encryption rc4 decode stream"); | 1257 | QTC::TC("qpdf", "QPDF_encryption rc4 decode stream"); |
| 1249 | pipeline = new Pl_RC4("RC4 stream decryption", pipeline, | 1258 | pipeline = new Pl_RC4("RC4 stream decryption", pipeline, |
| 1250 | - (unsigned char*) key.c_str(), | ||
| 1251 | - (unsigned int) key.length()); | 1259 | + QUtil::unsigned_char_pointer(key), |
| 1260 | + key.length()); | ||
| 1252 | } | 1261 | } |
| 1253 | heap.push_back(pipeline); | 1262 | heap.push_back(pipeline); |
| 1254 | } | 1263 | } |
| @@ -1285,7 +1294,7 @@ QPDF::compute_encryption_parameters_V5( | @@ -1285,7 +1294,7 @@ QPDF::compute_encryption_parameters_V5( | ||
| 1285 | id1, encrypt_metadata); | 1294 | id1, encrypt_metadata); |
| 1286 | unsigned char k[key_bytes]; | 1295 | unsigned char k[key_bytes]; |
| 1287 | QUtil::initializeWithRandomBytes(k, key_bytes); | 1296 | QUtil::initializeWithRandomBytes(k, key_bytes); |
| 1288 | - encryption_key = std::string((char const*)k, key_bytes); | 1297 | + encryption_key = std::string(reinterpret_cast<char*>(k), key_bytes); |
| 1289 | compute_U_UE_value_V5(user_password, encryption_key, data, U, UE); | 1298 | compute_U_UE_value_V5(user_password, encryption_key, data, U, UE); |
| 1290 | compute_O_OE_value_V5(owner_password, encryption_key, data, U, O, OE); | 1299 | compute_O_OE_value_V5(owner_password, encryption_key, data, U, O, OE); |
| 1291 | Perms = compute_Perms_value_V5(encryption_key, data); | 1300 | Perms = compute_Perms_value_V5(encryption_key, data); |
libqpdf/QPDF_linearization.cc
| @@ -109,7 +109,7 @@ QPDF::isLinearized() | @@ -109,7 +109,7 @@ QPDF::isLinearized() | ||
| 109 | } | 109 | } |
| 110 | else | 110 | else |
| 111 | { | 111 | { |
| 112 | - p = (char*)memchr(p, '\0', tbuf_size - (p - buf)); | 112 | + p = reinterpret_cast<char*>(memchr(p, '\0', tbuf_size - (p - buf))); |
| 113 | assert(p != 0); | 113 | assert(p != 0); |
| 114 | while ((p - buf < tbuf_size) && (*p == 0)) | 114 | while ((p - buf < tbuf_size) && (*p == 0)) |
| 115 | { | 115 | { |
| @@ -136,7 +136,8 @@ QPDF::isLinearized() | @@ -136,7 +136,8 @@ QPDF::isLinearized() | ||
| 136 | } | 136 | } |
| 137 | 137 | ||
| 138 | QPDFObjectHandle linkey = candidate.getKey("/Linearized"); | 138 | QPDFObjectHandle linkey = candidate.getKey("/Linearized"); |
| 139 | - if (! (linkey.isNumber() && ((int)floor(linkey.getNumericValue()) == 1))) | 139 | + if (! (linkey.isNumber() && |
| 140 | + (static_cast<int>(floor(linkey.getNumericValue())) == 1))) | ||
| 140 | { | 141 | { |
| 141 | return false; | 142 | return false; |
| 142 | } | 143 | } |
| @@ -289,7 +290,7 @@ QPDF::readLinearizationData() | @@ -289,7 +290,7 @@ QPDF::readLinearizationData() | ||
| 289 | PointerHolder<Buffer> hbp = pb.getBuffer(); | 290 | PointerHolder<Buffer> hbp = pb.getBuffer(); |
| 290 | Buffer* hb = hbp.getPointer(); | 291 | Buffer* hb = hbp.getPointer(); |
| 291 | unsigned char const* h_buf = hb->getBuffer(); | 292 | unsigned char const* h_buf = hb->getBuffer(); |
| 292 | - int h_size = (int)hb->getSize(); | 293 | + int h_size = hb->getSize(); |
| 293 | 294 | ||
| 294 | readHPageOffset(BitStream(h_buf, h_size)); | 295 | readHPageOffset(BitStream(h_buf, h_size)); |
| 295 | 296 | ||
| @@ -345,7 +346,7 @@ QPDF::readHintStream(Pipeline& pl, qpdf_offset_t offset, size_t length) | @@ -345,7 +346,7 @@ QPDF::readHintStream(Pipeline& pl, qpdf_offset_t offset, size_t length) | ||
| 345 | { | 346 | { |
| 346 | QTC::TC("qpdf", "QPDF hint table length direct"); | 347 | QTC::TC("qpdf", "QPDF hint table length direct"); |
| 347 | } | 348 | } |
| 348 | - qpdf_offset_t computed_end = offset + (qpdf_offset_t)length; | 349 | + qpdf_offset_t computed_end = offset + length; |
| 349 | if ((computed_end < min_end_offset) || | 350 | if ((computed_end < min_end_offset) || |
| 350 | (computed_end > max_end_offset)) | 351 | (computed_end > max_end_offset)) |
| 351 | { | 352 | { |
| @@ -488,7 +489,7 @@ QPDF::checkLinearizationInternal() | @@ -488,7 +489,7 @@ QPDF::checkLinearizationInternal() | ||
| 488 | } | 489 | } |
| 489 | 490 | ||
| 490 | // N: number of pages | 491 | // N: number of pages |
| 491 | - int npages = (int)pages.size(); | 492 | + int npages = pages.size(); |
| 492 | if (p.npages != npages) | 493 | if (p.npages != npages) |
| 493 | { | 494 | { |
| 494 | // Not tested in the test suite | 495 | // Not tested in the test suite |
| @@ -576,8 +577,8 @@ QPDF::checkLinearizationInternal() | @@ -576,8 +577,8 @@ QPDF::checkLinearizationInternal() | ||
| 576 | // contain any files with threads. | 577 | // contain any files with threads. |
| 577 | 578 | ||
| 578 | assert(! this->part6.empty()); | 579 | assert(! this->part6.empty()); |
| 579 | - int min_E = -1; | ||
| 580 | - int max_E = -1; | 580 | + qpdf_offset_t min_E = -1; |
| 581 | + qpdf_offset_t max_E = -1; | ||
| 581 | for (std::vector<QPDFObjectHandle>::iterator iter = this->part6.begin(); | 582 | for (std::vector<QPDFObjectHandle>::iterator iter = this->part6.begin(); |
| 582 | iter != this->part6.end(); ++iter) | 583 | iter != this->part6.end(); ++iter) |
| 583 | { | 584 | { |
| @@ -585,8 +586,8 @@ QPDF::checkLinearizationInternal() | @@ -585,8 +586,8 @@ QPDF::checkLinearizationInternal() | ||
| 585 | // All objects have to have been dereferenced to be classified. | 586 | // All objects have to have been dereferenced to be classified. |
| 586 | assert(this->obj_cache.count(og) > 0); | 587 | assert(this->obj_cache.count(og) > 0); |
| 587 | ObjCache const& oc = this->obj_cache[og]; | 588 | ObjCache const& oc = this->obj_cache[og]; |
| 588 | - min_E = std::max(min_E, (int)oc.end_before_space); | ||
| 589 | - max_E = std::max(max_E, (int)oc.end_after_space); | 589 | + min_E = std::max(min_E, oc.end_before_space); |
| 590 | + max_E = std::max(max_E, oc.end_after_space); | ||
| 590 | } | 591 | } |
| 591 | if ((p.first_page_end < min_E) || (p.first_page_end > max_E)) | 592 | if ((p.first_page_end < min_E) || (p.first_page_end > max_E)) |
| 592 | { | 593 | { |
| @@ -632,19 +633,18 @@ QPDF::checkLinearizationInternal() | @@ -632,19 +633,18 @@ QPDF::checkLinearizationInternal() | ||
| 632 | return result; | 633 | return result; |
| 633 | } | 634 | } |
| 634 | 635 | ||
| 635 | -int | 636 | +qpdf_offset_t |
| 636 | QPDF::maxEnd(ObjUser const& ou) | 637 | QPDF::maxEnd(ObjUser const& ou) |
| 637 | { | 638 | { |
| 638 | assert(this->obj_user_to_objects.count(ou) > 0); | 639 | assert(this->obj_user_to_objects.count(ou) > 0); |
| 639 | std::set<ObjGen> const& ogs = this->obj_user_to_objects[ou]; | 640 | std::set<ObjGen> const& ogs = this->obj_user_to_objects[ou]; |
| 640 | - int end = 0; | 641 | + qpdf_offset_t end = 0; |
| 641 | for (std::set<ObjGen>::const_iterator iter = ogs.begin(); | 642 | for (std::set<ObjGen>::const_iterator iter = ogs.begin(); |
| 642 | iter != ogs.end(); ++iter) | 643 | iter != ogs.end(); ++iter) |
| 643 | { | 644 | { |
| 644 | ObjGen const& og = *iter; | 645 | ObjGen const& og = *iter; |
| 645 | assert(this->obj_cache.count(og) > 0); | 646 | assert(this->obj_cache.count(og) > 0); |
| 646 | - end = std::max( | ||
| 647 | - end, (int)(this->obj_cache[og].end_after_space)); | 647 | + end = std::max(end, this->obj_cache[og].end_after_space); |
| 648 | } | 648 | } |
| 649 | return end; | 649 | return end; |
| 650 | } | 650 | } |
| @@ -736,7 +736,7 @@ QPDF::checkHPageOffset(std::list<std::string>& errors, | @@ -736,7 +736,7 @@ QPDF::checkHPageOffset(std::list<std::string>& 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 = (unsigned int)pages.size(); | 739 | + unsigned int npages = 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()); |
| @@ -1435,7 +1435,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1435,7 +1435,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1435 | pages.push_back(getUncompressedObject(*iter, object_stream_data)); | 1435 | pages.push_back(getUncompressedObject(*iter, object_stream_data)); |
| 1436 | } | 1436 | } |
| 1437 | } | 1437 | } |
| 1438 | - unsigned int npages = (unsigned int)pages.size(); | 1438 | + unsigned int npages = pages.size(); |
| 1439 | 1439 | ||
| 1440 | // We will be initializing some values of the computed hint | 1440 | // We will be initializing some values of the computed hint |
| 1441 | // tables. Specifically, we can initialize any items that deal | 1441 | // tables. Specifically, we can initialize any items that deal |
| @@ -1505,7 +1505,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1505,7 +1505,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1505 | // in garbage values for all the shared object identifiers on the | 1505 | // in garbage values for all the shared object identifiers on the |
| 1506 | // first page. | 1506 | // first page. |
| 1507 | 1507 | ||
| 1508 | - this->c_page_offset_data.entries[0].nobjects = (int)this->part6.size(); | 1508 | + this->c_page_offset_data.entries[0].nobjects = this->part6.size(); |
| 1509 | 1509 | ||
| 1510 | // Part 7: other pages' private objects | 1510 | // Part 7: other pages' private objects |
| 1511 | 1511 | ||
| @@ -1657,10 +1657,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1657,10 +1657,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1657 | // Make sure we got everything exactly once. | 1657 | // Make sure we got everything exactly once. |
| 1658 | 1658 | ||
| 1659 | unsigned int num_placed = | 1659 | unsigned int num_placed = |
| 1660 | - (unsigned int)(this->part4.size() + this->part6.size() + | ||
| 1661 | - this->part7.size() + this->part8.size() + | ||
| 1662 | - this->part9.size()); | ||
| 1663 | - unsigned int num_wanted = (unsigned int)this->object_to_obj_users.size(); | 1660 | + this->part4.size() + this->part6.size() + this->part7.size() + |
| 1661 | + this->part8.size() + this->part9.size(); | ||
| 1662 | + unsigned int num_wanted = this->object_to_obj_users.size(); | ||
| 1664 | if (num_placed != num_wanted) | 1663 | if (num_placed != num_wanted) |
| 1665 | { | 1664 | { |
| 1666 | throw std::logic_error( | 1665 | throw std::logic_error( |
| @@ -1684,11 +1683,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1684,11 +1683,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1684 | // can map from object number only without regards to generation. | 1683 | // can map from object number only without regards to generation. |
| 1685 | std::map<int, int> obj_to_index; | 1684 | std::map<int, int> obj_to_index; |
| 1686 | 1685 | ||
| 1687 | - this->c_shared_object_data.nshared_first_page = | ||
| 1688 | - (unsigned int)this->part6.size(); | 1686 | + this->c_shared_object_data.nshared_first_page = this->part6.size(); |
| 1689 | this->c_shared_object_data.nshared_total = | 1687 | this->c_shared_object_data.nshared_total = |
| 1690 | - this->c_shared_object_data.nshared_first_page + | ||
| 1691 | - (unsigned int) this->part8.size(); | 1688 | + this->c_shared_object_data.nshared_first_page + this->part8.size(); |
| 1692 | 1689 | ||
| 1693 | std::vector<CHSharedObjectEntry>& shared = | 1690 | std::vector<CHSharedObjectEntry>& shared = |
| 1694 | this->c_shared_object_data.entries; | 1691 | this->c_shared_object_data.entries; |
| @@ -1697,7 +1694,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1697,7 +1694,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1697 | { | 1694 | { |
| 1698 | QPDFObjectHandle& oh = *iter; | 1695 | QPDFObjectHandle& oh = *iter; |
| 1699 | int obj = oh.getObjectID(); | 1696 | int obj = oh.getObjectID(); |
| 1700 | - obj_to_index[obj] = (int)shared.size(); | 1697 | + obj_to_index[obj] = shared.size(); |
| 1701 | shared.push_back(CHSharedObjectEntry(obj)); | 1698 | shared.push_back(CHSharedObjectEntry(obj)); |
| 1702 | } | 1699 | } |
| 1703 | QTC::TC("qpdf", "QPDF lin part 8 empty", this->part8.empty() ? 1 : 0); | 1700 | QTC::TC("qpdf", "QPDF lin part 8 empty", this->part8.empty() ? 1 : 0); |
| @@ -1711,12 +1708,12 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | @@ -1711,12 +1708,12 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data) | ||
| 1711 | { | 1708 | { |
| 1712 | QPDFObjectHandle& oh = *iter; | 1709 | QPDFObjectHandle& oh = *iter; |
| 1713 | int obj = oh.getObjectID(); | 1710 | int obj = oh.getObjectID(); |
| 1714 | - obj_to_index[obj] = (int)shared.size(); | 1711 | + obj_to_index[obj] = shared.size(); |
| 1715 | shared.push_back(CHSharedObjectEntry(obj)); | 1712 | shared.push_back(CHSharedObjectEntry(obj)); |
| 1716 | } | 1713 | } |
| 1717 | } | 1714 | } |
| 1718 | - assert(this->c_shared_object_data.nshared_total == | ||
| 1719 | - (int) this->c_shared_object_data.entries.size()); | 1715 | + assert(static_cast<size_t>(this->c_shared_object_data.nshared_total) == |
| 1716 | + this->c_shared_object_data.entries.size()); | ||
| 1720 | 1717 | ||
| 1721 | // Now compute the list of shared objects for each page after the | 1718 | // Now compute the list of shared objects for each page after the |
| 1722 | // first page. | 1719 | // first page. |
| @@ -1827,7 +1824,7 @@ QPDF::calculateHPageOffset( | @@ -1827,7 +1824,7 @@ QPDF::calculateHPageOffset( | ||
| 1827 | // values. | 1824 | // values. |
| 1828 | 1825 | ||
| 1829 | std::vector<QPDFObjectHandle> const& pages = getAllPages(); | 1826 | std::vector<QPDFObjectHandle> const& pages = getAllPages(); |
| 1830 | - unsigned int npages = (unsigned int)pages.size(); | 1827 | + unsigned int npages = pages.size(); |
| 1831 | CHPageOffset& cph = this->c_page_offset_data; | 1828 | CHPageOffset& cph = this->c_page_offset_data; |
| 1832 | std::vector<CHPageOffsetEntry>& cphe = cph.entries; | 1829 | std::vector<CHPageOffsetEntry>& cphe = cph.entries; |
| 1833 | 1830 | ||
| @@ -2032,7 +2029,7 @@ QPDF::writeHPageOffset(BitWriter& w) | @@ -2032,7 +2029,7 @@ QPDF::writeHPageOffset(BitWriter& w) | ||
| 2032 | w.writeBits(t.nbits_shared_numerator, 16); // 12 | 2029 | w.writeBits(t.nbits_shared_numerator, 16); // 12 |
| 2033 | w.writeBits(t.shared_denominator, 16); // 13 | 2030 | w.writeBits(t.shared_denominator, 16); // 13 |
| 2034 | 2031 | ||
| 2035 | - unsigned int nitems = (unsigned int)getAllPages().size(); | 2032 | + unsigned int nitems = getAllPages().size(); |
| 2036 | std::vector<HPageOffsetEntry>& entries = t.entries; | 2033 | std::vector<HPageOffsetEntry>& entries = t.entries; |
| 2037 | 2034 | ||
| 2038 | write_vector_int(w, nitems, entries, | 2035 | write_vector_int(w, nitems, entries, |
| @@ -2123,12 +2120,12 @@ QPDF::generateHintStream(std::map<int, QPDFXRefEntry> const& xref, | @@ -2123,12 +2120,12 @@ QPDF::generateHintStream(std::map<int, QPDFXRefEntry> const& xref, | ||
| 2123 | BitWriter w(&c); | 2120 | BitWriter w(&c); |
| 2124 | 2121 | ||
| 2125 | writeHPageOffset(w); | 2122 | writeHPageOffset(w); |
| 2126 | - S = (int)c.getCount(); | 2123 | + S = c.getCount(); |
| 2127 | writeHSharedObject(w); | 2124 | writeHSharedObject(w); |
| 2128 | O = 0; | 2125 | O = 0; |
| 2129 | if (this->outline_hints.nobjects > 0) | 2126 | if (this->outline_hints.nobjects > 0) |
| 2130 | { | 2127 | { |
| 2131 | - O = (int)c.getCount(); | 2128 | + O = c.getCount(); |
| 2132 | writeHGeneric(w, this->outline_hints); | 2129 | writeHGeneric(w, this->outline_hints); |
| 2133 | } | 2130 | } |
| 2134 | c.finish(); | 2131 | c.finish(); |
libqpdf/QPDF_optimization.cc
| @@ -73,7 +73,7 @@ QPDF::optimize(std::map<int, int> const& object_stream_data, | @@ -73,7 +73,7 @@ QPDF::optimize(std::map<int, int> const& object_stream_data, | ||
| 73 | pushInheritedAttributesToPage(allow_changes, false); | 73 | pushInheritedAttributesToPage(allow_changes, false); |
| 74 | 74 | ||
| 75 | // Traverse pages | 75 | // Traverse pages |
| 76 | - int n = (int)this->all_pages.size(); | 76 | + int n = this->all_pages.size(); |
| 77 | for (int pageno = 0; pageno < n; ++pageno) | 77 | for (int pageno = 0; pageno < n; ++pageno) |
| 78 | { | 78 | { |
| 79 | updateObjectMaps(ObjUser(ObjUser::ou_page, pageno), | 79 | updateObjectMaps(ObjUser(ObjUser::ou_page, pageno), |
libqpdf/QPDF_pages.cc
| @@ -110,7 +110,7 @@ QPDF::flattenPagesTree() | @@ -110,7 +110,7 @@ QPDF::flattenPagesTree() | ||
| 110 | 110 | ||
| 111 | QPDFObjectHandle pages = getRoot().getKey("/Pages"); | 111 | QPDFObjectHandle pages = getRoot().getKey("/Pages"); |
| 112 | 112 | ||
| 113 | - int const len = (int)this->all_pages.size(); | 113 | + int const len = this->all_pages.size(); |
| 114 | for (int pos = 0; pos < len; ++pos) | 114 | for (int pos = 0; pos < len; ++pos) |
| 115 | { | 115 | { |
| 116 | // populate pageobj_to_pages_pos and fix parent pointer | 116 | // populate pageobj_to_pages_pos and fix parent pointer |
| @@ -175,25 +175,26 @@ QPDF::insertPage(QPDFObjectHandle newpage, int pos) | @@ -175,25 +175,26 @@ QPDF::insertPage(QPDFObjectHandle newpage, int pos) | ||
| 175 | 175 | ||
| 176 | QTC::TC("qpdf", "QPDF insert page", | 176 | QTC::TC("qpdf", "QPDF insert page", |
| 177 | (pos == 0) ? 0 : // insert at beginning | 177 | (pos == 0) ? 0 : // insert at beginning |
| 178 | - (pos == ((int)this->all_pages.size())) ? 1 : // insert at end | 178 | + (pos == static_cast<int>(this->all_pages.size())) ? 1 : // at end |
| 179 | 2); // insert in middle | 179 | 2); // insert in middle |
| 180 | 180 | ||
| 181 | QPDFObjectHandle pages = getRoot().getKey("/Pages"); | 181 | QPDFObjectHandle pages = getRoot().getKey("/Pages"); |
| 182 | QPDFObjectHandle kids = pages.getKey("/Kids"); | 182 | QPDFObjectHandle kids = pages.getKey("/Kids"); |
| 183 | - assert ((pos >= 0) && (pos <= (int)this->all_pages.size())); | 183 | + assert ((pos >= 0) && |
| 184 | + (static_cast<size_t>(pos) <= this->all_pages.size())); | ||
| 184 | 185 | ||
| 185 | newpage.replaceKey("/Parent", pages); | 186 | newpage.replaceKey("/Parent", pages); |
| 186 | kids.insertItem(pos, newpage); | 187 | kids.insertItem(pos, newpage); |
| 187 | int npages = kids.getArrayNItems(); | 188 | int npages = kids.getArrayNItems(); |
| 188 | pages.replaceKey("/Count", QPDFObjectHandle::newInteger(npages)); | 189 | pages.replaceKey("/Count", QPDFObjectHandle::newInteger(npages)); |
| 189 | this->all_pages.insert(this->all_pages.begin() + pos, newpage); | 190 | this->all_pages.insert(this->all_pages.begin() + pos, newpage); |
| 190 | - assert((int)this->all_pages.size() == npages); | 191 | + assert(this->all_pages.size() == static_cast<size_t>(npages)); |
| 191 | for (int i = pos + 1; i < npages; ++i) | 192 | for (int i = pos + 1; i < npages; ++i) |
| 192 | { | 193 | { |
| 193 | insertPageobjToPage(this->all_pages[i], i, false); | 194 | insertPageobjToPage(this->all_pages[i], i, false); |
| 194 | } | 195 | } |
| 195 | insertPageobjToPage(newpage, pos, true); | 196 | insertPageobjToPage(newpage, pos, true); |
| 196 | - assert((int)this->pageobj_to_pages_pos.size() == npages); | 197 | + assert(this->pageobj_to_pages_pos.size() == static_cast<size_t>(npages)); |
| 197 | } | 198 | } |
| 198 | 199 | ||
| 199 | void | 200 | void |
| @@ -201,9 +202,9 @@ QPDF::removePage(QPDFObjectHandle page) | @@ -201,9 +202,9 @@ QPDF::removePage(QPDFObjectHandle page) | ||
| 201 | { | 202 | { |
| 202 | int pos = findPage(page); // also ensures flat /Pages | 203 | int pos = findPage(page); // also ensures flat /Pages |
| 203 | QTC::TC("qpdf", "QPDF remove page", | 204 | QTC::TC("qpdf", "QPDF remove page", |
| 204 | - (pos == 0) ? 0 : // remove at beginning | ||
| 205 | - (pos == ((int)this->all_pages.size() - 1)) ? 1 : // remove at end | ||
| 206 | - 2); // remove in middle | 205 | + (pos == 0) ? 0 : // remove at beginning |
| 206 | + (pos == static_cast<int>(this->all_pages.size() - 1)) ? 1 : // end | ||
| 207 | + 2); // remove in middle | ||
| 207 | 208 | ||
| 208 | QPDFObjectHandle pages = getRoot().getKey("/Pages"); | 209 | QPDFObjectHandle pages = getRoot().getKey("/Pages"); |
| 209 | QPDFObjectHandle kids = pages.getKey("/Kids"); | 210 | QPDFObjectHandle kids = pages.getKey("/Kids"); |
| @@ -212,10 +213,10 @@ QPDF::removePage(QPDFObjectHandle page) | @@ -212,10 +213,10 @@ QPDF::removePage(QPDFObjectHandle page) | ||
| 212 | int npages = kids.getArrayNItems(); | 213 | int npages = kids.getArrayNItems(); |
| 213 | pages.replaceKey("/Count", QPDFObjectHandle::newInteger(npages)); | 214 | pages.replaceKey("/Count", QPDFObjectHandle::newInteger(npages)); |
| 214 | this->all_pages.erase(this->all_pages.begin() + pos); | 215 | this->all_pages.erase(this->all_pages.begin() + pos); |
| 215 | - assert((int)this->all_pages.size() == npages); | 216 | + assert(this->all_pages.size() == static_cast<size_t>(npages)); |
| 216 | this->pageobj_to_pages_pos.erase( | 217 | this->pageobj_to_pages_pos.erase( |
| 217 | ObjGen(page.getObjectID(), page.getGeneration())); | 218 | ObjGen(page.getObjectID(), page.getGeneration())); |
| 218 | - assert((int)this->pageobj_to_pages_pos.size() == npages); | 219 | + assert(this->pageobj_to_pages_pos.size() == static_cast<size_t>(npages)); |
| 219 | for (int i = pos; i < npages; ++i) | 220 | for (int i = pos; i < npages; ++i) |
| 220 | { | 221 | { |
| 221 | insertPageobjToPage(this->all_pages[i], i, false); | 222 | insertPageobjToPage(this->all_pages[i], i, false); |
libqpdf/QUtil.cc
| @@ -26,7 +26,7 @@ QUtil::int_to_string(long long num, int fullpad) | @@ -26,7 +26,7 @@ QUtil::int_to_string(long long num, int fullpad) | ||
| 26 | char t[50]; | 26 | char t[50]; |
| 27 | 27 | ||
| 28 | // -2 or -1 to leave space for the possible negative sign and for NUL... | 28 | // -2 or -1 to leave space for the possible negative sign and for NUL... |
| 29 | - if (abs(fullpad) > (int)sizeof(t) - ((num < 0)?2:1)) | 29 | + if (abs(fullpad) > sizeof(t) - ((num < 0)?2:1)) |
| 30 | { | 30 | { |
| 31 | throw std::logic_error("Util::int_to_string has been called with " | 31 | throw std::logic_error("Util::int_to_string has been called with " |
| 32 | "a padding value greater than its internal " | 32 | "a padding value greater than its internal " |
| @@ -58,7 +58,7 @@ QUtil::double_to_string(double num, int decimal_places) | @@ -58,7 +58,7 @@ QUtil::double_to_string(double num, int decimal_places) | ||
| 58 | // 99 digits. | 58 | // 99 digits. |
| 59 | char t[100]; | 59 | char t[100]; |
| 60 | 60 | ||
| 61 | - std::string lhs = int_to_string((int)num); | 61 | + std::string lhs = int_to_string(static_cast<int>(num)); |
| 62 | 62 | ||
| 63 | // lhs.length() gives us the length of the part on the right hand | 63 | // lhs.length() gives us the length of the part on the right hand |
| 64 | // side of the dot + 1 for the dot + decimal_places: total size of | 64 | // side of the dot + 1 for the dot + decimal_places: total size of |
| @@ -68,7 +68,8 @@ QUtil::double_to_string(double num, int decimal_places) | @@ -68,7 +68,8 @@ QUtil::double_to_string(double num, int decimal_places) | ||
| 68 | // If decimal_places <= 0, it is as if no precision was provided | 68 | // If decimal_places <= 0, it is as if no precision was provided |
| 69 | // so trust the buffer is big enough. The following test will | 69 | // so trust the buffer is big enough. The following test will |
| 70 | // always pass in those cases. | 70 | // always pass in those cases. |
| 71 | - if (decimal_places + 1 + (int)lhs.length() > (int)sizeof(t) - 1) | 71 | + if (decimal_places + 1 + static_cast<int>(lhs.length()) > |
| 72 | + static_cast<int>(sizeof(t)) - 1) | ||
| 72 | { | 73 | { |
| 73 | throw std::logic_error("Util::double_to_string has been called with " | 74 | throw std::logic_error("Util::double_to_string has been called with " |
| 74 | "a number and a decimal places specification " | 75 | "a number and a decimal places specification " |
| @@ -96,6 +97,18 @@ QUtil::string_to_ll(char const* str) | @@ -96,6 +97,18 @@ QUtil::string_to_ll(char const* str) | ||
| 96 | #endif | 97 | #endif |
| 97 | } | 98 | } |
| 98 | 99 | ||
| 100 | +unsigned char* | ||
| 101 | +QUtil::unsigned_char_pointer(std::string const& str) | ||
| 102 | +{ | ||
| 103 | + return reinterpret_cast<unsigned char*>(const_cast<char*>(str.c_str())); | ||
| 104 | +} | ||
| 105 | + | ||
| 106 | +unsigned char* | ||
| 107 | +QUtil::unsigned_char_pointer(char const* str) | ||
| 108 | +{ | ||
| 109 | + return reinterpret_cast<unsigned char*>(const_cast<char*>(str)); | ||
| 110 | +} | ||
| 111 | + | ||
| 99 | void | 112 | void |
| 100 | QUtil::throw_system_error(std::string const& description) | 113 | QUtil::throw_system_error(std::string const& description) |
| 101 | { | 114 | { |
| @@ -126,14 +139,14 @@ int | @@ -126,14 +139,14 @@ int | ||
| 126 | QUtil::seek(FILE* stream, qpdf_offset_t offset, int whence) | 139 | QUtil::seek(FILE* stream, qpdf_offset_t offset, int whence) |
| 127 | { | 140 | { |
| 128 | #if HAVE_FSEEKO | 141 | #if HAVE_FSEEKO |
| 129 | - return fseeko(stream, (off_t)offset, whence); | 142 | + return fseeko(stream, static_cast<off_t>(offset), whence); |
| 130 | #elif HAVE_FSEEKO64 | 143 | #elif HAVE_FSEEKO64 |
| 131 | return fseeko64(stream, offset, whence); | 144 | return fseeko64(stream, offset, whence); |
| 132 | #else | 145 | #else |
| 133 | # ifdef _MSC_VER | 146 | # ifdef _MSC_VER |
| 134 | return _fseeki64(stream, offset, whence); | 147 | return _fseeki64(stream, offset, whence); |
| 135 | # else | 148 | # else |
| 136 | - return fseek(stream, (long)offset, whence); | 149 | + return fseek(stream, static_cast<long>(offset), whence); |
| 137 | # endif | 150 | # endif |
| 138 | #endif | 151 | #endif |
| 139 | } | 152 | } |
| @@ -142,14 +155,14 @@ qpdf_offset_t | @@ -142,14 +155,14 @@ qpdf_offset_t | ||
| 142 | QUtil::tell(FILE* stream) | 155 | QUtil::tell(FILE* stream) |
| 143 | { | 156 | { |
| 144 | #if HAVE_FSEEKO | 157 | #if HAVE_FSEEKO |
| 145 | - return (qpdf_offset_t)ftello(stream); | 158 | + return static_cast<qpdf_offset_t>(ftello(stream)); |
| 146 | #elif HAVE_FSEEKO64 | 159 | #elif HAVE_FSEEKO64 |
| 147 | - return (qpdf_offset_t)ftello64(stream); | 160 | + return static_cast<qpdf_offset_t>(ftello64(stream)); |
| 148 | #else | 161 | #else |
| 149 | # ifdef _MSC_VER | 162 | # ifdef _MSC_VER |
| 150 | return _ftelli64(stream); | 163 | return _ftelli64(stream); |
| 151 | # else | 164 | # else |
| 152 | - return (qpdf_offset_t)ftell(stream); | 165 | + return static_cast<qpdf_offset_t>(ftell(stream)); |
| 153 | # endif | 166 | # endif |
| 154 | #endif | 167 | #endif |
| 155 | } | 168 | } |
| @@ -174,7 +187,7 @@ QUtil::hex_encode(std::string const& input) | @@ -174,7 +187,7 @@ QUtil::hex_encode(std::string const& input) | ||
| 174 | buf[hex_size - 1] = '\0'; | 187 | buf[hex_size - 1] = '\0'; |
| 175 | for (unsigned int i = 0; i < input_size; ++i) | 188 | for (unsigned int i = 0; i < input_size; ++i) |
| 176 | { | 189 | { |
| 177 | - sprintf(buf + i * 2, "%02x", (unsigned char)input[i]); | 190 | + sprintf(buf + i * 2, "%02x", static_cast<unsigned char>(input[i])); |
| 178 | } | 191 | } |
| 179 | return buf; | 192 | return buf; |
| 180 | } | 193 | } |
| @@ -199,7 +212,7 @@ void | @@ -199,7 +212,7 @@ void | ||
| 199 | QUtil::setLineBuf(FILE* f) | 212 | QUtil::setLineBuf(FILE* f) |
| 200 | { | 213 | { |
| 201 | #ifndef _WIN32 | 214 | #ifndef _WIN32 |
| 202 | - setvbuf(f, (char *) NULL, _IOLBF, 0); | 215 | + setvbuf(f, reinterpret_cast<char *>(NULL), _IOLBF, 0); |
| 203 | #endif | 216 | #endif |
| 204 | } | 217 | } |
| 205 | 218 | ||
| @@ -314,7 +327,7 @@ QUtil::toUTF8(unsigned long uval) | @@ -314,7 +327,7 @@ QUtil::toUTF8(unsigned long uval) | ||
| 314 | } | 327 | } |
| 315 | else if (uval < 128) | 328 | else if (uval < 128) |
| 316 | { | 329 | { |
| 317 | - result += (char)(uval); | 330 | + result += static_cast<char>(uval); |
| 318 | } | 331 | } |
| 319 | else | 332 | else |
| 320 | { | 333 | { |
| @@ -329,7 +342,7 @@ QUtil::toUTF8(unsigned long uval) | @@ -329,7 +342,7 @@ QUtil::toUTF8(unsigned long uval) | ||
| 329 | { | 342 | { |
| 330 | // Assign low six bits plus 10000000 to lowest unused | 343 | // Assign low six bits plus 10000000 to lowest unused |
| 331 | // byte position, then shift | 344 | // byte position, then shift |
| 332 | - *cur_byte = (unsigned char) (0x80 + (uval & 0x3f)); | 345 | + *cur_byte = static_cast<unsigned char>(0x80 + (uval & 0x3f)); |
| 333 | uval >>= 6; | 346 | uval >>= 6; |
| 334 | // Maximum that will fit in high byte now shrinks by one bit | 347 | // Maximum that will fit in high byte now shrinks by one bit |
| 335 | maxval >>= 1; | 348 | maxval >>= 1; |
| @@ -342,9 +355,10 @@ QUtil::toUTF8(unsigned long uval) | @@ -342,9 +355,10 @@ QUtil::toUTF8(unsigned long uval) | ||
| 342 | } | 355 | } |
| 343 | // If maxval is k bits long, the high (7 - k) bits of the | 356 | // If maxval is k bits long, the high (7 - k) bits of the |
| 344 | // resulting byte must be high. | 357 | // resulting byte must be high. |
| 345 | - *cur_byte = (unsigned char)((0xff - (1 + (maxval << 1))) + uval); | 358 | + *cur_byte = static_cast<unsigned char>( |
| 359 | + (0xff - (1 + (maxval << 1))) + uval); | ||
| 346 | 360 | ||
| 347 | - result += (char*)cur_byte; | 361 | + result += reinterpret_cast<char*>(cur_byte); |
| 348 | } | 362 | } |
| 349 | 363 | ||
| 350 | return result; | 364 | return result; |
| @@ -358,8 +372,8 @@ QUtil::random() | @@ -358,8 +372,8 @@ QUtil::random() | ||
| 358 | { | 372 | { |
| 359 | // Seed the random number generator with something simple, but | 373 | // Seed the random number generator with something simple, but |
| 360 | // just to be interesting, don't use the unmodified current | 374 | // just to be interesting, don't use the unmodified current |
| 361 | - // time.... | ||
| 362 | - QUtil::srandom((int)QUtil::get_current_time() ^ 0xcccc); | 375 | + // time. It would be better if this were a more secure seed. |
| 376 | + QUtil::srandom(QUtil::get_current_time() ^ 0xcccc); | ||
| 363 | seeded_random = true; | 377 | seeded_random = true; |
| 364 | } | 378 | } |
| 365 | 379 | ||
| @@ -385,6 +399,6 @@ QUtil::initializeWithRandomBytes(unsigned char* data, size_t len) | @@ -385,6 +399,6 @@ QUtil::initializeWithRandomBytes(unsigned char* data, size_t len) | ||
| 385 | { | 399 | { |
| 386 | for (size_t i = 0; i < len; ++i) | 400 | for (size_t i = 0; i < len; ++i) |
| 387 | { | 401 | { |
| 388 | - data[i] = (unsigned char)((QUtil::random() & 0xff0) >> 4); | 402 | + data[i] = static_cast<unsigned char>((QUtil::random() & 0xff0) >> 4); |
| 389 | } | 403 | } |
| 390 | } | 404 | } |
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 = (int)strlen((char*)key_data); | 18 | + key_len = strlen(reinterpret_cast<char const*>(key_data)); |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | for (int i = 0; i < 256; ++i) | 21 | for (int i = 0; i < 256; ++i) |
libqpdf/rijndael.cc
| @@ -693,15 +693,17 @@ static const u32 rcon[] = | @@ -693,15 +693,17 @@ static const u32 rcon[] = | ||
| 693 | /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */ | 693 | /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */ |
| 694 | }; | 694 | }; |
| 695 | 695 | ||
| 696 | -#define GETU32(plaintext) (((u32)(plaintext)[0] << 24) ^ \ | ||
| 697 | - ((u32)(plaintext)[1] << 16) ^ \ | ||
| 698 | - ((u32)(plaintext)[2] << 8) ^ \ | ||
| 699 | - ((u32)(plaintext)[3])) | 696 | +#define GETU32(plaintext) \ |
| 697 | + ((static_cast<u32>((plaintext)[0]) << 24) ^ \ | ||
| 698 | + (static_cast<u32>((plaintext)[1]) << 16) ^ \ | ||
| 699 | + (static_cast<u32>((plaintext)[2]) << 8) ^ \ | ||
| 700 | + (static_cast<u32>((plaintext)[3]))) | ||
| 700 | 701 | ||
| 701 | -#define PUTU32(ciphertext, st) { (ciphertext)[0] = (u8)((st) >> 24); \ | ||
| 702 | - (ciphertext)[1] = (u8)((st) >> 16); \ | ||
| 703 | - (ciphertext)[2] = (u8)((st) >> 8); \ | ||
| 704 | - (ciphertext)[3] = (u8)(st); } | 702 | +#define PUTU32(ciphertext, st) { \ |
| 703 | + (ciphertext)[0] = static_cast<u8>((st) >> 24); \ | ||
| 704 | + (ciphertext)[1] = static_cast<u8>((st) >> 16); \ | ||
| 705 | + (ciphertext)[2] = static_cast<u8>((st) >> 8); \ | ||
| 706 | + (ciphertext)[3] = static_cast<u8>(st); } | ||
| 705 | 707 | ||
| 706 | /** | 708 | /** |
| 707 | * Expand the cipher key into the encryption key schedule. | 709 | * Expand the cipher key into the encryption key schedule. |
libtests/aes.cc
| @@ -86,7 +86,7 @@ int main(int argc, char* argv[]) | @@ -86,7 +86,7 @@ int main(int argc, char* argv[]) | ||
| 86 | usage(); | 86 | usage(); |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | - unsigned int hexkeylen = (unsigned int)strlen(hexkey); | 89 | + unsigned int hexkeylen = strlen(hexkey); |
| 90 | unsigned int keylen = hexkeylen / 2; | 90 | unsigned int keylen = hexkeylen / 2; |
| 91 | 91 | ||
| 92 | FILE* infile = fopen(infilename, "rb"); | 92 | FILE* infile = fopen(infilename, "rb"); |
| @@ -112,7 +112,7 @@ int main(int argc, char* argv[]) | @@ -112,7 +112,7 @@ int main(int argc, char* argv[]) | ||
| 112 | t[2] = '\0'; | 112 | t[2] = '\0'; |
| 113 | 113 | ||
| 114 | long val = strtol(t, 0, 16); | 114 | long val = strtol(t, 0, 16); |
| 115 | - key[i/2] = (unsigned char) val; | 115 | + key[i/2] = static_cast<unsigned char>(val); |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | Pl_StdioFile* out = new Pl_StdioFile("stdout", outfile); | 118 | Pl_StdioFile* out = new Pl_StdioFile("stdout", outfile); |
libtests/bits.cc
| @@ -37,7 +37,8 @@ test_write_bits(unsigned char& ch, unsigned int& bit_offset, unsigned long val, | @@ -37,7 +37,8 @@ test_write_bits(unsigned char& ch, unsigned int& bit_offset, unsigned long val, | ||
| 37 | int bits, Pl_Buffer* bp) | 37 | int bits, Pl_Buffer* bp) |
| 38 | { | 38 | { |
| 39 | write_bits(ch, bit_offset, val, bits, bp); | 39 | write_bits(ch, bit_offset, val, bits, bp); |
| 40 | - printf("ch = %02x, bit_offset = %d\n", (unsigned int) ch, bit_offset); | 40 | + printf("ch = %02x, bit_offset = %d\n", |
| 41 | + static_cast<unsigned int>(ch), bit_offset); | ||
| 41 | } | 42 | } |
| 42 | 43 | ||
| 43 | static void | 44 | static void |
| @@ -49,7 +50,7 @@ print_buffer(Pl_Buffer* bp) | @@ -49,7 +50,7 @@ print_buffer(Pl_Buffer* bp) | ||
| 49 | size_t l = b->getSize(); | 50 | size_t l = b->getSize(); |
| 50 | for (unsigned long i = 0; i < l; ++i) | 51 | for (unsigned long i = 0; i < l; ++i) |
| 51 | { | 52 | { |
| 52 | - printf("%02x%s", (unsigned int)(p[i]), | 53 | + printf("%02x%s", static_cast<unsigned int>(p[i]), |
| 53 | (i == l - 1) ? "\n" : " "); | 54 | (i == l - 1) ? "\n" : " "); |
| 54 | } | 55 | } |
| 55 | printf("\n"); | 56 | printf("\n"); |
libtests/buffer.cc
| 1 | #include <qpdf/Pl_Buffer.hh> | 1 | #include <qpdf/Pl_Buffer.hh> |
| 2 | #include <qpdf/Pl_Count.hh> | 2 | #include <qpdf/Pl_Count.hh> |
| 3 | #include <qpdf/Pl_Discard.hh> | 3 | #include <qpdf/Pl_Discard.hh> |
| 4 | +#include <qpdf/QUtil.hh> | ||
| 4 | #include <stdlib.h> | 5 | #include <stdlib.h> |
| 5 | #include <stdexcept> | 6 | #include <stdexcept> |
| 6 | #include <iostream> | 7 | #include <iostream> |
| 7 | 8 | ||
| 8 | -typedef unsigned char* uc; | 9 | +static unsigned char* uc(char const* s) |
| 10 | +{ | ||
| 11 | + return QUtil::unsigned_char_pointer(s); | ||
| 12 | +} | ||
| 9 | 13 | ||
| 10 | int main() | 14 | int main() |
| 11 | { | 15 | { |
| @@ -14,20 +18,20 @@ int main() | @@ -14,20 +18,20 @@ int main() | ||
| 14 | Pl_Discard discard; | 18 | Pl_Discard discard; |
| 15 | Pl_Count count("count", &discard); | 19 | Pl_Count count("count", &discard); |
| 16 | Pl_Buffer bp1("bp1", &count); | 20 | Pl_Buffer bp1("bp1", &count); |
| 17 | - bp1.write((uc)"12345", 5); | ||
| 18 | - bp1.write((uc)"67890", 5); | 21 | + bp1.write(uc("12345"), 5); |
| 22 | + bp1.write(uc("67890"), 5); | ||
| 19 | bp1.finish(); | 23 | bp1.finish(); |
| 20 | std::cout << "count: " << count.getCount() << std::endl; | 24 | std::cout << "count: " << count.getCount() << std::endl; |
| 21 | - bp1.write((uc)"abcde", 5); | ||
| 22 | - bp1.write((uc)"fghij", 6); | 25 | + bp1.write(uc("abcde"), 5); |
| 26 | + bp1.write(uc("fghij"), 6); | ||
| 23 | bp1.finish(); | 27 | bp1.finish(); |
| 24 | std::cout << "count: " << count.getCount() << std::endl; | 28 | std::cout << "count: " << count.getCount() << std::endl; |
| 25 | Buffer* b = bp1.getBuffer(); | 29 | Buffer* b = bp1.getBuffer(); |
| 26 | std::cout << "size: " << b->getSize() << std::endl; | 30 | std::cout << "size: " << b->getSize() << std::endl; |
| 27 | std::cout << "data: " << b->getBuffer() << std::endl; | 31 | std::cout << "data: " << b->getBuffer() << std::endl; |
| 28 | delete b; | 32 | delete b; |
| 29 | - bp1.write((uc)"qwert", 5); | ||
| 30 | - bp1.write((uc)"yuiop", 6); | 33 | + bp1.write(uc("qwert"), 5); |
| 34 | + bp1.write(uc("yuiop"), 6); | ||
| 31 | bp1.finish(); | 35 | bp1.finish(); |
| 32 | std::cout << "count: " << count.getCount() << std::endl; | 36 | std::cout << "count: " << count.getCount() << std::endl; |
| 33 | b = bp1.getBuffer(); | 37 | b = bp1.getBuffer(); |
| @@ -36,8 +40,8 @@ int main() | @@ -36,8 +40,8 @@ int main() | ||
| 36 | delete b; | 40 | delete b; |
| 37 | 41 | ||
| 38 | Pl_Buffer bp2("bp2"); | 42 | Pl_Buffer bp2("bp2"); |
| 39 | - bp2.write((uc)"moo", 3); | ||
| 40 | - bp2.write((uc)"quack", 6); | 43 | + bp2.write(uc("moo"), 3); |
| 44 | + bp2.write(uc("quack"), 6); | ||
| 41 | try | 45 | try |
| 42 | { | 46 | { |
| 43 | delete bp2.getBuffer(); | 47 | delete bp2.getBuffer(); |
libtests/concatenate.cc
| 1 | #include <qpdf/Pl_Concatenate.hh> | 1 | #include <qpdf/Pl_Concatenate.hh> |
| 2 | #include <qpdf/Pl_Flate.hh> | 2 | #include <qpdf/Pl_Flate.hh> |
| 3 | #include <qpdf/Pl_Buffer.hh> | 3 | #include <qpdf/Pl_Buffer.hh> |
| 4 | +#include <qpdf/QUtil.hh> | ||
| 4 | #include <iostream> | 5 | #include <iostream> |
| 5 | #include <assert.h> | 6 | #include <assert.h> |
| 6 | 7 | ||
| 7 | static void pipeStringAndFinish(Pipeline* p, std::string const& str) | 8 | static void pipeStringAndFinish(Pipeline* p, std::string const& str) |
| 8 | { | 9 | { |
| 9 | - p->write((unsigned char*)str.c_str(), str.length()); | 10 | + p->write(QUtil::unsigned_char_pointer(str), str.length()); |
| 10 | p->finish(); | 11 | p->finish(); |
| 11 | } | 12 | } |
| 12 | 13 | ||
| @@ -25,7 +26,8 @@ int main(int argc, char* argv[]) | @@ -25,7 +26,8 @@ int main(int argc, char* argv[]) | ||
| 25 | inflate.write(b1_buf->getBuffer(), b1_buf->getSize()); | 26 | inflate.write(b1_buf->getBuffer(), b1_buf->getSize()); |
| 26 | inflate.finish(); | 27 | inflate.finish(); |
| 27 | PointerHolder<Buffer> b2_buf = b2.getBuffer(); | 28 | PointerHolder<Buffer> b2_buf = b2.getBuffer(); |
| 28 | - std::string result((char const*)b2_buf->getBuffer(), b2_buf->getSize()); | 29 | + std::string result(reinterpret_cast<char*>(b2_buf->getBuffer()), |
| 30 | + b2_buf->getSize()); | ||
| 29 | if (result == "-one--two-") | 31 | if (result == "-one--two-") |
| 30 | { | 32 | { |
| 31 | std::cout << "concatenate test passed" << std::endl; | 33 | std::cout << "concatenate test passed" << std::endl; |
libtests/qutil.cc
| @@ -152,7 +152,7 @@ static void print_utf8(unsigned long val) | @@ -152,7 +152,7 @@ static void print_utf8(unsigned long val) | ||
| 152 | iter != result.end(); ++iter) | 152 | iter != result.end(); ++iter) |
| 153 | { | 153 | { |
| 154 | char t[3]; | 154 | char t[3]; |
| 155 | - sprintf(t, "%02x", (unsigned char) (*iter)); | 155 | + sprintf(t, "%02x", static_cast<unsigned char>(*iter)); |
| 156 | std::cout << " " << t; | 156 | std::cout << " " << t; |
| 157 | } | 157 | } |
| 158 | } | 158 | } |
libtests/rc4.cc
| @@ -17,7 +17,7 @@ int main(int argc, char* argv[]) | @@ -17,7 +17,7 @@ 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 | - unsigned int hexkeylen = (unsigned int)strlen(hexkey); | 20 | + unsigned int hexkeylen = strlen(hexkey); |
| 21 | unsigned int keylen = hexkeylen / 2; | 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'; |
| @@ -37,7 +37,7 @@ int main(int argc, char* argv[]) | @@ -37,7 +37,7 @@ int main(int argc, char* argv[]) | ||
| 37 | t[2] = '\0'; | 37 | t[2] = '\0'; |
| 38 | 38 | ||
| 39 | long val = strtol(t, 0, 16); | 39 | long val = strtol(t, 0, 16); |
| 40 | - key[i/2] = (unsigned char) val; | 40 | + key[i/2] = static_cast<unsigned char>(val); |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | FILE* outfile = fopen(outfilename, "wb"); | 43 | FILE* outfile = fopen(outfilename, "wb"); |
libtests/sha2.cc
| @@ -8,7 +8,7 @@ static void test(Pl_SHA2& sha2, char const* description, int bits, | @@ -8,7 +8,7 @@ static void test(Pl_SHA2& sha2, char const* description, int bits, | ||
| 8 | char const* input, std::string const& output) | 8 | char const* input, std::string const& output) |
| 9 | { | 9 | { |
| 10 | sha2.resetBits(bits); | 10 | sha2.resetBits(bits); |
| 11 | - sha2.write((unsigned char*) input, strlen(input)); | 11 | + sha2.write(QUtil::unsigned_char_pointer(input), strlen(input)); |
| 12 | sha2.finish(); | 12 | sha2.finish(); |
| 13 | std::cout << description << ": "; | 13 | std::cout << description << ": "; |
| 14 | if (output == sha2.getHexDigest()) | 14 | if (output == sha2.getHexDigest()) |
qpdf/qpdf.cc
| @@ -881,7 +881,7 @@ QPDFPageData::QPDFPageData(QPDF* qpdf, char const* range) : | @@ -881,7 +881,7 @@ QPDFPageData::QPDFPageData(QPDF* qpdf, char const* range) : | ||
| 881 | qpdf(qpdf), | 881 | qpdf(qpdf), |
| 882 | orig_pages(qpdf->getAllPages()) | 882 | orig_pages(qpdf->getAllPages()) |
| 883 | { | 883 | { |
| 884 | - this->selected_pages = parse_numrange(range, (int)this->orig_pages.size()); | 884 | + this->selected_pages = parse_numrange(range, this->orig_pages.size()); |
| 885 | } | 885 | } |
| 886 | 886 | ||
| 887 | static void parse_version(std::string const& full_version_string, | 887 | static void parse_version(std::string const& full_version_string, |
| @@ -1012,7 +1012,7 @@ int main(int argc, char* argv[]) | @@ -1012,7 +1012,7 @@ int main(int argc, char* argv[]) | ||
| 1012 | // Be lax about -arg vs --arg | 1012 | // Be lax about -arg vs --arg |
| 1013 | ++arg; | 1013 | ++arg; |
| 1014 | } | 1014 | } |
| 1015 | - char* parameter = (char*)strchr(arg, '='); | 1015 | + char* parameter = const_cast<char*>(strchr(arg, '=')); |
| 1016 | if (parameter) | 1016 | if (parameter) |
| 1017 | { | 1017 | { |
| 1018 | *parameter++ = 0; | 1018 | *parameter++ = 0; |
qpdf/test_driver.cc
| @@ -95,7 +95,8 @@ static std::string getPageContents(QPDFObjectHandle page) | @@ -95,7 +95,8 @@ static std::string getPageContents(QPDFObjectHandle page) | ||
| 95 | { | 95 | { |
| 96 | PointerHolder<Buffer> b1 = | 96 | PointerHolder<Buffer> b1 = |
| 97 | page.getKey("/Contents").getStreamData(); | 97 | page.getKey("/Contents").getStreamData(); |
| 98 | - return std::string((char *)(b1->getBuffer()), b1->getSize()) + "\0"; | 98 | + return std::string( |
| 99 | + reinterpret_cast<char *>(b1->getBuffer()), b1->getSize()) + "\0"; | ||
| 99 | } | 100 | } |
| 100 | 101 | ||
| 101 | static void checkPageContents(QPDFObjectHandle page, | 102 | static void checkPageContents(QPDFObjectHandle page, |
| @@ -175,7 +176,7 @@ void runtest(int n, char const* filename1, char const* arg2) | @@ -175,7 +176,7 @@ void runtest(int n, char const* filename1, char const* arg2) | ||
| 175 | FILE* f = QUtil::fopen_wrapper(std::string("open ") + filename1, | 176 | FILE* f = QUtil::fopen_wrapper(std::string("open ") + filename1, |
| 176 | fopen(filename1, "rb")); | 177 | fopen(filename1, "rb")); |
| 177 | fseek(f, 0, SEEK_END); | 178 | fseek(f, 0, SEEK_END); |
| 178 | - size_t size = (size_t) QUtil::tell(f); | 179 | + size_t size = QUtil::tell(f); |
| 179 | fseek(f, 0, SEEK_SET); | 180 | fseek(f, 0, SEEK_SET); |
| 180 | file_buf = PointerHolder<char>(true, new char[size]); | 181 | file_buf = PointerHolder<char>(true, new char[size]); |
| 181 | char* buf_p = file_buf.getPointer(); | 182 | char* buf_p = file_buf.getPointer(); |
| @@ -495,7 +496,8 @@ void runtest(int n, char const* filename1, char const* arg2) | @@ -495,7 +496,8 @@ void runtest(int n, char const* filename1, char const* arg2) | ||
| 495 | unsigned char const* data = buf->getBuffer(); | 496 | unsigned char const* data = buf->getBuffer(); |
| 496 | bool cleartext = false; | 497 | bool cleartext = false; |
| 497 | if ((buf->getSize() > 9) && | 498 | if ((buf->getSize() > 9) && |
| 498 | - (strncmp((char const*)data, "<?xpacket", 9) == 0)) | 499 | + (strncmp(reinterpret_cast<char const*>(data), |
| 500 | + "<?xpacket", 9) == 0)) | ||
| 499 | { | 501 | { |
| 500 | cleartext = true; | 502 | cleartext = true; |
| 501 | } | 503 | } |
| @@ -532,7 +534,8 @@ void runtest(int n, char const* filename1, char const* arg2) | @@ -532,7 +534,8 @@ void runtest(int n, char const* filename1, char const* arg2) | ||
| 532 | } | 534 | } |
| 533 | Pl_Buffer p1("buffer"); | 535 | Pl_Buffer p1("buffer"); |
| 534 | Pl_Flate p2("compress", &p1, Pl_Flate::a_deflate); | 536 | Pl_Flate p2("compress", &p1, Pl_Flate::a_deflate); |
| 535 | - p2.write((unsigned char*)"new data for stream\n", 20); // no null! | 537 | + p2.write(QUtil::unsigned_char_pointer("new data for stream\n"), |
| 538 | + 20); // no null! | ||
| 536 | p2.finish(); | 539 | p2.finish(); |
| 537 | PointerHolder<Buffer> b = p1.getBuffer(); | 540 | PointerHolder<Buffer> b = p1.getBuffer(); |
| 538 | // This is a bogus way to use StreamDataProvider, but it does | 541 | // This is a bogus way to use StreamDataProvider, but it does |
| @@ -569,7 +572,7 @@ void runtest(int n, char const* filename1, char const* arg2) | @@ -569,7 +572,7 @@ void runtest(int n, char const* filename1, char const* arg2) | ||
| 569 | // Explicitly exercise the Buffer version of newStream | 572 | // Explicitly exercise the Buffer version of newStream |
| 570 | PointerHolder<Buffer> buf = new Buffer(20); | 573 | PointerHolder<Buffer> buf = new Buffer(20); |
| 571 | unsigned char* bp = buf->getBuffer(); | 574 | unsigned char* bp = buf->getBuffer(); |
| 572 | - memcpy(bp, (char*)"data for new stream\n", 20); // no null! | 575 | + memcpy(bp, "data for new stream\n", 20); // no null! |
| 573 | QPDFObjectHandle qstream = QPDFObjectHandle::newStream( | 576 | QPDFObjectHandle qstream = QPDFObjectHandle::newStream( |
| 574 | &pdf, buf); | 577 | &pdf, buf); |
| 575 | QPDFObjectHandle rstream = QPDFObjectHandle::newStream(&pdf); | 578 | QPDFObjectHandle rstream = QPDFObjectHandle::newStream(&pdf); |
| @@ -824,7 +827,7 @@ void runtest(int n, char const* filename1, char const* arg2) | @@ -824,7 +827,7 @@ void runtest(int n, char const* filename1, char const* arg2) | ||
| 824 | page.replaceKey("/Parent", pages); | 827 | page.replaceKey("/Parent", pages); |
| 825 | pages.replaceKey( | 828 | pages.replaceKey( |
| 826 | "/Count", | 829 | "/Count", |
| 827 | - QPDFObjectHandle::newInteger(1 + (int)all_pages.size())); | 830 | + QPDFObjectHandle::newInteger(1 + all_pages.size())); |
| 828 | kids.appendItem(page); | 831 | kids.appendItem(page); |
| 829 | assert(all_pages.size() == 10); | 832 | assert(all_pages.size() == 10); |
| 830 | pdf.updateAllPagesCache(); | 833 | pdf.updateAllPagesCache(); |
| @@ -1220,7 +1223,7 @@ void runtest(int n, char const* filename1, char const* arg2) | @@ -1220,7 +1223,7 @@ void runtest(int n, char const* filename1, char const* arg2) | ||
| 1220 | { | 1223 | { |
| 1221 | std::string const& filename = (*iter).first; | 1224 | std::string const& filename = (*iter).first; |
| 1222 | std::string data = std::string( | 1225 | std::string data = std::string( |
| 1223 | - (char const*)(*iter).second->getBuffer(), | 1226 | + reinterpret_cast<char const*>((*iter).second->getBuffer()), |
| 1224 | (*iter).second->getSize()); | 1227 | (*iter).second->getSize()); |
| 1225 | bool is_binary = false; | 1228 | bool is_binary = false; |
| 1226 | for (size_t i = 0; i < data.size(); ++i) | 1229 | for (size_t i = 0; i < data.size(); ++i) |
| @@ -1234,7 +1237,9 @@ void runtest(int n, char const* filename1, char const* arg2) | @@ -1234,7 +1237,9 @@ void runtest(int n, char const* filename1, char const* arg2) | ||
| 1234 | if (is_binary) | 1237 | if (is_binary) |
| 1235 | { | 1238 | { |
| 1236 | std::string t; | 1239 | std::string t; |
| 1237 | - for (size_t i = 0; i < std::min(data.size(), (size_t)20); ++i) | 1240 | + for (size_t i = 0; |
| 1241 | + i < std::min(data.size(), static_cast<size_t>(20)); | ||
| 1242 | + ++i) | ||
| 1238 | { | 1243 | { |
| 1239 | if ((data[i] >= 32) && (data[i] <= 126)) | 1244 | if ((data[i] >= 32) && (data[i] <= 126)) |
| 1240 | { | 1245 | { |
| @@ -1276,7 +1281,8 @@ void runtest(int n, char const* filename1, char const* arg2) | @@ -1276,7 +1281,8 @@ void runtest(int n, char const* filename1, char const* arg2) | ||
| 1276 | stream.pipeStreamData(&p2, false, false, false); | 1281 | stream.pipeStreamData(&p2, false, false, false); |
| 1277 | PointerHolder<Buffer> buf = p1.getBuffer(); | 1282 | PointerHolder<Buffer> buf = p1.getBuffer(); |
| 1278 | std::string data = std::string( | 1283 | std::string data = std::string( |
| 1279 | - (char const*)buf->getBuffer(), buf->getSize()); | 1284 | + reinterpret_cast<char const*>(buf->getBuffer()), |
| 1285 | + buf->getSize()); | ||
| 1280 | std::cout << stream.getDict().unparse() | 1286 | std::cout << stream.getDict().unparse() |
| 1281 | << filename << ":\n" << data << "--END--\n"; | 1287 | << filename << ":\n" << data << "--END--\n"; |
| 1282 | } | 1288 | } |
qpdf/test_large_file.cc
| @@ -135,7 +135,7 @@ ImageProvider::provideStreamData(int objid, int generation, | @@ -135,7 +135,7 @@ ImageProvider::provideStreamData(int objid, int generation, | ||
| 135 | for (int y = 0; y < nstripes; ++y) | 135 | for (int y = 0; y < nstripes; ++y) |
| 136 | { | 136 | { |
| 137 | unsigned char color = get_pixel_color(n, y); | 137 | unsigned char color = get_pixel_color(n, y); |
| 138 | - memset(buf, (int) color, width * stripesize); | 138 | + memset(buf, color, width * stripesize); |
| 139 | pipeline->write(buf, width * stripesize); | 139 | pipeline->write(buf, width * stripesize); |
| 140 | } | 140 | } |
| 141 | pipeline->finish(); | 141 | pipeline->finish(); |
| @@ -256,7 +256,8 @@ static void check_page_contents(int pageno, QPDFObjectHandle page) | @@ -256,7 +256,8 @@ static void check_page_contents(int pageno, QPDFObjectHandle page) | ||
| 256 | PointerHolder<Buffer> buf = | 256 | PointerHolder<Buffer> buf = |
| 257 | page.getKey("/Contents").getStreamData(); | 257 | page.getKey("/Contents").getStreamData(); |
| 258 | std::string actual_contents = | 258 | std::string actual_contents = |
| 259 | - std::string((char *)(buf->getBuffer()), buf->getSize()); | 259 | + std::string(reinterpret_cast<char *>(buf->getBuffer()), |
| 260 | + buf->getSize()); | ||
| 260 | std::string expected_contents = generate_page_contents(pageno); | 261 | std::string expected_contents = generate_page_contents(pageno); |
| 261 | if (expected_contents != actual_contents) | 262 | if (expected_contents != actual_contents) |
| 262 | { | 263 | { |
| @@ -280,7 +281,7 @@ static void check_pdf(char const* filename) | @@ -280,7 +281,7 @@ static void check_pdf(char const* filename) | ||
| 280 | QPDF pdf; | 281 | QPDF pdf; |
| 281 | pdf.processFile(filename); | 282 | pdf.processFile(filename); |
| 282 | std::vector<QPDFObjectHandle> const& pages = pdf.getAllPages(); | 283 | std::vector<QPDFObjectHandle> const& pages = pdf.getAllPages(); |
| 283 | - assert(pages.size() == (size_t)npages); | 284 | + assert(pages.size() == static_cast<size_t>(npages)); |
| 284 | for (int i = 0; i < npages; ++i) | 285 | for (int i = 0; i < npages; ++i) |
| 285 | { | 286 | { |
| 286 | int pageno = i + 1; | 287 | int pageno = i + 1; |