Skip to content

Commit cb57a17

Browse files
committed
clean up C Casts
1 parent eb03909 commit cb57a17

File tree

11 files changed

+52
-52
lines changed

11 files changed

+52
-52
lines changed

src/formats/Lgp.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ bool Lgp::openHeader()
400400

401401
qint32 fileCount;
402402

403-
if (archiveIO()->read((char *)&fileCount, 4) != 4) {
403+
if (archiveIO()->read(reinterpret_cast<char *>(&fileCount), 4) != 4) {
404404
setError(ReadError);
405405
return false;
406406
}
@@ -456,7 +456,7 @@ bool Lgp::openHeader()
456456
// Open conflicts
457457
quint16 conflictCount;
458458

459-
if (archiveIO()->read((char *)&conflictCount, 2) != 2) {
459+
if (archiveIO()->read(reinterpret_cast<char *>(&conflictCount), 2) != 2) {
460460
setError(ReadError);
461461
return false;
462462
}
@@ -465,7 +465,7 @@ bool Lgp::openHeader()
465465
quint16 conflictEntryCount;
466466

467467
// Open conflict entries
468-
if (archiveIO()->read((char *)&conflictEntryCount, 2) != 2) {
468+
if (archiveIO()->read(reinterpret_cast<char *>(&conflictEntryCount), 2) != 2) {
469469
setError(ReadError);
470470
return false;
471471
}
@@ -612,7 +612,7 @@ bool Lgp::pack(const QString &destination, ArchiveObserver *observer)
612612
}
613613

614614
// Writes the file count
615-
if (temp.write((char *)&nbFiles, 4) != 4) {
615+
if (temp.write(reinterpret_cast<const char *>(&nbFiles), 4) != 4) {
616616
temp.remove();
617617
setError(WriteError, temp.errorString());
618618
return false;
@@ -699,15 +699,15 @@ bool Lgp::pack(const QString &destination, ArchiveObserver *observer)
699699
// Write conflicts
700700
QByteArray conflictsData;
701701
const quint16 conflictCount = quint16(conflicts.size());
702-
conflictsData.append((char *)&conflictCount, 2);
702+
conflictsData.append(reinterpret_cast<const char *>(&conflictCount), 2);
703703

704704
for (const QList<LgpConflictEntry> &conflict : conflicts) {
705705
const quint16 conflictEntryCount = quint16(conflict.size());
706-
conflictsData.append((char *)&conflictEntryCount, 2);
706+
conflictsData.append(reinterpret_cast<const char *>(&conflictEntryCount), 2);
707707

708708
for (const LgpConflictEntry &conflictEntry : conflict) {
709709
conflictsData.append(conflictEntry.fileDir.toLatin1().leftJustified(128, '\0', true));
710-
conflictsData.append((char *)&conflictEntry.tocIndex, 2);
710+
conflictsData.append(reinterpret_cast<const char *>(&conflictEntry.tocIndex), 2);
711711
}
712712
}
713713

@@ -772,7 +772,7 @@ bool Lgp::pack(const QString &destination, ArchiveObserver *observer)
772772
}
773773
io->close();
774774
const qint64 size = data.size();
775-
if (temp.write((char *)&size, 4) != 4) {
775+
if (temp.write(reinterpret_cast<const char *>(&size), 4) != 4) {
776776
temp.remove();
777777
setError(WriteError, temp.errorString());
778778
return false;
@@ -810,10 +810,10 @@ bool Lgp::pack(const QString &destination, ArchiveObserver *observer)
810810
for (const LgpHeaderEntry *headerEntry : std::as_const(entries)) {
811811
tocData.append(headerEntry->fileName().toLower().toLatin1().leftJustified(20, '\0', true));
812812
quint32 filePos = headerEntry->filePosition();
813-
tocData.append((char *)&filePos, 4);
813+
tocData.append(reinterpret_cast<const char *>(&filePos), 4);
814814
tocData.append('\x0e');
815815
quint16 conflict = tocEntries.value(headerEntry).conflict;
816-
tocData.append((char *)&conflict, 2);
816+
tocData.append(reinterpret_cast<const char *>(&conflict), 2);
817817
}
818818
}
819819

src/formats/Lgp_p.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ QIODevice *LgpHeaderEntry::createFile(QIODevice *lgp)
142142
}
143143

144144
quint32 size;
145-
if (lgp->read((char *)&size, 4) != 4) {
145+
if (lgp->read(reinterpret_cast<char *>(&size), 4) != 4) {
146146
return nullptr;
147147
}
148148

src/formats/TblFile.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ QByteArray TblFile::save() const
3030
for (const TblFileEntry &entry : _entries) {
3131
for (int i = 0; i < 2; ++i) {
3232
const WorldToField &wm2Field = entry.wm2Field[i];
33-
data.append((const char *)&wm2Field.x, 2);
34-
data.append((const char *)&wm2Field.y, 2);
35-
data.append((const char *)&wm2Field.z, 2);
36-
data.append((const char *)&wm2Field.fieldId, 2);
33+
data.append(reinterpret_cast<const char *>(&wm2Field.x), 2);
34+
data.append(reinterpret_cast<const char *>(&wm2Field.y), 2);
35+
data.append(reinterpret_cast<const char *>(&wm2Field.z), 2);
36+
data.append(reinterpret_cast<const char *>(&wm2Field.fieldId), 2);
3737
data.append(char(wm2Field.dir));
3838
data.append(char(wm2Field.dir)); // padding
3939
data.append(char(wm2Field.dir)); // padding

src/formats/TexFile.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void TexFile::updateHeader()
112112
bool TexFile::save(QByteArray &data)
113113
{
114114
updateHeader();
115-
data.append((char *)&header, header.version==2 ? sizeof(TexStruct) : sizeof(TexStruct) - 4);
115+
data.append(reinterpret_cast<const char *>(&header), header.version==2 ? sizeof(TexStruct) : sizeof(TexStruct) - 4);
116116
if (isPaletted()) {
117117
quint32 palID;
118118
for (palID=0; palID < header.nbPalettes && palID < (quint32)_colorTables.size(); ++palID) {
@@ -127,7 +127,7 @@ bool TexFile::save(QByteArray &data)
127127
}
128128
for ( ; colorID < header.nbColorsPerPalette1; ++colorID) {
129129
const QRgb color = qRgba(0, 0, 0, 0);
130-
data.append((char *)&color, 4);
130+
data.append(reinterpret_cast<const char *>(&color), 4);
131131
}
132132
}
133133
for (int y=0; y<_image.height(); ++y) {
@@ -139,7 +139,7 @@ bool TexFile::save(QByteArray &data)
139139
QRgb *pixels = reinterpret_cast<QRgb *>(_image.bits());
140140
for (int i=0; i<_image.width()*_image.height(); ++i) {
141141
quint16 color = PsColor::toPsColor(pixels[i]);
142-
data.append((char *)&color, 2);
142+
data.append(reinterpret_cast<const char *>(&color), 2);
143143
}
144144
}
145145
return true;

src/formats/TimFile.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -201,16 +201,16 @@ bool TimFile::save(QByteArray &data) const
201201

202202
// Header
203203
data.append("\x10\x00\x00\x00", 4);
204-
data.append((char *)&flag, 4);
204+
data.append(reinterpret_cast<const char *>(&flag), 4);
205205

206206
if (hasPal) {
207207
quint16 colorPerPal = bpp == 0 ? 16 : 256;
208208
quint32 sizePalSection = 12 + quint32(_colorTables.size()) * colorPerPal * 2;
209-
data.append((char *)&sizePalSection, 4);
210-
data.append((char *)&palX, 2);
211-
data.append((char *)&palY, 2);
212-
data.append((char *)&palW, 2);
213-
data.append((char *)&palH, 2);
209+
data.append(reinterpret_cast<const char *>(&sizePalSection), 4);
210+
data.append(reinterpret_cast<const char *>(&palX), 2);
211+
data.append(reinterpret_cast<const char *>(palY), 2);
212+
data.append(reinterpret_cast<const char *>(&palW), 2);
213+
data.append(reinterpret_cast<const char *>(&palH), 2);
214214
int colorTableId = 0;
215215
for (const QList<QRgb> &colorTable : _colorTables) {
216216
const QBitArray &alphaBit = _alphaBits.at(colorTableId);
@@ -220,7 +220,7 @@ bool TimFile::save(QByteArray &data) const
220220
for (i=0; i<colorTable.size() && i<colorPerPal; ++i) {
221221
quint16 psColor = PsColor::toPsColor(colorTable.at(i));
222222
psColor = setPsColorAlphaBit(psColor, alphaBit.at(i));
223-
data.append((char *)&psColor, 2);
223+
data.append(reinterpret_cast<const char *>(&psColor), 2);
224224
}
225225
if (i<colorPerPal)
226226
data.append(QByteArray(colorPerPal - i, '\0'));
@@ -232,11 +232,11 @@ bool TimFile::save(QByteArray &data) const
232232
width/=4;
233233
else
234234
width/=2;
235-
data.append((char *)&sizeImgSection, 4);
236-
data.append((char *)&imgX, 2);
237-
data.append((char *)&imgY, 2);
238-
data.append((char *)&width, 2);
239-
data.append((char *)&height, 2);
235+
data.append(reinterpret_cast<const char *>(&sizeImgSection), 4);
236+
data.append(reinterpret_cast<const char *>(&imgX), 2);
237+
data.append(reinterpret_cast<const char *>(&imgY), 2);
238+
data.append(reinterpret_cast<const char *>(width), 2);
239+
data.append(reinterpret_cast<const char *>(&height), 2);
240240
width *= 2;
241241
for (int y=0; y<height; ++y) {
242242
for (int x=0; x<width; ++x) {
@@ -251,21 +251,21 @@ bool TimFile::save(QByteArray &data) const
251251
} else {
252252
quint16 width = quint16(_image.width()), height = quint16(_image.height());
253253
const QBitArray &alphaBit = _alphaBits.first();
254-
data.append((char *)&sizeImgSection, 4);
255-
data.append((char *)&imgX, 2);
256-
data.append((char *)&imgY, 2);
257-
data.append((char *)&width, 2);
258-
data.append((char *)&height, 2);
254+
data.append(reinterpret_cast<const char *>(&sizeImgSection), 4);
255+
data.append(reinterpret_cast<const char *>(&imgX), 2);
256+
data.append(reinterpret_cast<const char *>(&imgY), 2);
257+
data.append(reinterpret_cast<const char *>(&width), 2);
258+
data.append(reinterpret_cast<const char *>(&height), 2);
259259
for (int y=0; y<height; ++y) {
260260
for (int x=0; x<width; ++x) {
261261
if (bpp == 2) {
262262
quint16 color = PsColor::toPsColor(_image.pixel(x, y));
263263
setPsColorAlphaBit(color, alphaBit.at(y * width + x));
264-
data.append((char *)&color, 2);
264+
data.append(reinterpret_cast<const char *>(&color), 2);
265265
} else {
266266
QRgb c = _image.pixel(x, y);
267267
qint32 color = ((qRed(c) & 0xFF) << 16) | ((qGreen(c) & 0xFF) << 8) | (qBlue(c) & 0xFF);
268-
data.append((char *)&color, 3);
268+
data.append(reinterpret_cast<const char *>(&color), 3);
269269
}
270270
}
271271
}

src/formats/WindowBinFile.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ void WindowBinFile::saveSection(const QByteArray &section, QByteArray &data, qui
7878
QByteArray compressedData = GZIP::compress(section, 8);
7979
compressedData[9] = '\x03'; // Force OS = Unix
8080
quint16 size = compressedData.size();
81-
data.append((char *)&size, 2);
81+
data.append(reinterpret_cast<const char *>(&size), 2);
8282
size = section.size();
83-
data.append((char *)&size, 2);
84-
data.append((char *)&type, 2);
83+
data.append(reinterpret_cast<const char *>(&size), 2);
84+
data.append(reinterpret_cast<const char *>(&type), 2);
8585
data.append(compressedData);
8686
}
8787

src/utils/GZIP.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ QByteArray GZIP::decompressNoHeader(const char *data, int size)
8181
#if (ZLIB_VERNUM < 0x1280)
8282
err = z_uncompress(buffer, &destLen, reinterpret_cast<const Bytef *>(data), size);
8383
#else
84-
err = uncompress(buffer, &destLen, (const Bytef *)data, size);
84+
err = uncompress(buffer, &destLen, reinterpret_cast<const Bytef *>(data), size);
8585
#endif
8686
if (Z_MEM_ERROR != err && Z_BUF_ERROR != err) {
8787
break;
@@ -103,7 +103,7 @@ QByteArray GZIP::compressNoHeader(const char *data, int size, int level)
103103
{
104104
QByteArray ret;
105105
ret.resize(size * 2);
106-
Bytef *buffer = (Bytef *)ret.data();
106+
Bytef *buffer = reinterpret_cast<Bytef *>(ret.data());
107107
uLongf destLen = ret.size();
108108
#if (ZLIB_VERNUM < 0x1280)
109109
if (Z_OK != z_compress2(buffer, &destLen, reinterpret_cast<const Bytef *>(data), size, level)) {
@@ -112,7 +112,7 @@ QByteArray GZIP::compressNoHeader(const char *data, int size, int level)
112112
ret.resize(destLen);
113113
}
114114
#else
115-
if (Z_OK != compress2(buffer, &destLen, (const Bytef *)data, size, level)) {
115+
if (Z_OK != compress2(buffer, &destLen, reinterpret_cast<const Bytef *>(data), size, level)) {
116116
ret.clear();
117117
} else {
118118
ret.resize(destLen);
@@ -126,7 +126,7 @@ ulong GZIP::crc(const char *data, int size)
126126
#if (ZLIB_VERNUM < 0x1280)
127127
return z_crc32(z_crc32(0L, nullptr, 0), reinterpret_cast<const Bytef *>(data), size);
128128
#else
129-
return crc32(crc32(0L, nullptr, 0), (const Bytef *)data, size);
129+
return crc32(crc32(0L, nullptr, 0), reinterpret_cast<const Bytef *>(data), size);
130130
#endif
131131
}
132132

src/utils/GZIPPS.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ QByteArray GZIPPS::compress(const char *ungzip, int size, const QByteArray &head
1919
Q_ASSERT(header.size() == 4);
2020

2121
QByteArray ret;
22-
ret.append((char *)&size, 4); // = decSize
22+
ret.append(reinterpret_cast<const char *>(&size), 4); // = decSize
2323
ret.append(header);
2424
return ret.append(GZIP::compress(ungzip, size, level));
2525
}

src/utils/LZS.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ const QByteArray &LZS::decompressAll(const char *data, int fileSize)
8888
{
8989
int sizeAlloc = fileSize * 5;
9090
quint16 curBuff = 4078, offset, firstByte = 0, i, length;
91-
const quint8 *fileData = (const quint8 *)data;
91+
const quint8 *fileData = reinterpret_cast<const quint8 *>(data);
9292
const quint8 *endFileData = fileData + fileSize;
9393

9494
// Internal buffer is still allocated using this method instead of clear
@@ -269,7 +269,7 @@ const QByteArray &LZS::compressWithHeader(const char *data, int sizeData)
269269
{
270270
compress(data, sizeData);
271271
qint32 lzsSize = result.size();
272-
result.prepend((char *)&lzsSize, 4);
272+
result.prepend(reinterpret_cast<const char *>(&lzsSize), 4);
273273

274274
return result;
275275
}
@@ -376,7 +376,7 @@ const QByteArray &LZS::compress(const char *data, int sizeData)
376376
} while (len > 0); // until length of string to be processed is zero
377377

378378
if (code_buf_ptr > 1) { // Send remaining code.
379-
result.replace(curResult, code_buf_ptr, (char *)code_buf, code_buf_ptr);
379+
result.replace(curResult, code_buf_ptr, reinterpret_cast<char *>(code_buf), code_buf_ptr);
380380
curResult += code_buf_ptr;
381381
}
382382
result.truncate(curResult);

src/utils/PsfFile.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ QByteArray PsfFile::save() const
130130
QByteArray compressedData = GZIP::compressNoHeader(_data.constData(), int(_data.size()));
131131

132132
quint32 specialSize = quint32(_special.size());
133-
data.append((char *)&specialSize, 4);
133+
data.append(reinterpret_cast<const char *>(&specialSize), 4);
134134
quint32 dataSize = quint32(compressedData.size());
135-
data.append((char *)&dataSize, 4);
135+
data.append(reinterpret_cast<const char *>(&dataSize), 4);
136136
quint32 crc = GZIP::crc(compressedData.constData(), int(compressedData.size()));
137-
data.append((char *)&crc, 4);
137+
data.append(reinterpret_cast<const char *>(crc), 4);
138138

139139
data.append(_special);
140140
data.append(compressedData);

0 commit comments

Comments
 (0)