aboutsummaryrefslogtreecommitdiffstats
path: root/libtests
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 /libtests
parentbabb47948a408ebad12c452ba3fdd78782360167 (diff)
downloadqpdf-30027481f7f9e9191f7c8deea51850b7a76b1b1f.tar.zst
Remove all old-style casts from C++ code
Diffstat (limited to 'libtests')
-rw-r--r--libtests/aes.cc4
-rw-r--r--libtests/bits.cc5
-rw-r--r--libtests/buffer.cc22
-rw-r--r--libtests/concatenate.cc6
-rw-r--r--libtests/qutil.cc2
-rw-r--r--libtests/rc4.cc4
-rw-r--r--libtests/sha2.cc2
7 files changed, 26 insertions, 19 deletions
diff --git a/libtests/aes.cc b/libtests/aes.cc
index 381148c1..5535cbb8 100644
--- a/libtests/aes.cc
+++ b/libtests/aes.cc
@@ -86,7 +86,7 @@ int main(int argc, char* argv[])
usage();
}
- unsigned int hexkeylen = (unsigned int)strlen(hexkey);
+ unsigned int hexkeylen = strlen(hexkey);
unsigned int keylen = hexkeylen / 2;
FILE* infile = fopen(infilename, "rb");
@@ -112,7 +112,7 @@ int main(int argc, char* argv[])
t[2] = '\0';
long val = strtol(t, 0, 16);
- key[i/2] = (unsigned char) val;
+ key[i/2] = static_cast<unsigned char>(val);
}
Pl_StdioFile* out = new Pl_StdioFile("stdout", outfile);
diff --git a/libtests/bits.cc b/libtests/bits.cc
index 7837ac68..c14bceb6 100644
--- a/libtests/bits.cc
+++ b/libtests/bits.cc
@@ -37,7 +37,8 @@ test_write_bits(unsigned char& ch, unsigned int& bit_offset, unsigned long val,
int bits, Pl_Buffer* bp)
{
write_bits(ch, bit_offset, val, bits, bp);
- printf("ch = %02x, bit_offset = %d\n", (unsigned int) ch, bit_offset);
+ printf("ch = %02x, bit_offset = %d\n",
+ static_cast<unsigned int>(ch), bit_offset);
}
static void
@@ -49,7 +50,7 @@ print_buffer(Pl_Buffer* bp)
size_t l = b->getSize();
for (unsigned long i = 0; i < l; ++i)
{
- printf("%02x%s", (unsigned int)(p[i]),
+ printf("%02x%s", static_cast<unsigned int>(p[i]),
(i == l - 1) ? "\n" : " ");
}
printf("\n");
diff --git a/libtests/buffer.cc b/libtests/buffer.cc
index 923be197..094a3284 100644
--- a/libtests/buffer.cc
+++ b/libtests/buffer.cc
@@ -1,11 +1,15 @@
#include <qpdf/Pl_Buffer.hh>
#include <qpdf/Pl_Count.hh>
#include <qpdf/Pl_Discard.hh>
+#include <qpdf/QUtil.hh>
#include <stdlib.h>
#include <stdexcept>
#include <iostream>
-typedef unsigned char* uc;
+static unsigned char* uc(char const* s)
+{
+ return QUtil::unsigned_char_pointer(s);
+}
int main()
{
@@ -14,20 +18,20 @@ int main()
Pl_Discard discard;
Pl_Count count("count", &discard);
Pl_Buffer bp1("bp1", &count);
- bp1.write((uc)"12345", 5);
- bp1.write((uc)"67890", 5);
+ bp1.write(uc("12345"), 5);
+ bp1.write(uc("67890"), 5);
bp1.finish();
std::cout << "count: " << count.getCount() << std::endl;
- bp1.write((uc)"abcde", 5);
- bp1.write((uc)"fghij", 6);
+ bp1.write(uc("abcde"), 5);
+ bp1.write(uc("fghij"), 6);
bp1.finish();
std::cout << "count: " << count.getCount() << std::endl;
Buffer* b = bp1.getBuffer();
std::cout << "size: " << b->getSize() << std::endl;
std::cout << "data: " << b->getBuffer() << std::endl;
delete b;
- bp1.write((uc)"qwert", 5);
- bp1.write((uc)"yuiop", 6);
+ bp1.write(uc("qwert"), 5);
+ bp1.write(uc("yuiop"), 6);
bp1.finish();
std::cout << "count: " << count.getCount() << std::endl;
b = bp1.getBuffer();
@@ -36,8 +40,8 @@ int main()
delete b;
Pl_Buffer bp2("bp2");
- bp2.write((uc)"moo", 3);
- bp2.write((uc)"quack", 6);
+ bp2.write(uc("moo"), 3);
+ bp2.write(uc("quack"), 6);
try
{
delete bp2.getBuffer();
diff --git a/libtests/concatenate.cc b/libtests/concatenate.cc
index cf4332cb..41f88eb6 100644
--- a/libtests/concatenate.cc
+++ b/libtests/concatenate.cc
@@ -1,12 +1,13 @@
#include <qpdf/Pl_Concatenate.hh>
#include <qpdf/Pl_Flate.hh>
#include <qpdf/Pl_Buffer.hh>
+#include <qpdf/QUtil.hh>
#include <iostream>
#include <assert.h>
static void pipeStringAndFinish(Pipeline* p, std::string const& str)
{
- p->write((unsigned char*)str.c_str(), str.length());
+ p->write(QUtil::unsigned_char_pointer(str), str.length());
p->finish();
}
@@ -25,7 +26,8 @@ int main(int argc, char* argv[])
inflate.write(b1_buf->getBuffer(), b1_buf->getSize());
inflate.finish();
PointerHolder<Buffer> b2_buf = b2.getBuffer();
- std::string result((char const*)b2_buf->getBuffer(), b2_buf->getSize());
+ std::string result(reinterpret_cast<char*>(b2_buf->getBuffer()),
+ b2_buf->getSize());
if (result == "-one--two-")
{
std::cout << "concatenate test passed" << std::endl;
diff --git a/libtests/qutil.cc b/libtests/qutil.cc
index d1c090fb..ad77f3ea 100644
--- a/libtests/qutil.cc
+++ b/libtests/qutil.cc
@@ -152,7 +152,7 @@ static void print_utf8(unsigned long val)
iter != result.end(); ++iter)
{
char t[3];
- sprintf(t, "%02x", (unsigned char) (*iter));
+ sprintf(t, "%02x", static_cast<unsigned char>(*iter));
std::cout << " " << t;
}
}
diff --git a/libtests/rc4.cc b/libtests/rc4.cc
index 1328fc85..59a9265e 100644
--- a/libtests/rc4.cc
+++ b/libtests/rc4.cc
@@ -17,7 +17,7 @@ int main(int argc, char* argv[])
char* hexkey = argv[1];
char* infilename = argv[2];
char* outfilename = argv[3];
- unsigned int hexkeylen = (unsigned int)strlen(hexkey);
+ unsigned int hexkeylen = strlen(hexkey);
unsigned int keylen = hexkeylen / 2;
unsigned char* key = new unsigned char[keylen + 1];
key[keylen] = '\0';
@@ -37,7 +37,7 @@ int main(int argc, char* argv[])
t[2] = '\0';
long val = strtol(t, 0, 16);
- key[i/2] = (unsigned char) val;
+ key[i/2] = static_cast<unsigned char>(val);
}
FILE* outfile = fopen(outfilename, "wb");
diff --git a/libtests/sha2.cc b/libtests/sha2.cc
index 2b9aac3c..5110b89f 100644
--- a/libtests/sha2.cc
+++ b/libtests/sha2.cc
@@ -8,7 +8,7 @@ static void test(Pl_SHA2& sha2, char const* description, int bits,
char const* input, std::string const& output)
{
sha2.resetBits(bits);
- sha2.write((unsigned char*) input, strlen(input));
+ sha2.write(QUtil::unsigned_char_pointer(input), strlen(input));
sha2.finish();
std::cout << description << ": ";
if (output == sha2.getHexDigest())