aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2013-02-24 03:46:21 +0100
committerJay Berkenbilt <ejb@ql.org>2013-03-04 22:45:16 +0100
commit30027481f7f9e9191f7c8deea51850b7a76b1b1f (patch)
tree815af293c2f6e38994e6096a4499be0dc9a476f9 /libqpdf
parentbabb47948a408ebad12c452ba3fdd78782360167 (diff)
downloadqpdf-30027481f7f9e9191f7c8deea51850b7a76b1b1f.tar.zst
Remove all old-style casts from C++ code
Diffstat (limited to 'libqpdf')
-rw-r--r--libqpdf/BufferInputSource.cc19
-rw-r--r--libqpdf/FileInputSource.cc6
-rw-r--r--libqpdf/MD5.cc55
-rw-r--r--libqpdf/PCRE.cc2
-rw-r--r--libqpdf/Pl_AES_PDF.cc3
-rw-r--r--libqpdf/Pl_ASCII85Decoder.cc4
-rw-r--r--libqpdf/Pl_ASCIIHexDecoder.cc2
-rw-r--r--libqpdf/Pl_Flate.cc29
-rw-r--r--libqpdf/Pl_LZWDecoder.cc8
-rw-r--r--libqpdf/Pl_MD5.cc3
-rw-r--r--libqpdf/Pl_PNGFilter.cc2
-rw-r--r--libqpdf/Pl_RC4.cc2
-rw-r--r--libqpdf/Pl_SHA2.cc9
-rw-r--r--libqpdf/QPDF.cc21
-rw-r--r--libqpdf/QPDFObjectHandle.cc6
-rw-r--r--libqpdf/QPDFTokenizer.cc8
-rw-r--r--libqpdf/QPDFWriter.cc55
-rw-r--r--libqpdf/QPDFXRefEntry.cc2
-rw-r--r--libqpdf/QPDF_Array.cc6
-rw-r--r--libqpdf/QPDF_Stream.cc2
-rw-r--r--libqpdf/QPDF_String.cc8
-rw-r--r--libqpdf/QPDF_encryption.cc119
-rw-r--r--libqpdf/QPDF_linearization.cc61
-rw-r--r--libqpdf/QPDF_optimization.cc2
-rw-r--r--libqpdf/QPDF_pages.cc21
-rw-r--r--libqpdf/QUtil.cc48
-rw-r--r--libqpdf/RC4.cc2
-rw-r--r--libqpdf/rijndael.cc18
28 files changed, 284 insertions, 239 deletions
diff --git a/libqpdf/BufferInputSource.cc b/libqpdf/BufferInputSource.cc
index 03439955..73baefae 100644
--- a/libqpdf/BufferInputSource.cc
+++ b/libqpdf/BufferInputSource.cc
@@ -20,7 +20,7 @@ BufferInputSource::BufferInputSource(std::string const& description,
{
this->buf = new Buffer(contents.length());
unsigned char* bp = buf->getBuffer();
- memcpy(bp, (char*)contents.c_str(), contents.length());
+ memcpy(bp, contents.c_str(), contents.length());
}
BufferInputSource::~BufferInputSource()
@@ -38,7 +38,7 @@ BufferInputSource::findAndSkipNextEOL()
{
throw std::logic_error("INTERNAL ERROR: BufferInputSource offset < 0");
}
- qpdf_offset_t end_pos = (qpdf_offset_t) this->buf->getSize();
+ qpdf_offset_t end_pos = this->buf->getSize();
if (this->cur_offset >= end_pos)
{
this->last_offset = end_pos;
@@ -47,12 +47,12 @@ BufferInputSource::findAndSkipNextEOL()
}
qpdf_offset_t result = 0;
- size_t len = (size_t)(end_pos - this->cur_offset);
+ size_t len = end_pos - this->cur_offset;
unsigned char const* buffer = this->buf->getBuffer();
- void* start = (void*)(buffer + this->cur_offset);
- unsigned char* p1 = (unsigned char*)memchr(start, '\r', len);
- unsigned char* p2 = (unsigned char*)memchr(start, '\n', len);
+ void* start = const_cast<unsigned char*>(buffer) + this->cur_offset;
+ unsigned char* p1 = static_cast<unsigned char*>(memchr(start, '\r', len));
+ unsigned char* p2 = static_cast<unsigned char*>(memchr(start, '\n', len));
unsigned char* p = (p1 && p2) ? std::min(p1, p2) : p1 ? p1 : p2;
if (p)
{
@@ -96,7 +96,7 @@ BufferInputSource::seek(qpdf_offset_t offset, int whence)
break;
case SEEK_END:
- this->cur_offset = (qpdf_offset_t)this->buf->getSize() + offset;
+ this->cur_offset = this->buf->getSize() + offset;
break;
case SEEK_CUR:
@@ -129,7 +129,7 @@ BufferInputSource::read(char* buffer, size_t length)
{
throw std::logic_error("INTERNAL ERROR: BufferInputSource offset < 0");
}
- qpdf_offset_t end_pos = (qpdf_offset_t) this->buf->getSize();
+ qpdf_offset_t end_pos = this->buf->getSize();
if (this->cur_offset >= end_pos)
{
this->last_offset = end_pos;
@@ -137,7 +137,8 @@ BufferInputSource::read(char* buffer, size_t length)
}
this->last_offset = this->cur_offset;
- size_t len = std::min((size_t)(end_pos - this->cur_offset), length);
+ size_t len = std::min(
+ static_cast<size_t>(end_pos - this->cur_offset), length);
memcpy(buffer, buf->getBuffer() + this->cur_offset, len);
this->cur_offset += len;
return len;
diff --git a/libqpdf/FileInputSource.cc b/libqpdf/FileInputSource.cc
index b1f7b5d2..b49fad99 100644
--- a/libqpdf/FileInputSource.cc
+++ b/libqpdf/FileInputSource.cc
@@ -62,8 +62,8 @@ FileInputSource::findAndSkipNextEOL()
}
else
{
- char* p1 = (char*)memchr((void*)buf, '\r', len);
- char* p2 = (char*)memchr((void*)buf, '\n', len);
+ char* p1 = static_cast<char*>(memchr(buf, '\r', len));
+ char* p2 = static_cast<char*>(memchr(buf, '\n', len));
char* p = (p1 && p2) ? std::min(p1, p2) : p1 ? p1 : p2;
if (p)
{
@@ -137,5 +137,5 @@ void
FileInputSource::unreadCh(char ch)
{
QUtil::os_wrapper(this->filename + ": unread character",
- ungetc((unsigned char)ch, this->file));
+ ungetc(static_cast<unsigned char>(ch), this->file));
}
diff --git a/libqpdf/MD5.cc b/libqpdf/MD5.cc
index 57bcc45f..73ba7f9f 100644
--- a/libqpdf/MD5.cc
+++ b/libqpdf/MD5.cc
@@ -71,22 +71,22 @@ static unsigned char PADDING[64] = {
// FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
// Rotation is separate from addition to prevent recomputation.
#define FF(a, b, c, d, x, s, ac) { \
- (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) += F ((b), (c), (d)) + (x) + static_cast<UINT4>(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define GG(a, b, c, d, x, s, ac) { \
- (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) += G ((b), (c), (d)) + (x) + static_cast<UINT4>(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define HH(a, b, c, d, x, s, ac) { \
- (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) += H ((b), (c), (d)) + (x) + static_cast<UINT4>(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define II(a, b, c, d, x, s, ac) { \
- (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) += I ((b), (c), (d)) + (x) + static_cast<UINT4>(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
@@ -115,21 +115,20 @@ void MD5::update(unsigned char *input,
unsigned int i, index, partLen;
// Compute number of bytes mod 64
- index = (unsigned int)((count[0] >> 3) & 0x3F);
+ index = static_cast<unsigned int>((count[0] >> 3) & 0x3f);
// Update number of bits
- if ((count[0] += ((UINT4)inputLen << 3))
- < ((UINT4)inputLen << 3))
+ if ((count[0] += (static_cast<UINT4>(inputLen) << 3)) <
+ (static_cast<UINT4>(inputLen) << 3))
count[1]++;
- count[1] += ((UINT4)inputLen >> 29);
+ count[1] += (static_cast<UINT4>(inputLen) >> 29);
partLen = 64 - index;
// Transform as many times as possible.
if (inputLen >= partLen) {
- memcpy
- ((POINTER)&buffer[index], (POINTER)input, partLen);
+ memcpy(&buffer[index], input, partLen);
transform(state, buffer);
for (i = partLen; i + 63 < inputLen; i += 64)
@@ -141,9 +140,7 @@ void MD5::update(unsigned char *input,
i = 0;
// Buffer remaining input
- memcpy
- ((POINTER)&buffer[index], (POINTER)&input[i],
- inputLen-i);
+ memcpy(&buffer[index], &input[i], inputLen-i);
}
// MD5 finalization. Ends an MD5 message-digest operation, writing the
@@ -163,7 +160,7 @@ void MD5::final()
// Pad out to 56 mod 64.
- index = (unsigned int)((count[0] >> 3) & 0x3f);
+ index = static_cast<unsigned int>((count[0] >> 3) & 0x3f);
padLen = (index < 56) ? (56 - index) : (120 - index);
update(PADDING, padLen);
@@ -266,7 +263,7 @@ void MD5::transform(UINT4 state[4], unsigned char block[64])
// Zeroize sensitive information.
- memset ((POINTER)x, 0, sizeof (x));
+ memset (x, 0, sizeof (x));
}
// 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)
unsigned int i, j;
for (i = 0, j = 0; j < len; i++, j += 4) {
- output[j] = (unsigned char)(input[i] & 0xff);
- output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
- output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
- output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
+ output[j] = static_cast<unsigned char>(input[i] & 0xff);
+ output[j+1] = static_cast<unsigned char>((input[i] >> 8) & 0xff);
+ output[j+2] = static_cast<unsigned char>((input[i] >> 16) & 0xff);
+ output[j+3] = static_cast<unsigned char>((input[i] >> 24) & 0xff);
}
}
@@ -290,8 +287,11 @@ void MD5::decode(UINT4 *output, unsigned char *input, unsigned int len)
unsigned int i, j;
for (i = 0, j = 0; j < len; i++, j += 4)
- output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
- (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
+ output[i] =
+ static_cast<UINT4>(input[j]) |
+ (static_cast<UINT4>(input[j+1]) << 8) |
+ (static_cast<UINT4>(input[j+2]) << 16) |
+ (static_cast<UINT4>(input[j+3]) << 24);
}
// Public functions
@@ -308,20 +308,20 @@ void MD5::reset()
void MD5::encodeString(char const* str)
{
- unsigned int len = (unsigned int)strlen(str);
+ unsigned int len = strlen(str);
- update((unsigned char *)str, len);
+ update(QUtil::unsigned_char_pointer(str), len);
final();
}
void MD5::appendString(char const* input_string)
{
- update((unsigned char *)input_string, (unsigned int) strlen(input_string));
+ update(QUtil::unsigned_char_pointer(input_string), strlen(input_string));
}
void MD5::encodeDataIncrementally(char const* data, int len)
{
- update((unsigned char *)data, len);
+ update(QUtil::unsigned_char_pointer(data), len);
}
void MD5::encodeFile(char const *filename, int up_to_size)
@@ -344,7 +344,7 @@ void MD5::encodeFile(char const *filename, int up_to_size)
len = fread(buffer, 1, to_try, file);
if (len > 0)
{
- update(buffer, (unsigned int) len);
+ update(buffer, len);
so_far += len;
if ((up_to_size >= 0) && (so_far >= up_to_size))
{
@@ -386,7 +386,8 @@ void MD5::print()
std::string MD5::unparse()
{
final();
- return QUtil::hex_encode(std::string((char*)digest_val, 16));
+ return QUtil::hex_encode(
+ std::string(reinterpret_cast<char*>(digest_val), 16));
}
std::string
diff --git a/libqpdf/PCRE.cc b/libqpdf/PCRE.cc
index 1e5585b0..2e808aa7 100644
--- a/libqpdf/PCRE.cc
+++ b/libqpdf/PCRE.cc
@@ -166,7 +166,7 @@ PCRE::match(char const* subject, int options, int startoffset, int size)
{
if (size == -1)
{
- size = (int) strlen(subject);
+ size = strlen(subject);
}
Match result(this->nbackrefs, subject);
diff --git a/libqpdf/Pl_AES_PDF.cc b/libqpdf/Pl_AES_PDF.cc
index 52876101..5c493cb4 100644
--- a/libqpdf/Pl_AES_PDF.cc
+++ b/libqpdf/Pl_AES_PDF.cc
@@ -122,7 +122,8 @@ Pl_AES_PDF::finish()
// Pad as described in section 3.5.1 of version 1.7 of the PDF
// specification, including providing an entire block of padding
// if the input was a multiple of 16 bytes.
- unsigned char pad = (unsigned char) (this->buf_size - this->offset);
+ unsigned char pad =
+ static_cast<unsigned char>(this->buf_size - this->offset);
memset(this->inbuf + this->offset, pad, pad);
this->offset = this->buf_size;
flush(false);
diff --git a/libqpdf/Pl_ASCII85Decoder.cc b/libqpdf/Pl_ASCII85Decoder.cc
index 5c9c9f56..3a3b57b1 100644
--- a/libqpdf/Pl_ASCII85Decoder.cc
+++ b/libqpdf/Pl_ASCII85Decoder.cc
@@ -68,7 +68,9 @@ Pl_ASCII85Decoder::write(unsigned char* buf, size_t len)
else
{
QTC::TC("libtests", "Pl_ASCII85Decoder read z");
- getNext()->write((unsigned char*)"\000\000\000\000", 4);
+ unsigned char zeroes[4];
+ memset(zeroes, '\0', 4);
+ getNext()->write(zeroes, 4);
}
break;
diff --git a/libqpdf/Pl_ASCIIHexDecoder.cc b/libqpdf/Pl_ASCIIHexDecoder.cc
index ca153e89..0ba85dc7 100644
--- a/libqpdf/Pl_ASCIIHexDecoder.cc
+++ b/libqpdf/Pl_ASCIIHexDecoder.cc
@@ -91,7 +91,7 @@ Pl_ASCIIHexDecoder::flush()
b[i] = this->inbuf[i] - '0';
}
}
- unsigned char ch = (unsigned char)((b[0] << 4) + b[1]);
+ unsigned char ch = static_cast<unsigned char>((b[0] << 4) + b[1]);
QTC::TC("libtests", "Pl_ASCIIHexDecoder partial flush",
(this->pos == 2) ? 0 : 1);
diff --git a/libqpdf/Pl_Flate.cc b/libqpdf/Pl_Flate.cc
index 30616707..be8ca8ba 100644
--- a/libqpdf/Pl_Flate.cc
+++ b/libqpdf/Pl_Flate.cc
@@ -18,10 +18,10 @@ Pl_Flate::Pl_Flate(char const* identifier, Pipeline* next,
// Windows environment.
this->zdata = new z_stream;
- z_stream& zstream = *((z_stream*) this->zdata);
- zstream.zalloc = (alloc_func)0;
- zstream.zfree = (free_func)0;
- zstream.opaque = (voidpf)0;
+ z_stream& zstream = *(static_cast<z_stream*>(this->zdata));
+ zstream.zalloc = 0;
+ zstream.zfree = 0;
+ zstream.opaque = 0;
zstream.next_in = 0;
zstream.avail_in = 0;
zstream.next_out = this->outbuf;
@@ -35,7 +35,7 @@ Pl_Flate::~Pl_Flate()
delete [] this->outbuf;
this->outbuf = 0;
}
- delete (z_stream*)this->zdata;
+ delete static_cast<z_stream*>(this->zdata);
this->zdata = 0;
}
@@ -57,7 +57,7 @@ Pl_Flate::write(unsigned char* data, size_t len)
while (bytes_left > 0)
{
size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left);
- handleData(buf, (int)bytes, Z_NO_FLUSH);
+ handleData(buf, bytes, Z_NO_FLUSH);
bytes_left -= bytes;
buf += bytes;
}
@@ -66,13 +66,20 @@ Pl_Flate::write(unsigned char* data, size_t len)
void
Pl_Flate::handleData(unsigned char* data, int len, int flush)
{
- z_stream& zstream = *((z_stream*) this->zdata);
+ z_stream& zstream = *(static_cast<z_stream*>(this->zdata));
zstream.next_in = data;
zstream.avail_in = len;
if (! this->initialized)
{
int err = Z_OK;
+
+ // deflateInit and inflateInit are macros that use old-style
+ // casts.
+#ifdef __GNUC__
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wold-style-cast"
+#endif
if (this->action == a_deflate)
{
err = deflateInit(&zstream, Z_DEFAULT_COMPRESSION);
@@ -81,6 +88,10 @@ Pl_Flate::handleData(unsigned char* data, int len, int flush)
{
err = inflateInit(&zstream);
}
+#ifdef __GNUC__
+# pragma GCC diagnostic pop
+#endif
+
checkError("Init", err);
this->initialized = true;
}
@@ -146,7 +157,7 @@ Pl_Flate::finish()
{
if (this->initialized)
{
- z_stream& zstream = *((z_stream*) this->zdata);
+ z_stream& zstream = *(static_cast<z_stream*>(this->zdata));
unsigned char buf[1];
buf[0] = '\0';
handleData(buf, 0, Z_FINISH);
@@ -171,7 +182,7 @@ Pl_Flate::finish()
void
Pl_Flate::checkError(char const* prefix, int error_code)
{
- z_stream& zstream = *((z_stream*) this->zdata);
+ z_stream& zstream = *(static_cast<z_stream*>(this->zdata));
if (error_code != Z_OK)
{
char const* action_str = (action == a_deflate ? "deflate" : "inflate");
diff --git a/libqpdf/Pl_LZWDecoder.cc b/libqpdf/Pl_LZWDecoder.cc
index 646e45de..f7c6fb30 100644
--- a/libqpdf/Pl_LZWDecoder.cc
+++ b/libqpdf/Pl_LZWDecoder.cc
@@ -98,7 +98,7 @@ Pl_LZWDecoder::getFirstChar(int code)
unsigned char result = '\0';
if (code < 256)
{
- result = (unsigned char) code;
+ result = static_cast<unsigned char>(code);
}
else
{
@@ -131,7 +131,7 @@ Pl_LZWDecoder::addToTable(unsigned char next)
assert(idx < table.size());
Buffer& b = table[idx];
last_data = b.getBuffer();
- last_size = (unsigned int) b.getSize();
+ last_size = b.getSize();
}
Buffer entry(1 + last_size);
@@ -170,7 +170,7 @@ Pl_LZWDecoder::handleCode(int code)
// be what we read last plus the first character of what
// we're reading now.
unsigned char next = '\0';
- unsigned int table_size = (unsigned int) table.size();
+ unsigned int table_size = table.size();
if (code < 256)
{
// just read < 256; last time's next was code
@@ -214,7 +214,7 @@ Pl_LZWDecoder::handleCode(int code)
if (code < 256)
{
- unsigned char ch = (unsigned char) code;
+ unsigned char ch = static_cast<unsigned char>(code);
getNext()->write(&ch, 1);
}
else
diff --git a/libqpdf/Pl_MD5.cc b/libqpdf/Pl_MD5.cc
index 44911b42..3a78cb33 100644
--- a/libqpdf/Pl_MD5.cc
+++ b/libqpdf/Pl_MD5.cc
@@ -28,7 +28,8 @@ Pl_MD5::write(unsigned char* buf, size_t len)
while (bytes_left > 0)
{
size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left);
- this->md5.encodeDataIncrementally((char*) data, (int)bytes);
+ this->md5.encodeDataIncrementally(
+ reinterpret_cast<char*>(data), bytes);
bytes_left -= bytes;
data += bytes;
}
diff --git a/libqpdf/Pl_PNGFilter.cc b/libqpdf/Pl_PNGFilter.cc
index 19b90c03..4b79e6b1 100644
--- a/libqpdf/Pl_PNGFilter.cc
+++ b/libqpdf/Pl_PNGFilter.cc
@@ -73,7 +73,7 @@ Pl_PNGFilter::processRow()
void
Pl_PNGFilter::decodeRow()
{
- int filter = (int) this->cur_row[0];
+ int filter = this->cur_row[0];
if (this->prev_row)
{
switch (filter)
diff --git a/libqpdf/Pl_RC4.cc b/libqpdf/Pl_RC4.cc
index 74bb16b9..87c17f83 100644
--- a/libqpdf/Pl_RC4.cc
+++ b/libqpdf/Pl_RC4.cc
@@ -38,7 +38,7 @@ Pl_RC4::write(unsigned char* data, size_t len)
size_t bytes =
(bytes_left < this->out_bufsize ? bytes_left : out_bufsize);
bytes_left -= bytes;
- rc4.process(p, (int)bytes, outbuf);
+ rc4.process(p, bytes, outbuf);
p += bytes;
getNext()->write(outbuf, bytes);
}
diff --git a/libqpdf/Pl_SHA2.cc b/libqpdf/Pl_SHA2.cc
index 84f24d6e..17eff7e3 100644
--- a/libqpdf/Pl_SHA2.cc
+++ b/libqpdf/Pl_SHA2.cc
@@ -128,13 +128,16 @@ Pl_SHA2::getRawDigest()
switch (bits)
{
case 256:
- result = std::string((char*)this->sha256sum, sizeof(this->sha256sum));
+ result = std::string(reinterpret_cast<char*>(this->sha256sum),
+ sizeof(this->sha256sum));
break;
case 384:
- result = std::string((char*)this->sha384sum, sizeof(this->sha384sum));
+ result = std::string(reinterpret_cast<char*>(this->sha384sum),
+ sizeof(this->sha384sum));
break;
case 512:
- result = std::string((char*)this->sha512sum, sizeof(this->sha512sum));
+ result = std::string(reinterpret_cast<char*>(this->sha512sum),
+ sizeof(this->sha512sum));
break;
default:
badBits();
diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc
index 5860fb11..7cd3509b 100644
--- a/libqpdf/QPDF.cc
+++ b/libqpdf/QPDF.cc
@@ -159,9 +159,10 @@ QPDF::processMemoryFile(char const* description,
char const* password)
{
processInputSource(
- new BufferInputSource(description,
- new Buffer((unsigned char*)buf, length),
- true),
+ new BufferInputSource(
+ description,
+ new Buffer(QUtil::unsigned_char_pointer(buf), length),
+ true),
password);
}
@@ -280,7 +281,7 @@ QPDF::parse(char const* password)
// where the regexp matches.
char* p = buf;
char const* candidate = "";
- while ((p = (char*)memchr(p, 's', tbuf_size - (p - buf))) != 0)
+ while ((p = static_cast<char*>(memchr(p, 's', tbuf_size - (p - buf)))) != 0)
{
if (eof_re.match(p))
{
@@ -796,7 +797,7 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj)
for (int k = 0; k < W[j]; ++k)
{
fields[j] <<= 8;
- fields[j] += (int)(*p++);
+ fields[j] += static_cast<int>(*p++);
}
}
@@ -828,7 +829,8 @@ QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj)
// This is needed by checkLinearization()
this->first_xref_item_offset = xref_offset;
}
- insertXrefEntry(obj, (int)fields[0], fields[1], (int)fields[2]);
+ insertXrefEntry(obj, static_cast<int>(fields[0]),
+ fields[1], static_cast<int>(fields[2]));
}
if (! this->trailer.isInitialized())
@@ -1096,8 +1098,7 @@ QPDF::readObject(PointerHolder<InputSource> input,
}
length = length_obj.getIntValue();
- input->seek(
- stream_offset + (qpdf_offset_t)length, SEEK_SET);
+ input->seek(stream_offset + length, SEEK_SET);
if (! (readToken(input) ==
QPDFTokenizer::Token(
QPDFTokenizer::tt_word, "endstream")))
@@ -1395,7 +1396,7 @@ QPDF::readObjectAtOffset(bool try_recovery,
char ch;
if (this->file->read(&ch, 1))
{
- if (! isspace((unsigned char)ch))
+ if (! isspace(static_cast<unsigned char>(ch)))
{
this->file->seek(-1, SEEK_CUR);
break;
@@ -2064,7 +2065,7 @@ QPDF::pipeStreamData(int objid, int generation,
"unexpected EOF reading stream data");
}
length -= len;
- pipeline->write((unsigned char*)buf, len);
+ pipeline->write(QUtil::unsigned_char_pointer(buf), len);
}
}
catch (QPDFExc& e)
diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc
index 1a7dfc73..e6f53d08 100644
--- a/libqpdf/QPDFObjectHandle.cc
+++ b/libqpdf/QPDFObjectHandle.cc
@@ -508,7 +508,7 @@ QPDFObjectHandle::replaceStreamData(std::string const& data,
assertStream();
PointerHolder<Buffer> b = new Buffer(data.length());
unsigned char* bp = b->getBuffer();
- memcpy(bp, (char*)data.c_str(), data.length());
+ memcpy(bp, data.c_str(), data.length());
dynamic_cast<QPDF_Stream*>(obj.getPointer())->replaceStreamData(
b, filter, decode_parms);
}
@@ -690,7 +690,7 @@ QPDFObjectHandle::parse(std::string const& object_str,
bool empty = false;
QPDFObjectHandle result =
parse(input, object_description, tokenizer, empty, 0, 0);
- size_t offset = (size_t) input->tell();
+ size_t offset = input->tell();
while (offset < object_str.length())
{
if (! isspace(object_str[offset]))
@@ -748,7 +748,7 @@ QPDFObjectHandle::parseContentStream_internal(QPDFObjectHandle stream,
QPDFTokenizer tokenizer;
tokenizer.allowEOF();
bool empty = false;
- while ((size_t) input->tell() < length)
+ while (static_cast<size_t>(input->tell()) < length)
{
QPDFObjectHandle obj =
parseInternal(input, "content", tokenizer, empty,
diff --git a/libqpdf/QPDFTokenizer.cc b/libqpdf/QPDFTokenizer.cc
index a6333b73..19442bab 100644
--- a/libqpdf/QPDFTokenizer.cc
+++ b/libqpdf/QPDFTokenizer.cc
@@ -80,7 +80,7 @@ QPDFTokenizer::resolveLiteral()
num[0] = p[1];
num[1] = p[2];
num[2] = '\0';
- char ch = (char)(strtol(num, 0, 16));
+ char ch = static_cast<char>(strtol(num, 0, 16));
if (ch == '\0')
{
type = tt_bad;
@@ -273,7 +273,7 @@ QPDFTokenizer::presentCharacter(char ch)
{
// We've accumulated \ddd. PDF Spec says to ignore
// high-order overflow.
- val += (char) strtol(bs_num_register, 0, 8);
+ val += static_cast<char>(strtol(bs_num_register, 0, 8));
memset(bs_num_register, '\0', sizeof(bs_num_register));
bs_num_count = 0;
}
@@ -399,7 +399,7 @@ QPDFTokenizer::presentCharacter(char ch)
{
num[0] = val[i];
num[1] = val[i+1];
- char nch = (char)(strtol(num, 0, 16));
+ char nch = static_cast<char>(strtol(num, 0, 16));
nval += nch;
}
val = nval;
@@ -511,7 +511,7 @@ QPDFTokenizer::readToken(PointerHolder<InputSource> input,
}
else
{
- if (is_space((unsigned char)ch) &&
+ if (is_space(static_cast<unsigned char>(ch)) &&
(input->getLastOffset() == offset))
{
++offset;
diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc
index a1949a9b..6384df54 100644
--- a/libqpdf/QPDFWriter.cc
+++ b/libqpdf/QPDFWriter.cc
@@ -772,7 +772,7 @@ QPDFWriter::writeBinary(unsigned long long val, unsigned int bytes)
unsigned char data[sizeof(unsigned long long)];
for (unsigned int i = 0; i < bytes; ++i)
{
- data[bytes - i - 1] = (unsigned char)(val & 0xff);
+ data[bytes - i - 1] = static_cast<unsigned char>(val & 0xff);
val >>= 8;
}
this->pipeline->write(data, bytes);
@@ -781,7 +781,7 @@ QPDFWriter::writeBinary(unsigned long long val, unsigned int bytes)
void
QPDFWriter::writeString(std::string const& str)
{
- this->pipeline->write((unsigned char*)str.c_str(), str.length());
+ this->pipeline->write(QUtil::unsigned_char_pointer(str), str.length());
}
void
@@ -887,14 +887,14 @@ QPDFWriter::pushEncryptionFilter()
{
p = new Pl_AES_PDF(
"aes stream encryption", this->pipeline, true,
- (unsigned char*) this->cur_data_key.c_str(),
- (unsigned int)this->cur_data_key.length());
+ QUtil::unsigned_char_pointer(this->cur_data_key),
+ this->cur_data_key.length());
}
else
{
p = new Pl_RC4("rc4 stream encryption", this->pipeline,
- (unsigned char*) this->cur_data_key.c_str(),
- (unsigned int)this->cur_data_key.length());
+ QUtil::unsigned_char_pointer(this->cur_data_key),
+ this->cur_data_key.length());
}
pushPipeline(p);
}
@@ -1087,7 +1087,7 @@ QPDFWriter::writeTrailer(trailer_e which, int size, bool xref_stream,
writeString(" /Prev ");
qpdf_offset_t pos = this->pipeline->getCount();
writeString(QUtil::int_to_string(prev));
- int nspaces = (int)(pos - this->pipeline->getCount() + 21);
+ int nspaces = pos - this->pipeline->getCount() + 21;
assert(nspaces >= 0);
writePad(nspaces);
}
@@ -1504,14 +1504,15 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level,
if (this->encrypt_use_aes)
{
Pl_Buffer bufpl("encrypted string");
- Pl_AES_PDF pl("aes encrypt string", &bufpl, true,
- (unsigned char const*)this->cur_data_key.c_str(),
- (unsigned int)this->cur_data_key.length());
- pl.write((unsigned char*) val.c_str(), val.length());
+ Pl_AES_PDF pl(
+ "aes encrypt string", &bufpl, true,
+ QUtil::unsigned_char_pointer(this->cur_data_key),
+ this->cur_data_key.length());
+ pl.write(QUtil::unsigned_char_pointer(val), val.length());
pl.finish();
Buffer* buf = bufpl.getBuffer();
val = QPDF_String(
- std::string((char*)buf->getBuffer(),
+ std::string(reinterpret_cast<char*>(buf->getBuffer()),
buf->getSize())).unparse(true);
delete buf;
}
@@ -1519,9 +1520,9 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level,
{
char* tmp = QUtil::copy_string(val);
size_t vlen = val.length();
- RC4 rc4((unsigned char const*)this->cur_data_key.c_str(),
- (int)this->cur_data_key.length());
- rc4.process((unsigned char*)tmp, (int)vlen);
+ RC4 rc4(QUtil::unsigned_char_pointer(this->cur_data_key),
+ this->cur_data_key.length());
+ rc4.process(QUtil::unsigned_char_pointer(tmp), vlen);
val = QPDF_String(std::string(tmp, vlen)).unparse();
delete [] tmp;
}
@@ -1788,7 +1789,7 @@ QPDFWriter::generateID()
0x23, 0x84, 0x62, 0x64,
0x33, 0x83, 0x27, 0x95,
0x00};
- result = (char*)tmp;
+ result = reinterpret_cast<char*>(tmp);
}
else
{
@@ -1799,7 +1800,7 @@ QPDFWriter::generateID()
// the file yet. This scheme should be fine though.
std::string seed;
- seed += QUtil::int_to_string((int)QUtil::get_current_time());
+ seed += QUtil::int_to_string(QUtil::get_current_time());
seed += " QPDF ";
seed += this->filename;
seed += " ";
@@ -1823,7 +1824,8 @@ QPDFWriter::generateID()
m.encodeString(seed.c_str());
MD5::Digest digest;
m.digest(digest);
- result = std::string((char*)digest, sizeof(MD5::Digest));
+ result = std::string(reinterpret_cast<char*>(digest),
+ sizeof(MD5::Digest));
}
// If /ID already exists, follow the spec: use the original first
@@ -1899,9 +1901,8 @@ QPDFWriter::generateObjectStreams()
// This code doesn't do anything with /Extends.
std::vector<int> const& eligible = this->pdf.getCompressibleObjects();
- unsigned int n_object_streams =
- (unsigned int)((eligible.size() + 99) / 100);
- unsigned int n_per = (unsigned int)(eligible.size() / n_object_streams);
+ unsigned int n_object_streams = (eligible.size() + 99) / 100;
+ unsigned int n_per = eligible.size() / n_object_streams;
if (n_per * n_object_streams < eligible.size())
{
++n_per;
@@ -2206,7 +2207,8 @@ QPDFWriter::write()
this->object_stream_to_objects[stream].insert(obj);
this->max_ostream_index =
std::max(this->max_ostream_index,
- (int)this->object_stream_to_objects[stream].size() - 1);
+ static_cast<int>(
+ this->object_stream_to_objects[stream].size()) - 1);
}
if (! this->object_stream_to_objects.empty())
@@ -2553,8 +2555,7 @@ QPDFWriter::writeLinearized()
//
// Second half objects
- int second_half_uncompressed =
- (int)(part7.size() + part8.size() + part9.size());
+ int second_half_uncompressed = part7.size() + part8.size() + part9.size();
int second_half_first_obj = 1;
int after_second_half = 1 + second_half_uncompressed;
this->next_objid = after_second_half;
@@ -2661,7 +2662,7 @@ QPDFWriter::writeLinearized()
{
std::vector<QPDFObjectHandle> const& pages = pdf.getAllPages();
int first_page_object = obj_renumber[pages[0].getObjectID()];
- int npages = (int)pages.size();
+ int npages = pages.size();
writeString(" /Linearized 1 /L ");
writeString(QUtil::int_to_string(file_size + hint_length));
@@ -2821,7 +2822,7 @@ QPDFWriter::writeLinearized()
// If this assertion fails, maybe we didn't have
// enough padding above.
assert(this->pipeline->getCount() ==
- (qpdf_offset_t)(second_xref_end + hint_length));
+ second_xref_end + hint_length);
}
}
else
@@ -2849,7 +2850,7 @@ QPDFWriter::writeLinearized()
activatePipelineStack();
writeHintStream(hint_id);
popPipelineStack(&hint_buffer);
- hint_length = (qpdf_offset_t)hint_buffer->getSize();
+ hint_length = hint_buffer->getSize();
// Restore hint offset
this->xref[hint_id] = QPDFXRefEntry(1, hint_offset, 0);
diff --git a/libqpdf/QPDFXRefEntry.cc b/libqpdf/QPDFXRefEntry.cc
index 847fc8e6..2e458ada 100644
--- a/libqpdf/QPDFXRefEntry.cc
+++ b/libqpdf/QPDFXRefEntry.cc
@@ -46,7 +46,7 @@ QPDFXRefEntry::getObjStreamNumber() const
throw std::logic_error(
"getObjStreamNumber called for xref entry of type != 2");
}
- return (int) this->field1;
+ return this->field1;
}
int
diff --git a/libqpdf/QPDF_Array.cc b/libqpdf/QPDF_Array.cc
index 0c2be92f..00903fa6 100644
--- a/libqpdf/QPDF_Array.cc
+++ b/libqpdf/QPDF_Array.cc
@@ -49,13 +49,13 @@ QPDF_Array::getTypeName() const
int
QPDF_Array::getNItems() const
{
- return (int)this->items.size();
+ return this->items.size();
}
QPDFObjectHandle
QPDF_Array::getItem(int n) const
{
- if ((n < 0) || (n >= (int)this->items.size()))
+ if ((n < 0) || (n >= static_cast<int>(this->items.size())))
{
throw std::logic_error(
"INTERNAL ERROR: bounds error accessing QPDF_Array element");
@@ -87,7 +87,7 @@ void
QPDF_Array::insertItem(int at, QPDFObjectHandle const& item)
{
// As special case, also allow insert beyond the end
- if ((at < 0) || (at > (int)this->items.size()))
+ if ((at < 0) || (at > static_cast<int>(this->items.size())))
{
throw std::logic_error(
"INTERNAL ERROR: bounds error accessing QPDF_Array element");
diff --git a/libqpdf/QPDF_Stream.cc b/libqpdf/QPDF_Stream.cc
index 15024849..6ca88caf 100644
--- a/libqpdf/QPDF_Stream.cc
+++ b/libqpdf/QPDF_Stream.cc
@@ -519,7 +519,7 @@ QPDF_Stream::replaceFilterData(QPDFObjectHandle const& filter,
else
{
this->stream_dict.replaceKey(
- "/Length", QPDFObjectHandle::newInteger((int)length));
+ "/Length", QPDFObjectHandle::newInteger(length));
}
}
diff --git a/libqpdf/QPDF_String.cc b/libqpdf/QPDF_String.cc
index 619adef6..db6fb2f5 100644
--- a/libqpdf/QPDF_String.cc
+++ b/libqpdf/QPDF_String.cc
@@ -140,7 +140,7 @@ QPDF_String::unparse(bool force_binary)
}
else
{
- sprintf(num, "\\%03o", (unsigned char)ch);
+ sprintf(num, "\\%03o", static_cast<unsigned char>(ch));
result += num;
}
break;
@@ -181,8 +181,8 @@ QPDF_String::getUTF8Val() const
// discarded, and a low codepoint not preceded by a high
// codepoint will just get its low 10 bits output.
unsigned short bits =
- (((unsigned char) this->val[i]) << 8) +
- ((unsigned char) this->val[i+1]);
+ (static_cast<unsigned char>(this->val[i]) << 8) +
+ static_cast<unsigned char>(this->val[i+1]);
if ((bits & 0xFC00) == 0xD800)
{
codepoint = 0x10000 + ((bits & 0x3FF) << 10);
@@ -209,7 +209,7 @@ QPDF_String::getUTF8Val() const
{
for (unsigned int i = 0; i < len; ++i)
{
- result += QUtil::toUTF8((unsigned char) this->val[i]);
+ result += QUtil::toUTF8(static_cast<unsigned char>(this->val[i]));
}
}
return result;
diff --git a/libqpdf/QPDF_encryption.cc b/libqpdf/QPDF_encryption.cc
index 60d54b77..c49f4b26 100644
--- a/libqpdf/QPDF_encryption.cc
+++ b/libqpdf/QPDF_encryption.cc
@@ -129,7 +129,8 @@ QPDF::EncryptionData::setV5EncryptionParameters(
static void
pad_or_truncate_password_V4(std::string const& password, char k1[key_bytes])
{
- int password_bytes = std::min(key_bytes, (unsigned int)password.length());
+ int password_bytes = std::min(static_cast<size_t>(key_bytes),
+ password.length());
int pad_bytes = key_bytes - password_bytes;
memcpy(k1, password.c_str(), password_bytes);
memcpy(k1 + password_bytes, padding_string, pad_bytes);
@@ -176,7 +177,8 @@ pad_or_truncate_password_V4(std::string const& password)
static std::string
truncate_password_V5(std::string const& password)
{
- return password.substr(0, std::min((size_t)127, password.length()));
+ return password.substr(
+ 0, std::min(static_cast<size_t>(127), password.length()));
}
static void
@@ -187,7 +189,8 @@ iterate_md5_digest(MD5& md5, MD5::Digest& digest, int iterations)
for (int i = 0; i < iterations; ++i)
{
MD5 m;
- m.encodeDataIncrementally((char*)digest, sizeof(digest));
+ m.encodeDataIncrementally(reinterpret_cast<char*>(digest),
+ sizeof(digest));
m.digest(digest);
}
}
@@ -223,8 +226,8 @@ process_with_aes(std::string const& key,
{
Pl_Buffer buffer("buffer");
Pl_AES_PDF aes("aes", &buffer, encrypt,
- (unsigned char const*)key.c_str(),
- (unsigned int)key.length());
+ QUtil::unsigned_char_pointer(key),
+ key.length());
if (iv)
{
aes.setIV(iv, iv_length);
@@ -236,7 +239,7 @@ process_with_aes(std::string const& key,
aes.disablePadding();
for (unsigned int i = 0; i < repetitions; ++i)
{
- aes.write((unsigned char*)data.c_str(), data.length());
+ aes.write(QUtil::unsigned_char_pointer(data), data.length());
}
aes.finish();
PointerHolder<Buffer> bufp = buffer.getBuffer();
@@ -248,7 +251,7 @@ process_with_aes(std::string const& key,
{
outlength = std::min(outlength, bufp->getSize());
}
- return std::string((char const*)bufp->getBuffer(), outlength);
+ return std::string(reinterpret_cast<char*>(bufp->getBuffer()), outlength);
}
static std::string
@@ -258,9 +261,9 @@ hash_V5(std::string const& password,
QPDF::EncryptionData const& data)
{
Pl_SHA2 hash(256);
- hash.write((unsigned char*)password.c_str(), password.length());
- hash.write((unsigned char*)salt.c_str(), salt.length());
- hash.write((unsigned char*)udata.c_str(), udata.length());
+ hash.write(QUtil::unsigned_char_pointer(password), password.length());
+ hash.write(QUtil::unsigned_char_pointer(salt), salt.length());
+ hash.write(QUtil::unsigned_char_pointer(udata), udata.length());
hash.finish();
std::string K = hash.getRawDigest();
@@ -299,7 +302,7 @@ hash_V5(std::string const& password,
assert(K.length() >= 32);
std::string E = process_with_aes(
K.substr(0, 16), true, K1, 0, 64,
- (unsigned char*)K.substr(16, 16).c_str(), 16);
+ QUtil::unsigned_char_pointer(K.substr(16, 16)), 16);
// E_mod_3 is supposed to be mod 3 of the first 16 bytes
// of E taken as as a (128-bit) big-endian number. Since
@@ -309,22 +312,22 @@ hash_V5(std::string const& password,
int E_mod_3 = 0;
for (unsigned int i = 0; i < 16; ++i)
{
- E_mod_3 += (unsigned char)E[i];
+ E_mod_3 += static_cast<unsigned char>(E[i]);
}
E_mod_3 %= 3;
int next_hash = ((E_mod_3 == 0) ? 256 :
(E_mod_3 == 1) ? 384 :
512);
Pl_SHA2 hash(next_hash);
- hash.write((unsigned char*)E.c_str(), E.length());
+ hash.write(QUtil::unsigned_char_pointer(E), E.length());
hash.finish();
K = hash.getRawDigest();
if (round_number >= 64)
{
- unsigned int ch = (unsigned int)((unsigned char) *(E.rbegin()));
+ unsigned int ch = static_cast<unsigned char>(*(E.rbegin()));
- if (ch <= (unsigned int)(round_number - 32))
+ if (ch <= static_cast<unsigned int>(round_number - 32))
{
done = true;
}
@@ -353,22 +356,22 @@ QPDF::compute_data_key(std::string const& encryption_key,
}
// Append low three bytes of object ID and low two bytes of generation
- result += (char) (objid & 0xff);
- result += (char) ((objid >> 8) & 0xff);
- result += (char) ((objid >> 16) & 0xff);
- result += (char) (generation & 0xff);
- result += (char) ((generation >> 8) & 0xff);
+ result += static_cast<char>(objid & 0xff);
+ result += static_cast<char>((objid >> 8) & 0xff);
+ result += static_cast<char>((objid >> 16) & 0xff);
+ result += static_cast<char>(generation & 0xff);
+ result += static_cast<char>((generation >> 8) & 0xff);
if (use_aes)
{
result += "sAlT";
}
MD5 md5;
- md5.encodeDataIncrementally(result.c_str(), (int)result.length());
+ md5.encodeDataIncrementally(result.c_str(), result.length());
MD5::Digest digest;
md5.digest(digest);
- return std::string((char*) digest,
- std::min(result.length(), (size_t) 16));
+ return std::string(reinterpret_cast<char*>(digest),
+ std::min(result.length(), static_cast<size_t>(16)));
}
std::string
@@ -409,13 +412,13 @@ QPDF::compute_encryption_key_from_password(
md5.encodeDataIncrementally(data.getO().c_str(), key_bytes);
char pbytes[4];
int P = data.getP();
- pbytes[0] = (char) (P & 0xff);
- pbytes[1] = (char) ((P >> 8) & 0xff);
- pbytes[2] = (char) ((P >> 16) & 0xff);
- pbytes[3] = (char) ((P >> 24) & 0xff);
+ pbytes[0] = static_cast<char>(P & 0xff);
+ pbytes[1] = static_cast<char>((P >> 8) & 0xff);
+ pbytes[2] = static_cast<char>((P >> 16) & 0xff);
+ pbytes[3] = static_cast<char>((P >> 24) & 0xff);
md5.encodeDataIncrementally(pbytes, 4);
md5.encodeDataIncrementally(data.getId1().c_str(),
- (int)data.getId1().length());
+ data.getId1().length());
if ((data.getR() >= 4) && (! data.getEncryptMetadata()))
{
char bytes[4];
@@ -424,7 +427,7 @@ QPDF::compute_encryption_key_from_password(
}
MD5::Digest digest;
iterate_md5_digest(md5, digest, ((data.getR() >= 3) ? 50 : 0));
- return std::string((char*)digest, data.getLengthBytes());
+ return std::string(reinterpret_cast<char*>(digest), data.getLengthBytes());
}
static void
@@ -463,7 +466,7 @@ compute_O_value(std::string const& user_password,
char upass[key_bytes];
pad_or_truncate_password_V4(user_password, upass);
- iterate_rc4((unsigned char*) upass, key_bytes,
+ iterate_rc4(QUtil::unsigned_char_pointer(upass), key_bytes,
O_key, data.getLengthBytes(),
(data.getR() >= 3) ? 20 : 1, false);
return std::string(upass, key_bytes);
@@ -479,8 +482,9 @@ compute_U_value_R2(std::string const& user_password,
std::string k1 = QPDF::compute_encryption_key(user_password, data);
char udata[key_bytes];
pad_or_truncate_password_V4("", udata);
- iterate_rc4((unsigned char*) udata, key_bytes,
- (unsigned char*)k1.c_str(), data.getLengthBytes(), 1, false);
+ iterate_rc4(QUtil::unsigned_char_pointer(udata), key_bytes,
+ QUtil::unsigned_char_pointer(k1),
+ data.getLengthBytes(), 1, false);
return std::string(udata, key_bytes);
}
@@ -496,18 +500,19 @@ compute_U_value_R3(std::string const& user_password,
md5.encodeDataIncrementally(
pad_or_truncate_password_V4("").c_str(), key_bytes);
md5.encodeDataIncrementally(data.getId1().c_str(),
- (int)data.getId1().length());
+ data.getId1().length());
MD5::Digest digest;
md5.digest(digest);
iterate_rc4(digest, sizeof(MD5::Digest),
- (unsigned char*) k1.c_str(), data.getLengthBytes(), 20, false);
+ QUtil::unsigned_char_pointer(k1),
+ data.getLengthBytes(), 20, false);
char result[key_bytes];
memcpy(result, digest, sizeof(MD5::Digest));
// pad with arbitrary data -- make it consistent for the sake of
// testing
for (unsigned int i = sizeof(MD5::Digest); i < key_bytes; ++i)
{
- result[i] = (char)((i * i) % 0xff);
+ result[i] = static_cast<char>((i * i) % 0xff);
}
return std::string(result, key_bytes);
}
@@ -572,11 +577,11 @@ check_owner_password_V4(std::string& user_password,
unsigned char key[OU_key_bytes_V4];
compute_O_rc4_key(user_password, owner_password, data, key);
unsigned char O_data[key_bytes];
- memcpy(O_data, (unsigned char*) data.getO().c_str(), key_bytes);
+ memcpy(O_data, QUtil::unsigned_char_pointer(data.getO()), key_bytes);
iterate_rc4(O_data, key_bytes, key, data.getLengthBytes(),
(data.getR() >= 3) ? 20 : 1, true);
std::string new_user_password =
- std::string((char*)O_data, key_bytes);
+ std::string(reinterpret_cast<char*>(O_data), key_bytes);
bool result = false;
if (check_user_password(new_user_password, data))
{
@@ -632,7 +637,8 @@ compute_U_UE_value_V5(std::string const& user_password,
{
// Algorithm 3.8 from the PDF 1.7 extension level 3
char k[16];
- QUtil::initializeWithRandomBytes((unsigned char*) k, sizeof(k));
+ QUtil::initializeWithRandomBytes(
+ QUtil::unsigned_char_pointer(k), sizeof(k));
std::string validation_salt(k, 8);
std::string key_salt(k + 8, 8);
U = hash_V5(user_password, validation_salt, "", data) +
@@ -650,7 +656,8 @@ compute_O_OE_value_V5(std::string const& owner_password,
{
// Algorithm 3.9 from the PDF 1.7 extension level 3
char k[16];
- QUtil::initializeWithRandomBytes((unsigned char*) k, sizeof(k));
+ QUtil::initializeWithRandomBytes(
+ QUtil::unsigned_char_pointer(k), sizeof(k));
std::string validation_salt(k, 8);
std::string key_salt(k + 8, 8);
O = hash_V5(owner_password, validation_salt, U, data) +
@@ -668,7 +675,7 @@ compute_Perms_value_V5_clear(std::string const& encryption_key,
unsigned long long extended_perms = 0xffffffff00000000LL | data.getP();
for (int i = 0; i < 8; ++i)
{
- k[i] = (unsigned char) (extended_perms & 0xff);
+ k[i] = static_cast<unsigned char>(extended_perms & 0xff);
extended_perms >>= 8;
}
k[8] = data.getEncryptMetadata() ? 'T' : 'F';
@@ -685,8 +692,9 @@ compute_Perms_value_V5(std::string const& encryption_key,
// Algorithm 3.10 from the PDF 1.7 extension level 3
unsigned char k[16];
compute_Perms_value_V5_clear(encryption_key, data, k);
- return process_with_aes(encryption_key, true,
- std::string((char const*) k, sizeof(k)));
+ return process_with_aes(
+ encryption_key, true,
+ std::string(reinterpret_cast<char*>(k), sizeof(k)));
}
std::string
@@ -834,7 +842,7 @@ QPDF::initializeEncryption()
int R = encryption_dict.getKey("/R").getIntValue();
std::string O = encryption_dict.getKey("/O").getStringValue();
std::string U = encryption_dict.getKey("/U").getStringValue();
- unsigned int P = (unsigned int) encryption_dict.getKey("/P").getIntValue();
+ unsigned int P = encryption_dict.getKey("/P").getIntValue();
// If supporting new encryption R/V values, remember to update
// error message inside this if statement.
@@ -1084,22 +1092,23 @@ QPDF::decryptString(std::string& str, int objid, int generation)
QTC::TC("qpdf", "QPDF_encryption aes decode string");
Pl_Buffer bufpl("decrypted string");
Pl_AES_PDF pl("aes decrypt string", &bufpl, false,
- (unsigned char const*)key.c_str(),
- (unsigned int)key.length());
- pl.write((unsigned char*)str.c_str(), str.length());
+ QUtil::unsigned_char_pointer(key),
+ key.length());
+ pl.write(QUtil::unsigned_char_pointer(str), str.length());
pl.finish();
PointerHolder<Buffer> buf = bufpl.getBuffer();
- str = std::string((char*)buf->getBuffer(), buf->getSize());
+ str = std::string(reinterpret_cast<char*>(buf->getBuffer()),
+ buf->getSize());
}
else
{
QTC::TC("qpdf", "QPDF_encryption rc4 decode string");
- unsigned int vlen = (int)str.length();
+ unsigned int vlen = str.length();
// Using PointerHolder guarantees that tmp will
// be freed even if rc4.process throws an exception.
PointerHolder<char> tmp(true, QUtil::copy_string(str));
- RC4 rc4((unsigned char const*)key.c_str(), (int)key.length());
- rc4.process((unsigned char*)tmp.getPointer(), vlen);
+ RC4 rc4(QUtil::unsigned_char_pointer(key), key.length());
+ rc4.process(QUtil::unsigned_char_pointer(tmp.getPointer()), vlen);
str = std::string(tmp.getPointer(), vlen);
}
}
@@ -1240,15 +1249,15 @@ QPDF::decryptStream(Pipeline*& pipeline, int objid, int generation,
{
QTC::TC("qpdf", "QPDF_encryption aes decode stream");
pipeline = new Pl_AES_PDF("AES stream decryption", pipeline,
- false, (unsigned char*) key.c_str(),
- (unsigned int) key.length());
+ false, QUtil::unsigned_char_pointer(key),
+ key.length());
}
else
{
QTC::TC("qpdf", "QPDF_encryption rc4 decode stream");
pipeline = new Pl_RC4("RC4 stream decryption", pipeline,
- (unsigned char*) key.c_str(),
- (unsigned int) key.length());
+ QUtil::unsigned_char_pointer(key),
+ key.length());
}
heap.push_back(pipeline);
}
@@ -1285,7 +1294,7 @@ QPDF::compute_encryption_parameters_V5(
id1, encrypt_metadata);
unsigned char k[key_bytes];
QUtil::initializeWithRandomBytes(k, key_bytes);
- encryption_key = std::string((char const*)k, key_bytes);
+ encryption_key = std::string(reinterpret_cast<char*>(k), key_bytes);
compute_U_UE_value_V5(user_password, encryption_key, data, U, UE);
compute_O_OE_value_V5(owner_password, encryption_key, data, U, O, OE);
Perms = compute_Perms_value_V5(encryption_key, data);
diff --git a/libqpdf/QPDF_linearization.cc b/libqpdf/QPDF_linearization.cc
index 65f2b99e..d047ad11 100644
--- a/libqpdf/QPDF_linearization.cc
+++ b/libqpdf/QPDF_linearization.cc
@@ -109,7 +109,7 @@ QPDF::isLinearized()
}
else
{
- p = (char*)memchr(p, '\0', tbuf_size - (p - buf));
+ p = reinterpret_cast<char*>(memchr(p, '\0', tbuf_size - (p - buf)));
assert(p != 0);
while ((p - buf < tbuf_size) && (*p == 0))
{
@@ -136,7 +136,8 @@ QPDF::isLinearized()
}
QPDFObjectHandle linkey = candidate.getKey("/Linearized");
- if (! (linkey.isNumber() && ((int)floor(linkey.getNumericValue()) == 1)))
+ if (! (linkey.isNumber() &&
+ (static_cast<int>(floor(linkey.getNumericValue())) == 1)))
{
return false;
}
@@ -289,7 +290,7 @@ QPDF::readLinearizationData()
PointerHolder<Buffer> hbp = pb.getBuffer();
Buffer* hb = hbp.getPointer();
unsigned char const* h_buf = hb->getBuffer();
- int h_size = (int)hb->getSize();
+ int h_size = hb->getSize();
readHPageOffset(BitStream(h_buf, h_size));
@@ -345,7 +346,7 @@ QPDF::readHintStream(Pipeline& pl, qpdf_offset_t offset, size_t length)
{
QTC::TC("qpdf", "QPDF hint table length direct");
}
- qpdf_offset_t computed_end = offset + (qpdf_offset_t)length;
+ qpdf_offset_t computed_end = offset + length;
if ((computed_end < min_end_offset) ||
(computed_end > max_end_offset))
{
@@ -488,7 +489,7 @@ QPDF::checkLinearizationInternal()
}
// N: number of pages
- int npages = (int)pages.size();
+ int npages = pages.size();
if (p.npages != npages)
{
// Not tested in the test suite
@@ -576,8 +577,8 @@ QPDF::checkLinearizationInternal()
// contain any files with threads.
assert(! this->part6.empty());
- int min_E = -1;
- int max_E = -1;
+ qpdf_offset_t min_E = -1;
+ qpdf_offset_t max_E = -1;
for (std::vector<QPDFObjectHandle>::iterator iter = this->part6.begin();
iter != this->part6.end(); ++iter)
{
@@ -585,8 +586,8 @@ QPDF::checkLinearizationInternal()
// All objects have to have been dereferenced to be classified.
assert(this->obj_cache.count(og) > 0);
ObjCache const& oc = this->obj_cache[og];
- min_E = std::max(min_E, (int)oc.end_before_space);
- max_E = std::max(max_E, (int)oc.end_after_space);
+ min_E = std::max(min_E, oc.end_before_space);
+ max_E = std::max(max_E, oc.end_after_space);
}
if ((p.first_page_end < min_E) || (p.first_page_end > max_E))
{
@@ -632,19 +633,18 @@ QPDF::checkLinearizationInternal()
return result;
}
-int
+qpdf_offset_t
QPDF::maxEnd(ObjUser const& ou)
{
assert(this->obj_user_to_objects.count(ou) > 0);
std::set<ObjGen> const& ogs = this->obj_user_to_objects[ou];
- int end = 0;
+ qpdf_offset_t end = 0;
for (std::set<ObjGen>::const_iterator iter = ogs.begin();
iter != ogs.end(); ++iter)
{
ObjGen const& og = *iter;
assert(this->obj_cache.count(og) > 0);
- end = std::max(
- end, (int)(this->obj_cache[og].end_after_space));
+ end = std::max(end, this->obj_cache[og].end_after_space);
}
return end;
}
@@ -736,7 +736,7 @@ QPDF::checkHPageOffset(std::list<std::string>& errors,
// under a page's /Resources dictionary in with shared objects
// even when they are private.
- unsigned int npages = (unsigned int)pages.size();
+ unsigned int npages = pages.size();
int table_offset = adjusted_offset(
this->page_offset_hints.first_page_offset);
ObjGen first_page_og(pages[0].getObjectID(), pages[0].getGeneration());
@@ -1435,7 +1435,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
pages.push_back(getUncompressedObject(*iter, object_stream_data));
}
}
- unsigned int npages = (unsigned int)pages.size();
+ unsigned int npages = pages.size();
// We will be initializing some values of the computed hint
// tables. Specifically, we can initialize any items that deal
@@ -1505,7 +1505,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
// in garbage values for all the shared object identifiers on the
// first page.
- this->c_page_offset_data.entries[0].nobjects = (int)this->part6.size();
+ this->c_page_offset_data.entries[0].nobjects = this->part6.size();
// Part 7: other pages' private objects
@@ -1657,10 +1657,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
// Make sure we got everything exactly once.
unsigned int num_placed =
- (unsigned int)(this->part4.size() + this->part6.size() +
- this->part7.size() + this->part8.size() +
- this->part9.size());
- unsigned int num_wanted = (unsigned int)this->object_to_obj_users.size();
+ this->part4.size() + this->part6.size() + this->part7.size() +
+ this->part8.size() + this->part9.size();
+ unsigned int num_wanted = this->object_to_obj_users.size();
if (num_placed != num_wanted)
{
throw std::logic_error(
@@ -1684,11 +1683,9 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
// can map from object number only without regards to generation.
std::map<int, int> obj_to_index;
- this->c_shared_object_data.nshared_first_page =
- (unsigned int)this->part6.size();
+ this->c_shared_object_data.nshared_first_page = this->part6.size();
this->c_shared_object_data.nshared_total =
- this->c_shared_object_data.nshared_first_page +
- (unsigned int) this->part8.size();
+ this->c_shared_object_data.nshared_first_page + this->part8.size();
std::vector<CHSharedObjectEntry>& shared =
this->c_shared_object_data.entries;
@@ -1697,7 +1694,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
{
QPDFObjectHandle& oh = *iter;
int obj = oh.getObjectID();
- obj_to_index[obj] = (int)shared.size();
+ obj_to_index[obj] = shared.size();
shared.push_back(CHSharedObjectEntry(obj));
}
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)
{
QPDFObjectHandle& oh = *iter;
int obj = oh.getObjectID();
- obj_to_index[obj] = (int)shared.size();
+ obj_to_index[obj] = shared.size();
shared.push_back(CHSharedObjectEntry(obj));
}
}
- assert(this->c_shared_object_data.nshared_total ==
- (int) this->c_shared_object_data.entries.size());
+ assert(static_cast<size_t>(this->c_shared_object_data.nshared_total) ==
+ this->c_shared_object_data.entries.size());
// Now compute the list of shared objects for each page after the
// first page.
@@ -1827,7 +1824,7 @@ QPDF::calculateHPageOffset(
// values.
std::vector<QPDFObjectHandle> const& pages = getAllPages();
- unsigned int npages = (unsigned int)pages.size();
+ unsigned int npages = pages.size();
CHPageOffset& cph = this->c_page_offset_data;
std::vector<CHPageOffsetEntry>& cphe = cph.entries;
@@ -2032,7 +2029,7 @@ QPDF::writeHPageOffset(BitWriter& w)
w.writeBits(t.nbits_shared_numerator, 16); // 12
w.writeBits(t.shared_denominator, 16); // 13
- unsigned int nitems = (unsigned int)getAllPages().size();
+ unsigned int nitems = getAllPages().size();
std::vector<HPageOffsetEntry>& entries = t.entries;
write_vector_int(w, nitems, entries,
@@ -2123,12 +2120,12 @@ QPDF::generateHintStream(std::map<int, QPDFXRefEntry> const& xref,
BitWriter w(&c);
writeHPageOffset(w);
- S = (int)c.getCount();
+ S = c.getCount();
writeHSharedObject(w);
O = 0;
if (this->outline_hints.nobjects > 0)
{
- O = (int)c.getCount();
+ O = c.getCount();
writeHGeneric(w, this->outline_hints);
}
c.finish();
diff --git a/libqpdf/QPDF_optimization.cc b/libqpdf/QPDF_optimization.cc
index f832a883..befa871e 100644
--- a/libqpdf/QPDF_optimization.cc
+++ b/libqpdf/QPDF_optimization.cc
@@ -73,7 +73,7 @@ QPDF::optimize(std::map<int, int> const& object_stream_data,
pushInheritedAttributesToPage(allow_changes, false);
// Traverse pages
- int n = (int)this->all_pages.size();
+ int n = this->all_pages.size();
for (int pageno = 0; pageno < n; ++pageno)
{
updateObjectMaps(ObjUser(ObjUser::ou_page, pageno),
diff --git a/libqpdf/QPDF_pages.cc b/libqpdf/QPDF_pages.cc
index 36ca951d..11f57dd9 100644
--- a/libqpdf/QPDF_pages.cc
+++ b/libqpdf/QPDF_pages.cc
@@ -110,7 +110,7 @@ QPDF::flattenPagesTree()
QPDFObjectHandle pages = getRoot().getKey("/Pages");
- int const len = (int)this->all_pages.size();
+ int const len = this->all_pages.size();
for (int pos = 0; pos < len; ++pos)
{
// populate pageobj_to_pages_pos and fix parent pointer
@@ -175,25 +175,26 @@ QPDF::insertPage(QPDFObjectHandle newpage, int pos)
QTC::TC("qpdf", "QPDF insert page",
(pos == 0) ? 0 : // insert at beginning
- (pos == ((int)this->all_pages.size())) ? 1 : // insert at end
+ (pos == static_cast<int>(this->all_pages.size())) ? 1 : // at end
2); // insert in middle
QPDFObjectHandle pages = getRoot().getKey("/Pages");
QPDFObjectHandle kids = pages.getKey("/Kids");
- assert ((pos >= 0) && (pos <= (int)this->all_pages.size()));
+ assert ((pos >= 0) &&
+ (static_cast<size_t>(pos) <= this->all_pages.size()));
newpage.replaceKey("/Parent", pages);
kids.insertItem(pos, newpage);
int npages = kids.getArrayNItems();
pages.replaceKey("/Count", QPDFObjectHandle::newInteger(npages));
this->all_pages.insert(this->all_pages.begin() + pos, newpage);
- assert((int)this->all_pages.size() == npages);
+ assert(this->all_pages.size() == static_cast<size_t>(npages));
for (int i = pos + 1; i < npages; ++i)
{
insertPageobjToPage(this->all_pages[i], i, false);
}
insertPageobjToPage(newpage, pos, true);
- assert((int)this->pageobj_to_pages_pos.size() == npages);
+ assert(this->pageobj_to_pages_pos.size() == static_cast<size_t>(npages));
}
void
@@ -201,9 +202,9 @@ QPDF::removePage(QPDFObjectHandle page)
{
int pos = findPage(page); // also ensures flat /Pages
QTC::TC("qpdf", "QPDF remove page",
- (pos == 0) ? 0 : // remove at beginning
- (pos == ((int)this->all_pages.size() - 1)) ? 1 : // remove at end
- 2); // remove in middle
+ (pos == 0) ? 0 : // remove at beginning
+ (pos == static_cast<int>(this->all_pages.size() - 1)) ? 1 : // end
+ 2); // remove in middle
QPDFObjectHandle pages = getRoot().getKey("/Pages");
QPDFObjectHandle kids = pages.getKey("/Kids");
@@ -212,10 +213,10 @@ QPDF::removePage(QPDFObjectHandle page)
int npages = kids.getArrayNItems();
pages.replaceKey("/Count", QPDFObjectHandle::newInteger(npages));
this->all_pages.erase(this->all_pages.begin() + pos);
- assert((int)this->all_pages.size() == npages);
+ assert(this->all_pages.size() == static_cast<size_t>(npages));
this->pageobj_to_pages_pos.erase(
ObjGen(page.getObjectID(), page.getGeneration()));
- assert((int)this->pageobj_to_pages_pos.size() == npages);
+ assert(this->pageobj_to_pages_pos.size() == static_cast<size_t>(npages));
for (int i = pos; i < npages; ++i)
{
insertPageobjToPage(this->all_pages[i], i, false);
diff --git a/libqpdf/QUtil.cc b/libqpdf/QUtil.cc
index faccaee7..9549bfa1 100644
--- a/libqpdf/QUtil.cc
+++ b/libqpdf/QUtil.cc
@@ -26,7 +26,7 @@ QUtil::int_to_string(long long num, int fullpad)
char t[50];
// -2 or -1 to leave space for the possible negative sign and for NUL...
- if (abs(fullpad) > (int)sizeof(t) - ((num < 0)?2:1))
+ if (abs(fullpad) > sizeof(t) - ((num < 0)?2:1))
{
throw std::logic_error("Util::int_to_string has been called with "
"a padding value greater than its internal "
@@ -58,7 +58,7 @@ QUtil::double_to_string(double num, int decimal_places)
// 99 digits.
char t[100];
- std::string lhs = int_to_string((int)num);
+ std::string lhs = int_to_string(static_cast<int>(num));
// lhs.length() gives us the length of the part on the right hand
// 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)
// If decimal_places <= 0, it is as if no precision was provided
// so trust the buffer is big enough. The following test will
// always pass in those cases.
- if (decimal_places + 1 + (int)lhs.length() > (int)sizeof(t) - 1)
+ if (decimal_places + 1 + static_cast<int>(lhs.length()) >
+ static_cast<int>(sizeof(t)) - 1)
{
throw std::logic_error("Util::double_to_string has been called with "
"a number and a decimal places specification "
@@ -96,6 +97,18 @@ QUtil::string_to_ll(char const* str)
#endif
}
+unsigned char*
+QUtil::unsigned_char_pointer(std::string const& str)
+{
+ return reinterpret_cast<unsigned char*>(const_cast<char*>(str.c_str()));
+}
+
+unsigned char*
+QUtil::unsigned_char_pointer(char const* str)
+{
+ return reinterpret_cast<unsigned char*>(const_cast<char*>(str));
+}
+
void
QUtil::throw_system_error(std::string const& description)
{
@@ -126,14 +139,14 @@ int
QUtil::seek(FILE* stream, qpdf_offset_t offset, int whence)
{
#if HAVE_FSEEKO
- return fseeko(stream, (off_t)offset, whence);
+ return fseeko(stream, static_cast<off_t>(offset), whence);
#elif HAVE_FSEEKO64
return fseeko64(stream, offset, whence);
#else
# ifdef _MSC_VER
return _fseeki64(stream, offset, whence);
# else
- return fseek(stream, (long)offset, whence);
+ return fseek(stream, static_cast<long>(offset), whence);
# endif
#endif
}
@@ -142,14 +155,14 @@ qpdf_offset_t
QUtil::tell(FILE* stream)
{
#if HAVE_FSEEKO
- return (qpdf_offset_t)ftello(stream);
+ return static_cast<qpdf_offset_t>(ftello(stream));
#elif HAVE_FSEEKO64
- return (qpdf_offset_t)ftello64(stream);
+ return static_cast<qpdf_offset_t>(ftello64(stream));
#else
# ifdef _MSC_VER
return _ftelli64(stream);
# else
- return (qpdf_offset_t)ftell(stream);
+ return static_cast<qpdf_offset_t>(ftell(stream));
# endif
#endif
}
@@ -174,7 +187,7 @@ QUtil::hex_encode(std::string const& input)
buf[hex_size - 1] = '\0';
for (unsigned int i = 0; i < input_size; ++i)
{
- sprintf(buf + i * 2, "%02x", (unsigned char)input[i]);
+ sprintf(buf + i * 2, "%02x", static_cast<unsigned char>(input[i]));
}
return buf;
}
@@ -199,7 +212,7 @@ void
QUtil::setLineBuf(FILE* f)
{
#ifndef _WIN32
- setvbuf(f, (char *) NULL, _IOLBF, 0);
+ setvbuf(f, reinterpret_cast<char *>(NULL), _IOLBF, 0);
#endif
}
@@ -314,7 +327,7 @@ QUtil::toUTF8(unsigned long uval)
}
else if (uval < 128)
{
- result += (char)(uval);
+ result += static_cast<char>(uval);
}
else
{
@@ -329,7 +342,7 @@ QUtil::toUTF8(unsigned long uval)
{
// Assign low six bits plus 10000000 to lowest unused
// byte position, then shift
- *cur_byte = (unsigned char) (0x80 + (uval & 0x3f));
+ *cur_byte = static_cast<unsigned char>(0x80 + (uval & 0x3f));
uval >>= 6;
// Maximum that will fit in high byte now shrinks by one bit
maxval >>= 1;
@@ -342,9 +355,10 @@ QUtil::toUTF8(unsigned long uval)
}
// If maxval is k bits long, the high (7 - k) bits of the
// resulting byte must be high.
- *cur_byte = (unsigned char)((0xff - (1 + (maxval << 1))) + uval);
+ *cur_byte = static_cast<unsigned char>(
+ (0xff - (1 + (maxval << 1))) + uval);
- result += (char*)cur_byte;
+ result += reinterpret_cast<char*>(cur_byte);
}
return result;
@@ -358,8 +372,8 @@ QUtil::random()
{
// Seed the random number generator with something simple, but
// just to be interesting, don't use the unmodified current
- // time....
- QUtil::srandom((int)QUtil::get_current_time() ^ 0xcccc);
+ // time. It would be better if this were a more secure seed.
+ QUtil::srandom(QUtil::get_current_time() ^ 0xcccc);
seeded_random = true;
}
@@ -385,6 +399,6 @@ QUtil::initializeWithRandomBytes(unsigned char* data, size_t len)
{
for (size_t i = 0; i < len; ++i)
{
- data[i] = (unsigned char)((QUtil::random() & 0xff0) >> 4);
+ data[i] = static_cast<unsigned char>((QUtil::random() & 0xff0) >> 4);
}
}
diff --git a/libqpdf/RC4.cc b/libqpdf/RC4.cc
index b992937f..7639a364 100644
--- a/libqpdf/RC4.cc
+++ b/libqpdf/RC4.cc
@@ -15,7 +15,7 @@ RC4::RC4(unsigned char const* key_data, int key_len)
{
if (key_len == -1)
{
- key_len = (int)strlen((char*)key_data);
+ key_len = strlen(reinterpret_cast<char const*>(key_data));
}
for (int i = 0; i < 256; ++i)
diff --git a/libqpdf/rijndael.cc b/libqpdf/rijndael.cc
index 64748d82..7f711df7 100644
--- a/libqpdf/rijndael.cc
+++ b/libqpdf/rijndael.cc
@@ -693,15 +693,17 @@ static const u32 rcon[] =
/* for 128-bit blocks, Rijndael never uses more than 10 rcon values */
};
-#define GETU32(plaintext) (((u32)(plaintext)[0] << 24) ^ \
- ((u32)(plaintext)[1] << 16) ^ \
- ((u32)(plaintext)[2] << 8) ^ \
- ((u32)(plaintext)[3]))
+#define GETU32(plaintext) \
+ ((static_cast<u32>((plaintext)[0]) << 24) ^ \
+ (static_cast<u32>((plaintext)[1]) << 16) ^ \
+ (static_cast<u32>((plaintext)[2]) << 8) ^ \
+ (static_cast<u32>((plaintext)[3])))
-#define PUTU32(ciphertext, st) { (ciphertext)[0] = (u8)((st) >> 24); \
- (ciphertext)[1] = (u8)((st) >> 16); \
- (ciphertext)[2] = (u8)((st) >> 8); \
- (ciphertext)[3] = (u8)(st); }
+#define PUTU32(ciphertext, st) { \
+ (ciphertext)[0] = static_cast<u8>((st) >> 24); \
+ (ciphertext)[1] = static_cast<u8>((st) >> 16); \
+ (ciphertext)[2] = static_cast<u8>((st) >> 8); \
+ (ciphertext)[3] = static_cast<u8>(st); }
/**
* Expand the cipher key into the encryption key schedule.