Commit 30027481f7f9e9191f7c8deea51850b7a76b1b1f

Authored by Jay Berkenbilt
1 parent babb4794

Remove all old-style casts from C++ code

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