Skip to content

Commit

Permalink
clean up C Casts
Browse files Browse the repository at this point in the history
  • Loading branch information
sithlord48 committed Jan 28, 2024
1 parent 5d7da34 commit ecdf2f6
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 52 deletions.
20 changes: 10 additions & 10 deletions src/formats/Lgp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ bool Lgp::openHeader()

qint32 fileCount;

if (archiveIO()->read((char *)&fileCount, 4) != 4) {
if (archiveIO()->read(reinterpret_cast<char *>(&fileCount), 4) != 4) {
setError(ReadError);
return false;
}
Expand Down Expand Up @@ -456,7 +456,7 @@ bool Lgp::openHeader()
// Open conflicts
quint16 conflictCount;

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

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

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

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

for (const LgpConflictEntry &conflictEntry : conflict) {
conflictsData.append(conflictEntry.fileDir.toLatin1().leftJustified(128, '\0', true));
conflictsData.append((char *)&conflictEntry.tocIndex, 2);
conflictsData.append(reinterpret_cast<const char *>(&conflictEntry.tocIndex), 2);
}
}

Expand Down Expand Up @@ -772,7 +772,7 @@ bool Lgp::pack(const QString &destination, ArchiveObserver *observer)
}
io->close();
const qint64 size = data.size();
if (temp.write((char *)&size, 4) != 4) {
if (temp.write(reinterpret_cast<const char *>(&size), 4) != 4) {
temp.remove();
setError(WriteError, temp.errorString());
return false;
Expand Down Expand Up @@ -810,10 +810,10 @@ bool Lgp::pack(const QString &destination, ArchiveObserver *observer)
for (const LgpHeaderEntry *headerEntry : std::as_const(entries)) {
tocData.append(headerEntry->fileName().toLower().toLatin1().leftJustified(20, '\0', true));
quint32 filePos = headerEntry->filePosition();
tocData.append((char *)&filePos, 4);
tocData.append(reinterpret_cast<const char *>(&filePos), 4);
tocData.append('\x0e');
quint16 conflict = tocEntries.value(headerEntry).conflict;
tocData.append((char *)&conflict, 2);
tocData.append(reinterpret_cast<const char *>(&conflict), 2);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/formats/Lgp_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ QIODevice *LgpHeaderEntry::createFile(QIODevice *lgp)
}

quint32 size;
if (lgp->read((char *)&size, 4) != 4) {
if (lgp->read(reinterpret_cast<char *>(&size), 4) != 4) {
return nullptr;
}

Expand Down
8 changes: 4 additions & 4 deletions src/formats/TblFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ QByteArray TblFile::save() const
for (const TblFileEntry &entry : _entries) {
for (int i = 0; i < 2; ++i) {
const WorldToField &wm2Field = entry.wm2Field[i];
data.append((const char *)&wm2Field.x, 2);
data.append((const char *)&wm2Field.y, 2);
data.append((const char *)&wm2Field.z, 2);
data.append((const char *)&wm2Field.fieldId, 2);
data.append(reinterpret_cast<const char *>(&wm2Field.x), 2);
data.append(reinterpret_cast<const char *>(&wm2Field.y), 2);
data.append(reinterpret_cast<const char *>(&wm2Field.z), 2);
data.append(reinterpret_cast<const char *>(&wm2Field.fieldId), 2);
data.append(char(wm2Field.dir));
data.append(char(wm2Field.dir)); // padding
data.append(char(wm2Field.dir)); // padding
Expand Down
6 changes: 3 additions & 3 deletions src/formats/TexFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void TexFile::updateHeader()
bool TexFile::save(QByteArray &data)
{
updateHeader();
data.append((char *)&header, header.version==2 ? sizeof(TexStruct) : sizeof(TexStruct) - 4);
data.append(reinterpret_cast<const char *>(&header), header.version==2 ? sizeof(TexStruct) : sizeof(TexStruct) - 4);
if (isPaletted()) {
quint32 palID;
for (palID=0; palID < header.nbPalettes && palID < (quint32)_colorTables.size(); ++palID) {
Expand All @@ -127,7 +127,7 @@ bool TexFile::save(QByteArray &data)
}
for ( ; colorID < header.nbColorsPerPalette1; ++colorID) {
const QRgb color = qRgba(0, 0, 0, 0);
data.append((char *)&color, 4);
data.append(reinterpret_cast<const char *>(&color), 4);
}
}
for (int y=0; y<_image.height(); ++y) {
Expand All @@ -139,7 +139,7 @@ bool TexFile::save(QByteArray &data)
QRgb *pixels = reinterpret_cast<QRgb *>(_image.bits());
for (int i=0; i<_image.width()*_image.height(); ++i) {
quint16 color = PsColor::toPsColor(pixels[i]);
data.append((char *)&color, 2);
data.append(reinterpret_cast<const char *>(&color), 2);
}
}
return true;
Expand Down
38 changes: 19 additions & 19 deletions src/formats/TimFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,16 @@ bool TimFile::save(QByteArray &data) const

// Header
data.append("\x10\x00\x00\x00", 4);
data.append((char *)&flag, 4);
data.append(reinterpret_cast<const char *>(&flag), 4);

if (hasPal) {
quint16 colorPerPal = bpp == 0 ? 16 : 256;
quint32 sizePalSection = 12 + quint32(_colorTables.size()) * colorPerPal * 2;
data.append((char *)&sizePalSection, 4);
data.append((char *)&palX, 2);
data.append((char *)&palY, 2);
data.append((char *)&palW, 2);
data.append((char *)&palH, 2);
data.append(reinterpret_cast<const char *>(&sizePalSection), 4);
data.append(reinterpret_cast<const char *>(&palX), 2);
data.append(reinterpret_cast<const char *>(palY), 2);
data.append(reinterpret_cast<const char *>(&palW), 2);
data.append(reinterpret_cast<const char *>(&palH), 2);
int colorTableId = 0;
for (const QList<QRgb> &colorTable : _colorTables) {
const QBitArray &alphaBit = _alphaBits.at(colorTableId);
Expand All @@ -220,7 +220,7 @@ bool TimFile::save(QByteArray &data) const
for (i=0; i<colorTable.size() && i<colorPerPal; ++i) {
quint16 psColor = PsColor::toPsColor(colorTable.at(i));
psColor = setPsColorAlphaBit(psColor, alphaBit.at(i));
data.append((char *)&psColor, 2);
data.append(reinterpret_cast<const char *>(&psColor), 2);
}
if (i<colorPerPal)
data.append(QByteArray(colorPerPal - i, '\0'));
Expand All @@ -232,11 +232,11 @@ bool TimFile::save(QByteArray &data) const
width/=4;
else
width/=2;
data.append((char *)&sizeImgSection, 4);
data.append((char *)&imgX, 2);
data.append((char *)&imgY, 2);
data.append((char *)&width, 2);
data.append((char *)&height, 2);
data.append(reinterpret_cast<const char *>(&sizeImgSection), 4);
data.append(reinterpret_cast<const char *>(&imgX), 2);
data.append(reinterpret_cast<const char *>(&imgY), 2);
data.append(reinterpret_cast<const char *>(width), 2);
data.append(reinterpret_cast<const char *>(&height), 2);
width *= 2;
for (int y=0; y<height; ++y) {
for (int x=0; x<width; ++x) {
Expand All @@ -251,21 +251,21 @@ bool TimFile::save(QByteArray &data) const
} else {
quint16 width = quint16(_image.width()), height = quint16(_image.height());
const QBitArray &alphaBit = _alphaBits.first();
data.append((char *)&sizeImgSection, 4);
data.append((char *)&imgX, 2);
data.append((char *)&imgY, 2);
data.append((char *)&width, 2);
data.append((char *)&height, 2);
data.append(reinterpret_cast<const char *>(&sizeImgSection), 4);
data.append(reinterpret_cast<const char *>(&imgX), 2);
data.append(reinterpret_cast<const char *>(&imgY), 2);
data.append(reinterpret_cast<const char *>(&width), 2);
data.append(reinterpret_cast<const char *>(&height), 2);
for (int y=0; y<height; ++y) {
for (int x=0; x<width; ++x) {
if (bpp == 2) {
quint16 color = PsColor::toPsColor(_image.pixel(x, y));
setPsColorAlphaBit(color, alphaBit.at(y * width + x));
data.append((char *)&color, 2);
data.append(reinterpret_cast<const char *>(&color), 2);
} else {
QRgb c = _image.pixel(x, y);
qint32 color = ((qRed(c) & 0xFF) << 16) | ((qGreen(c) & 0xFF) << 8) | (qBlue(c) & 0xFF);
data.append((char *)&color, 3);
data.append(reinterpret_cast<const char *>(&color), 3);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/formats/WindowBinFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ void WindowBinFile::saveSection(const QByteArray &section, QByteArray &data, qui
QByteArray compressedData = GZIP::compress(section, 8);
compressedData[9] = '\x03'; // Force OS = Unix
quint16 size = compressedData.size();
data.append((char *)&size, 2);
data.append(reinterpret_cast<const char *>(&size), 2);
size = section.size();
data.append((char *)&size, 2);
data.append((char *)&type, 2);
data.append(reinterpret_cast<const char *>(&size), 2);
data.append(reinterpret_cast<const char *>(&type), 2);
data.append(compressedData);
}

Expand Down
8 changes: 4 additions & 4 deletions src/utils/GZIP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ QByteArray GZIP::decompressNoHeader(const char *data, int size)
#if (ZLIB_VERNUM < 0x1280)
err = z_uncompress(buffer, &destLen, reinterpret_cast<const Bytef *>(data), size);
#else
err = uncompress(buffer, &destLen, (const Bytef *)data, size);
err = uncompress(buffer, &destLen, reinterpret_cast<const Bytef *>(data), size);
#endif
if (Z_MEM_ERROR != err && Z_BUF_ERROR != err) {
break;
Expand All @@ -103,7 +103,7 @@ QByteArray GZIP::compressNoHeader(const char *data, int size, int level)
{
QByteArray ret;
ret.resize(size * 2);
Bytef *buffer = (Bytef *)ret.data();
Bytef *buffer = reinterpret_cast<Bytef *>(ret.data());
uLongf destLen = ret.size();
#if (ZLIB_VERNUM < 0x1280)
if (Z_OK != z_compress2(buffer, &destLen, reinterpret_cast<const Bytef *>(data), size, level)) {
Expand All @@ -112,7 +112,7 @@ QByteArray GZIP::compressNoHeader(const char *data, int size, int level)
ret.resize(destLen);
}
#else
if (Z_OK != compress2(buffer, &destLen, (const Bytef *)data, size, level)) {
if (Z_OK != compress2(buffer, &destLen, reinterpret_cast<const Bytef *>(data), size, level)) {
ret.clear();
} else {
ret.resize(destLen);
Expand All @@ -126,7 +126,7 @@ ulong GZIP::crc(const char *data, int size)
#if (ZLIB_VERNUM < 0x1280)
return z_crc32(z_crc32(0L, nullptr, 0), reinterpret_cast<const Bytef *>(data), size);
#else
return crc32(crc32(0L, nullptr, 0), (const Bytef *)data, size);
return crc32(crc32(0L, nullptr, 0), reinterpret_cast<const Bytef *>(data), size);
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/GZIPPS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ QByteArray GZIPPS::compress(const char *ungzip, int size, const QByteArray &head
Q_ASSERT(header.size() == 4);

QByteArray ret;
ret.append((char *)&size, 4); // = decSize
ret.append(reinterpret_cast<const char *>(&size), 4); // = decSize
ret.append(header);
return ret.append(GZIP::compress(ungzip, size, level));
}
6 changes: 3 additions & 3 deletions src/utils/LZS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const QByteArray &LZS::decompressAll(const char *data, int fileSize)
{
int sizeAlloc = fileSize * 5;
quint16 curBuff = 4078, offset, firstByte = 0, i, length;
const quint8 *fileData = (const quint8 *)data;
const quint8 *fileData = reinterpret_cast<const quint8 *>(data);
const quint8 *endFileData = fileData + fileSize;

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

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

if (code_buf_ptr > 1) { // Send remaining code.
result.replace(curResult, code_buf_ptr, (char *)code_buf, code_buf_ptr);
result.replace(curResult, code_buf_ptr, reinterpret_cast<char *>(code_buf), code_buf_ptr);
curResult += code_buf_ptr;
}
result.truncate(curResult);
Expand Down
6 changes: 3 additions & 3 deletions src/utils/PsfFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ QByteArray PsfFile::save() const
QByteArray compressedData = GZIP::compressNoHeader(_data.constData(), int(_data.size()));

quint32 specialSize = quint32(_special.size());
data.append((char *)&specialSize, 4);
data.append(reinterpret_cast<const char *>(&specialSize), 4);
quint32 dataSize = quint32(compressedData.size());
data.append((char *)&dataSize, 4);
data.append(reinterpret_cast<const char *>(&dataSize), 4);
quint32 crc = GZIP::crc(compressedData.constData(), int(compressedData.size()));
data.append((char *)&crc, 4);
data.append(reinterpret_cast<const char *>(crc), 4);

data.append(_special);
data.append(compressedData);
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/common/QTaskBarButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ QTaskBarButton::QTaskBarButton(QObject *parent)
CoInitialize(nullptr);
HRESULT hRes = CoCreateInstance(CLSID_TaskbarList,
nullptr, CLSCTX_INPROC_SERVER,
IID_ITaskbarList3, (LPVOID*)&pITask);
IID_ITaskbarList3, reinterpret_cast<LPVOID*>(&pITask));
if (FAILED(hRes)) {
pITask = 0;
CoUninitialize();
Expand Down

0 comments on commit ecdf2f6

Please sign in to comment.