Static analysis fixes.

This commit is contained in:
Leonardo Zide 2017-04-02 17:15:09 -07:00
parent b9726a2a99
commit c34810c084
10 changed files with 48 additions and 26 deletions

View file

@ -126,18 +126,21 @@ void Image::Resize(int width, int height)
{
bits = (unsigned char*)malloc(BufferSize);
for (j = 0; j < mHeight; j++)
if (bits)
{
accumy = (float)height*j/(float)mHeight;
sty = (int)floor(accumy);
for (i = 0; i < mWidth; i++)
for (j = 0; j < mHeight; j++)
{
accumx = (float)width*i/(float)mWidth;
stx = (int)floor(accumx);
accumy = (float)height*j / (float)mHeight;
sty = (int)floor(accumy);
for (k = 0; k < components; k++)
bits[(stx+sty*width)*components+k] = mData[(i+j*mWidth)*components+k];
for (i = 0; i < mWidth; i++)
{
accumx = (float)width*i / (float)mWidth;
stx = (int)floor(accumx);
for (k = 0; k < components; k++)
bits[(stx + sty*width)*components + k] = mData[(i + j * mWidth) * components + k];
}
}
}
}

View file

@ -77,12 +77,22 @@ public:
return true;
}
T* begin() const
T* begin()
{
return &mData[0];
}
T* end() const
T* end()
{
return &mData[0] + mLength;
}
const T* begin() const
{
return &mData[0];
}
const T* end() const
{
return &mData[0] + mLength;
}

View file

@ -269,7 +269,8 @@ bool lcLoadColorFile(lcFile& File)
Token[0] = ' ';
int Value;
sscanf(Token, "%x", &Value);
if (sscanf(Token, "%x", &Value) != 1)
Value = 0;
Color.Value[2] = (float)(Value & 0xff) / 255.0f;
Value >>= 8;
@ -284,7 +285,8 @@ bool lcLoadColorFile(lcFile& File)
Token[0] = ' ';
int Value;
sscanf(Token, "%x", &Value);
if (sscanf(Token, "%x", &Value) != 1)
Value = 0;
Color.Edge[2] = (float)(Value & 0xff) / 255.0f;
Value >>= 8;

View file

@ -684,7 +684,8 @@ lcVertexBuffer lcContext::CreateVertexBuffer(int Size, const void* Data)
else
{
VertexBuffer.Pointer = malloc(Size);
memcpy(VertexBuffer.Pointer, Data, Size);
if (VertexBuffer.Pointer)
memcpy(VertexBuffer.Pointer, Data, Size);
}
return VertexBuffer;
@ -729,7 +730,8 @@ lcIndexBuffer lcContext::CreateIndexBuffer(int Size, const void* Data)
else
{
IndexBuffer.Pointer = malloc(Size);
memcpy(IndexBuffer.Pointer, Data, Size);
if (IndexBuffer.Pointer)
memcpy(IndexBuffer.Pointer, Data, Size);
}
return IndexBuffer;

View file

@ -123,8 +123,15 @@ void lcMemFile::GrowFile(size_t NewLength)
NewLength = ((NewLength + mGrowBytes - 1) / mGrowBytes) * mGrowBytes;
if (mBuffer != NULL)
mBuffer = (unsigned char*)realloc(mBuffer, NewLength);
if (mBuffer)
{
unsigned char* NewBuffer = (unsigned char*)realloc(mBuffer, NewLength);
if (!NewBuffer)
return;
mBuffer = NewBuffer;
}
else
mBuffer = (unsigned char*)malloc(NewLength);

View file

@ -244,10 +244,7 @@ QVariant lcPartSelectionListModel::data(const QModelIndex& Index, int Role) cons
{
case Qt::DisplayRole:
if (!mIconSize || mShowPartNames)
{
PieceInfo* Info = mParts[InfoIndex].first;
return QVariant(QString::fromLatin1(Info->m_strDescription));
}
break;
case Qt::ToolTipRole:

View file

@ -507,7 +507,7 @@ void lcPiece::DrawInterface(lcContext* Context) const
const lcVector3& Max = BoundingBox.Max;
lcVector3 Edge((Max - Min) * 0.33f);
float Verts[48][3] =
float LineVerts[48][3] =
{
{ Max[0], Max[1], Max[2] }, { Max[0] - Edge[0], Max[1], Max[2] },
{ Max[0], Max[1], Max[2] }, { Max[0], Max[1] - Edge[1], Max[2] },
@ -550,7 +550,7 @@ void lcPiece::DrawInterface(lcContext* Context) const
else
Context->SetInterfaceColor(LC_COLOR_SELECTED);
Context->SetVertexBufferPointer(Verts);
Context->SetVertexBufferPointer(LineVerts);
Context->SetVertexFormatPosition(3);
Context->DrawPrimitives(GL_LINES, 0, 48);

View file

@ -1361,7 +1361,7 @@ void Project::ExportHTML()
for (int ModelIdx = 0; ModelIdx < Models.GetSize(); ModelIdx++)
{
lcModel* Model = Models[ModelIdx];
QString BaseName = ProjectTitle.left(ProjectTitle.length() - QFileInfo(ProjectTitle).suffix().length() - 1) + '-' + Model->GetProperties().mName;
BaseName = ProjectTitle.left(ProjectTitle.length() - QFileInfo(ProjectTitle).suffix().length() - 1) + '-' + Model->GetProperties().mName;
BaseName.replace('#', '_');
if (Options.SinglePage)

View file

@ -952,8 +952,7 @@ void View::DrawRotateOverlay()
// Transform ViewDir to local space.
ViewDir = lcMul(ViewDir, lcMatrix33AffineInverse(RelativeRotation));
lcMatrix44 WorldMatrix = lcMatrix44(RelativeRotation, OverlayCenter);
mContext->SetWorldMatrix(WorldMatrix);
mContext->SetWorldMatrix(lcMatrix44(RelativeRotation, OverlayCenter));
// Draw each axis circle.
for (int i = 0; i < 3; i++)
@ -1316,6 +1315,8 @@ void View::DrawGrid()
VertexBufferSize += 2 * (MaxX - MinX + MaxY - MinY + 2) * 3 * sizeof(float);
float* Verts = (float*)malloc(VertexBufferSize);
if (!Verts)
return;
float* CurVert = Verts;
if (Preferences.mDrawGridStuds)

View file

@ -119,7 +119,7 @@ static void lcRegisterShellFileTypes()
if (RegCreateKeyEx(HKEY_CLASSES_ROOT, TEXT(".lcd\\ShellNew"), 0, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_READ, NULL, &key, &disposition) != ERROR_SUCCESS)
return;
LONG result = RegSetValueEx(key, TEXT("NullFile"), 0, REG_SZ, (CONST BYTE*)TEXT(""), (lstrlen(TEXT("")) + 1) * sizeof(TCHAR));
result = RegSetValueEx(key, TEXT("NullFile"), 0, REG_SZ, (CONST BYTE*)TEXT(""), (lstrlen(TEXT("")) + 1) * sizeof(TCHAR));
if (RegCloseKey(key) != ERROR_SUCCESS || result != ERROR_SUCCESS)
return;