Fixed /w4 warnings.

This commit is contained in:
Leonardo Zide 2019-05-18 11:33:27 -07:00
parent ec720a6c04
commit 602dfeb8b6
16 changed files with 88 additions and 96 deletions

View file

@ -120,11 +120,11 @@ public:
mGrow = Grow;
}
void AllocGrow(int Grow)
void AllocGrow(size_t Grow)
{
if ((mLength + Grow) > mAlloc)
{
int NewSize = ((mLength + Grow + mGrow - 1) / mGrow) * mGrow;
size_t NewSize = ((mLength + Grow + mGrow - 1) / mGrow) * mGrow;
T* NewData = new T[NewSize];
for (int i = 0; i < mLength; i++)
@ -263,7 +263,7 @@ public:
protected:
T* mData;
int mLength;
int mAlloc;
size_t mAlloc;
int mGrow;
};

View file

@ -19,7 +19,7 @@ lcMemFile::~lcMemFile()
Close();
}
void lcMemFile::Seek(long Offset, int From)
void lcMemFile::Seek(qint64 Offset, int From)
{
if (From == SEEK_SET)
mPosition = Offset;

View file

@ -19,7 +19,7 @@ public:
}
virtual long GetPosition() const = 0;
virtual void Seek(long Offset, int From) = 0;
virtual void Seek(qint64 Offset, int From) = 0;
virtual size_t GetLength() const = 0;
virtual void Close() = 0;
@ -457,7 +457,7 @@ public:
virtual ~lcMemFile();
long GetPosition() const override;
void Seek(long Offset, int From) override;
void Seek(qint64 Offset, int From) override;
void SetLength(size_t NewLength);
size_t GetLength() const override;
@ -503,7 +503,7 @@ public:
return mFile.pos();
}
void Seek(long Offset, int From) override
void Seek(qint64 Offset, int From) override
{
switch (From)
{

View file

@ -18,8 +18,7 @@ void lcHttpReply::run()
HINTERNET Session = nullptr;
HINTERNET Request = nullptr;
if (sizeof(wchar_t) != sizeof(QChar))
return;
static_assert(sizeof(wchar_t) == sizeof(QChar), "Character size mismatch");
Session = InternetOpen(L"LeoCAD", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (!Session)

View file

@ -783,7 +783,7 @@ void lcPiecesLibrary::ReadDirectoryDescriptions(const QFileInfoList (&FileLists)
ProgressDialog->setWindowFlags(ProgressDialog->windowFlags() & ~Qt::WindowCloseButtonHint);
ProgressDialog->setWindowTitle(tr("Initializing"));
ProgressDialog->setLabelText(tr("Loading Parts Library"));
ProgressDialog->setMaximum(mPieces.size());
ProgressDialog->setMaximum((int)mPieces.size());
ProgressDialog->setMinimum(0);
ProgressDialog->setValue(0);
ProgressDialog->setCancelButton(nullptr);
@ -814,11 +814,11 @@ void lcPiecesLibrary::ReadDirectoryDescriptions(const QFileInfoList (&FileLists)
if (Modified)
{
lcMemFile IndexFile;
lcMemFile NewIndexFile;
IndexFile.WriteQString(mLibraryDir.absolutePath());
NewIndexFile.WriteQString(mLibraryDir.absolutePath());
IndexFile.WriteU32(mPieces.size());
NewIndexFile.WriteU32((quint32)mPieces.size());
std::vector<PieceInfo*> SortedPieces;
SortedPieces.reserve(mPieces.size());
@ -834,14 +834,14 @@ void lcPiecesLibrary::ReadDirectoryDescriptions(const QFileInfoList (&FileLists)
for (const PieceInfo* Info : SortedPieces)
{
if (IndexFile.WriteBuffer(Info->mFileName, strlen(Info->mFileName) + 1) == 0)
if (NewIndexFile.WriteBuffer(Info->mFileName, strlen(Info->mFileName) + 1) == 0)
return;
if (IndexFile.WriteBuffer(Info->m_strDescription, strlen(Info->m_strDescription) + 1) == 0)
if (NewIndexFile.WriteBuffer(Info->m_strDescription, strlen(Info->m_strDescription) + 1) == 0)
return;
IndexFile.WriteU32(Info->mFlags);
IndexFile.WriteU8(Info->mFolderType);
NewIndexFile.WriteU32(Info->mFlags);
NewIndexFile.WriteU8(Info->mFolderType);
#if (QT_VERSION >= QT_VERSION_CHECK(4, 7, 0))
quint64 FileTime = FileLists[Info->mFolderType][Info->mFolderIndex].lastModified().toMSecsSinceEpoch();
@ -849,10 +849,10 @@ void lcPiecesLibrary::ReadDirectoryDescriptions(const QFileInfoList (&FileLists)
quint64 FileTime = FileLists[Info->mFolderType][Info->mFolderIndex].lastModified().toTime_t();
#endif
IndexFile.WriteU64(FileTime);
NewIndexFile.WriteU64(FileTime);
}
WriteDirectoryCacheFile(IndexFileName, IndexFile);
WriteDirectoryCacheFile(IndexFileName, NewIndexFile);
}
}
@ -1062,7 +1062,7 @@ bool lcPiecesLibrary::WriteDirectoryCacheFile(const QString& FileName, lcMemFile
if (File.write((char*)&UncompressedSize, sizeof(UncompressedSize)) == -1)
return false;
File.write(qCompress(CacheFile.mBuffer, CacheFile.GetLength()));
File.write(qCompress(CacheFile.mBuffer, (int)CacheFile.GetLength()));
return true;
}
@ -1100,7 +1100,7 @@ bool lcPiecesLibrary::SaveArchiveCacheIndex(const QString& FileName)
{
lcMemFile IndexFile;
quint32 NumFiles = mPieces.size();
quint32 NumFiles = (quint32)mPieces.size();
if (IndexFile.WriteBuffer((char*)&NumFiles, sizeof(NumFiles)) == 0)
return false;

View file

@ -1192,8 +1192,8 @@ void lcMainWindow::SetSelectionMode(lcSelectionMode SelectionMode)
QByteArray lcMainWindow::GetTabLayout()
{
QByteArray TabLayout;
QDataStream DataStream(&TabLayout, QIODevice::WriteOnly);
QByteArray TabLayoutData;
QDataStream DataStream(&TabLayoutData, QIODevice::WriteOnly);
DataStream << (quint32)LC_TAB_LAYOUT_VERSION;
qint32 NumTabs = mModelTabWidget->count();
@ -1249,7 +1249,7 @@ QByteArray lcMainWindow::GetTabLayout()
SaveWidget(TabLayout->itemAt(0)->widget());
}
return TabLayout;
return TabLayoutData;
}
void lcMainWindow::RestoreTabLayout(const QByteArray& TabLayout)

View file

@ -179,18 +179,18 @@ bool lcMouseShortcuts::Save(QStringList& Shortcuts)
return true;
}
bool lcMouseShortcuts::Load(const QStringList& Shortcuts)
bool lcMouseShortcuts::Load(const QStringList& FullShortcuts)
{
memset(mShortcuts, 0, sizeof(mShortcuts));
for (const QString& Shortcut : Shortcuts)
for (const QString& FullShortcut : FullShortcuts)
{
int Equals = Shortcut.indexOf('=');
int Equals = FullShortcut.indexOf('=');
if (Equals == -1)
continue;
QString Key = Shortcut.left(Equals);
QString Key = FullShortcut.left(Equals);
int ToolIdx;
for (ToolIdx = 0; ToolIdx < LC_NUM_TOOLS; ToolIdx++)
@ -200,7 +200,7 @@ bool lcMouseShortcuts::Load(const QStringList& Shortcuts)
if (ToolIdx == LC_NUM_TOOLS)
continue;
QStringList Shortcuts = Shortcut.mid(Equals + 1).split(',');
QStringList Shortcuts = FullShortcut.mid(Equals + 1).split(',');
bool AddedShortcut = false;
for (const QString& Shortcut : Shortcuts)

View file

@ -18,6 +18,8 @@ lcStringCache::~lcStringCache()
void lcStringCache::AddRef(lcContext* Context)
{
Q_UNUSED(Context);
mRefCount++;
if (mRefCount == 1)

View file

@ -328,11 +328,11 @@ std::bitset<6> lcViewSphere::GetIntersectionFlags(lcVector3& Intersection) const
{
for (int Axis1Idx = 0; Axis1Idx < 6; Axis1Idx++)
{
lcVector3 Point(0.0f, 0.0f, 0.0f);
lcVector3 Point1(0.0f, 0.0f, 0.0f);
Point[Axis1Idx / 2] = Axis1Idx % 2 ? -1.0f : 1.0f;
Point1[Axis1Idx / 2] = Axis1Idx % 2 ? -1.0f : 1.0f;
if (lcLengthSquared(Point - Intersection) < mHighlightRadius * mHighlightRadius)
if (lcLengthSquared(Point1 - Intersection) < mHighlightRadius * mHighlightRadius)
{
IntersectionFlags.set(Axis1Idx);
return;
@ -343,11 +343,11 @@ std::bitset<6> lcViewSphere::GetIntersectionFlags(lcVector3& Intersection) const
if (Axis1Idx / 2 == Axis2Idx / 2)
continue;
lcVector3 Point(0.0f, 0.0f, 0.0f);
Point[Axis1Idx / 2] = Axis1Idx % 2 ? -0.70710678118f : 0.70710678118f;
Point[Axis2Idx / 2] = Axis2Idx % 2 ? -0.70710678118f : 0.70710678118f;
lcVector3 Point2(0.0f, 0.0f, 0.0f);
Point2[Axis1Idx / 2] = Axis1Idx % 2 ? -0.70710678118f : 0.70710678118f;
Point2[Axis2Idx / 2] = Axis2Idx % 2 ? -0.70710678118f : 0.70710678118f;
if (lcLengthSquared(Point - Intersection) < mHighlightRadius * mHighlightRadius)
if (lcLengthSquared(Point2 - Intersection) < mHighlightRadius * mHighlightRadius)
{
IntersectionFlags.set(Axis1Idx);
IntersectionFlags.set(Axis2Idx);
@ -359,12 +359,12 @@ std::bitset<6> lcViewSphere::GetIntersectionFlags(lcVector3& Intersection) const
if (Axis1Idx / 2 == Axis3Idx / 2 || Axis2Idx / 2 == Axis3Idx / 2)
continue;
lcVector3 Point(0.0f, 0.0f, 0.0f);
Point[Axis1Idx / 2] = Axis1Idx % 2 ? -0.57735026919f : 0.57735026919f;
Point[Axis2Idx / 2] = Axis2Idx % 2 ? -0.57735026919f : 0.57735026919f;
Point[Axis3Idx / 2] = Axis3Idx % 2 ? -0.57735026919f : 0.57735026919f;
lcVector3 Point3(0.0f, 0.0f, 0.0f);
Point3[Axis1Idx / 2] = Axis1Idx % 2 ? -0.57735026919f : 0.57735026919f;
Point3[Axis2Idx / 2] = Axis2Idx % 2 ? -0.57735026919f : 0.57735026919f;
Point3[Axis3Idx / 2] = Axis3Idx % 2 ? -0.57735026919f : 0.57735026919f;
if (lcLengthSquared(Point - Intersection) < mHighlightRadius * mHighlightRadius)
if (lcLengthSquared(Point3 - Intersection) < mHighlightRadius * mHighlightRadius)
{
IntersectionFlags.set(Axis1Idx);
IntersectionFlags.set(Axis2Idx);

View file

@ -93,7 +93,7 @@ quint64 lcZipFile::SearchCentralDir()
ReadPos = SizeFile - BackRead;
ReadSize = ((CommentBufferSize + 4) < (SizeFile - ReadPos)) ? (CommentBufferSize + 4) : (SizeFile - ReadPos);
mFile->Seek((long)ReadPos, SEEK_SET);
mFile->Seek(ReadPos, SEEK_SET);
if (mFile->ReadBuffer(buf, (long)ReadSize) != ReadSize)
break;
@ -136,7 +136,7 @@ quint64 lcZipFile::SearchCentralDir64()
ReadPos = SizeFile - BackRead;
ReadSize = ((CommentBufferSize + 4) < (SizeFile - ReadPos)) ? (CommentBufferSize + 4) : (SizeFile - ReadPos);
mFile->Seek((long)ReadPos, SEEK_SET);
mFile->Seek(ReadPos, SEEK_SET);
if (mFile->ReadBuffer(buf, (long)ReadSize) != ReadSize)
break;
@ -157,7 +157,7 @@ quint64 lcZipFile::SearchCentralDir64()
if (PosFound == 0)
return 0;
mFile->Seek((long)PosFound, SEEK_SET);
mFile->Seek(PosFound, SEEK_SET);
quint32 Number;
quint64 RelativeOffset;
@ -185,7 +185,7 @@ quint64 lcZipFile::SearchCentralDir64()
return 0;
// Go to end of central directory record.
mFile->Seek((long)RelativeOffset, SEEK_SET);
mFile->Seek(RelativeOffset, SEEK_SET);
// The signature.
if (mFile->ReadU32(&Number, 1) != 1)
@ -208,7 +208,7 @@ bool lcZipFile::CheckFileCoherencyHeader(int FileIndex, quint32* SizeVar, quint6
*OffsetLocalExtraField = 0;
*SizeLocalExtraField = 0;
mFile->Seek((long)(FileInfo.offset_curfile + mBytesBeforeZipFile), SEEK_SET);
mFile->Seek(FileInfo.offset_curfile + mBytesBeforeZipFile, SEEK_SET);
if (mFile->ReadU32(&Magic, 1) != 1 || Magic != 0x04034b50)
return false;
@ -266,7 +266,7 @@ bool lcZipFile::Open()
mZip64 = true;
// Skip signature, size and versions.
mFile->Seek((long)CentralPos + 4 + 8 + 2 + 2, SEEK_SET);
mFile->Seek(CentralPos + 4 + 8 + 2 + 2, SEEK_SET);
// Number of this disk.
if (mFile->ReadU32(&NumberDisk, 1) != 1)
@ -310,7 +310,7 @@ bool lcZipFile::Open()
mZip64 = false;
// Skip signature.
mFile->Seek((long)CentralPos + 4, SEEK_SET);
mFile->Seek(CentralPos + 4, SEEK_SET);
// Number of this disk.
if (mFile->ReadU16(&NumberDisk, 1) != 1)
@ -361,7 +361,7 @@ bool lcZipFile::ReadCentralDir()
{
quint64 PosInCentralDir = mCentralDirOffset;
mFile->Seek((long)(PosInCentralDir + mBytesBeforeZipFile), SEEK_SET);
mFile->Seek(PosInCentralDir + mBytesBeforeZipFile, SEEK_SET);
mFiles.AllocGrow((int)mNumEntries);
for (quint64 FileNum = 0; FileNum < mNumEntries; FileNum++)
@ -636,6 +636,7 @@ bool lcZipFile::ExtractFile(int FileIndex, lcMemFile& File, quint32 MaxLength)
File.SetLength(Length);
File.Seek(0, SEEK_SET);
Stream.next_in = (Bytef*)ReadBuffer;
Stream.next_out = (Bytef*)File.mBuffer;
Stream.avail_out = Length;
@ -653,7 +654,7 @@ bool lcZipFile::ExtractFile(int FileIndex, lcMemFile& File, quint32 MaxLength)
if (ReadThis == 0)
return false;
mFile->Seek((long)(PosInZipfile + mBytesBeforeZipFile), SEEK_SET);
mFile->Seek(PosInZipfile + mBytesBeforeZipFile, SEEK_SET);
if (mFile->ReadBuffer(ReadBuffer, ReadThis) != ReadThis)
return false;

View file

@ -596,17 +596,17 @@ void lcPiece::DrawInterface(lcContext* Context, const lcScene& Scene) const
float Verts[8 * 3];
float* CurVert = Verts;
lcVector3 Min(-LC_PIECE_CONTROL_POINT_SIZE, -LC_PIECE_CONTROL_POINT_SIZE, -LC_PIECE_CONTROL_POINT_SIZE);
lcVector3 Max(LC_PIECE_CONTROL_POINT_SIZE, LC_PIECE_CONTROL_POINT_SIZE, LC_PIECE_CONTROL_POINT_SIZE);
lcVector3 CubeMin(-LC_PIECE_CONTROL_POINT_SIZE, -LC_PIECE_CONTROL_POINT_SIZE, -LC_PIECE_CONTROL_POINT_SIZE);
lcVector3 CubeMax(LC_PIECE_CONTROL_POINT_SIZE, LC_PIECE_CONTROL_POINT_SIZE, LC_PIECE_CONTROL_POINT_SIZE);
*CurVert++ = Min[0]; *CurVert++ = Min[1]; *CurVert++ = Min[2];
*CurVert++ = Min[0]; *CurVert++ = Max[1]; *CurVert++ = Min[2];
*CurVert++ = Max[0]; *CurVert++ = Max[1]; *CurVert++ = Min[2];
*CurVert++ = Max[0]; *CurVert++ = Min[1]; *CurVert++ = Min[2];
*CurVert++ = Min[0]; *CurVert++ = Min[1]; *CurVert++ = Max[2];
*CurVert++ = Min[0]; *CurVert++ = Max[1]; *CurVert++ = Max[2];
*CurVert++ = Max[0]; *CurVert++ = Max[1]; *CurVert++ = Max[2];
*CurVert++ = Max[0]; *CurVert++ = Min[1]; *CurVert++ = Max[2];
*CurVert++ = CubeMin[0]; *CurVert++ = CubeMin[1]; *CurVert++ = CubeMin[2];
*CurVert++ = CubeMin[0]; *CurVert++ = CubeMax[1]; *CurVert++ = CubeMin[2];
*CurVert++ = CubeMax[0]; *CurVert++ = CubeMax[1]; *CurVert++ = CubeMin[2];
*CurVert++ = CubeMax[0]; *CurVert++ = CubeMin[1]; *CurVert++ = CubeMin[2];
*CurVert++ = CubeMin[0]; *CurVert++ = CubeMin[1]; *CurVert++ = CubeMax[2];
*CurVert++ = CubeMin[0]; *CurVert++ = CubeMax[1]; *CurVert++ = CubeMax[2];
*CurVert++ = CubeMax[0]; *CurVert++ = CubeMax[1]; *CurVert++ = CubeMax[2];
*CurVert++ = CubeMax[0]; *CurVert++ = CubeMin[1]; *CurVert++ = CubeMax[2];
const GLushort Indices[36] =
{

View file

@ -192,11 +192,11 @@ QString Project::GetNewModelName(QWidget* ParentWidget, const QString& DialogTit
for (int ModelIdx = 0; ModelIdx < ExistingModels.size(); ModelIdx++)
{
const QString& Name = ExistingModels[ModelIdx];
const QString& ExistingName = ExistingModels[ModelIdx];
if (Name.startsWith(Prefix))
if (ExistingName.startsWith(Prefix))
{
QString NumberString = Name.mid(Prefix.length());
QString NumberString = ExistingName.mid(Prefix.length());
QTextStream Stream(&NumberString);
int Number;
Stream >> Number;
@ -552,18 +552,13 @@ bool Project::ImportLDD(const QString& FileName)
Model->SetSaved();
}
else
delete Model;
if (mModels.IsEmpty())
return false;
if (mModels.GetSize() == 1)
{
lcModel* Model = mModels[0];
delete Model;
return false;
}
if (Model->GetProperties().mName.isEmpty())
Model->SetName(QFileInfo(FileName).completeBaseName());
}
for (int ModelIdx = 0; ModelIdx < mModels.GetSize(); ModelIdx++)
mModels[ModelIdx]->CreatePieceInfo(this);
@ -593,18 +588,13 @@ bool Project::ImportInventory(const QByteArray& Inventory, const QString& Name,
Model->SetSaved();
}
else
delete Model;
if (mModels.IsEmpty())
return false;
if (mModels.GetSize() == 1)
{
lcModel* Model = mModels[0];
delete Model;
return false;
}
Model->SetName(Name);
Model->SetDescription(Description);
}
for (int ModelIdx = 0; ModelIdx < mModels.GetSize(); ModelIdx++)
mModels[ModelIdx]->CreatePieceInfo(this);
@ -1670,10 +1660,10 @@ QImage Project::CreatePartsListImage(lcModel* Model, lcStep Step)
CurrentHeight += NextHeightIncrease;
}
QImage Image(MaxWidth + 40, CurrentHeight + 40, QImage::Format_ARGB32);
Image.fill(QColor(255, 255, 255, 0));
QImage PainterImage(MaxWidth + 40, CurrentHeight + 40, QImage::Format_ARGB32);
PainterImage.fill(QColor(255, 255, 255, 0));
QPainter Painter(&Image);
QPainter Painter(&PainterImage);
Painter.setFont(Font);
for (lcPartsListImage& Image : Images)
@ -1685,7 +1675,7 @@ QImage Project::CreatePartsListImage(lcModel* Model, lcStep Step)
Painter.end();
return Image;
return PainterImage;
}
void Project::CreateHTMLPieceList(QTextStream& Stream, lcModel* Model, lcStep Step, bool Images)

View file

@ -690,7 +690,7 @@ lcArray<lcObject*> View::FindObjectsInBox(float x1, float y1, float x2, float y2
lcVector3(Right, Bottom, 1)
}};
UnprojectPoints(Corners.data(), Corners.size());
UnprojectPoints(Corners.data(), (int)Corners.size());
lcModel* ActiveModel = GetActiveModel();

View file

@ -22,6 +22,7 @@ win32 {
}
win32-msvc* {
QMAKE_CXXFLAGS_WARN_ON += -wd4100
QMAKE_CXXFLAGS *= /MP /W4
PRECOMPILED_HEADER = common/lc_global.h
DEFINES += _CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_DEPRECATE=1 _CRT_NONSTDC_NO_WARNINGS=1
greaterThan(QT_MAJOR_VERSION, 4) {

View file

@ -71,7 +71,7 @@ lcQPropertiesDialog::lcQPropertiesDialog(QWidget *parent, void *data) :
QTableWidget *table = ui->partsTable;
table->setColumnCount(NumColors + 2);
table->setRowCount(PartsList.size() + 1);
table->setRowCount((int)PartsList.size() + 1);
table->setHorizontalHeaderLabels(horizontalLabels);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
@ -80,8 +80,8 @@ lcQPropertiesDialog::lcQPropertiesDialog(QWidget *parent, void *data) :
table->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
#endif
QVector<int> InfoTotals(PartsList.size());
QVector<int> ColorTotals(NumColors);
std::vector<int> InfoTotals(PartsList.size());
std::vector<int> ColorTotals(NumColors);
int Row = 0, Total = 0;
for (const auto& PartIt : PartsList)
@ -105,7 +105,7 @@ lcQPropertiesDialog::lcQPropertiesDialog(QWidget *parent, void *data) :
Row++;
}
table->setItem(InfoTotals.size(), 0, new QTableWidgetItem(tr("Total")));
table->setItem((int)InfoTotals.size(), 0, new QTableWidgetItem(tr("Total")));
for (Row = 0; Row < InfoTotals.size(); Row++)
{
@ -118,12 +118,12 @@ lcQPropertiesDialog::lcQPropertiesDialog(QWidget *parent, void *data) :
{
QTableWidgetItem *item = new QTableWidgetItem(QString::number(ColorTotals[colorIdx]));
item->setTextAlignment(Qt::AlignCenter);
table->setItem(InfoTotals.size(), colorIdx + 1, item);
table->setItem((int)InfoTotals.size(), colorIdx + 1, item);
}
QTableWidgetItem *item = new QTableWidgetItem(QString::number(Total));
item->setTextAlignment(Qt::AlignCenter);
table->setItem(InfoTotals.size(), NumColors + 1, item);
table->setItem((int)InfoTotals.size(), NumColors + 1, item);
}
lcQPropertiesDialog::~lcQPropertiesDialog()

View file

@ -5,12 +5,11 @@
char* strcasestr(const char *s, const char *find)
{
char c, sc;
size_t len;
if ((c = *find++) != 0)
{
c = tolower((unsigned char)c);
len = strlen(find);
int len = (int)strlen(find);
do
{
do