Fix some casts/calculations to keep PVS Studio happy

* It identifies some potential overflows which we know likely won't happen, but
  the fixes are harmless.
* Some issues are definitely bad, though not actual bugs.
This commit is contained in:
baldurk
2020-01-21 18:28:56 +00:00
parent baac06ca93
commit 8fa93105f2
17 changed files with 45 additions and 42 deletions
+1 -1
View File
@@ -841,7 +841,7 @@ int RDStyle::styleHint(StyleHint stylehint, const QStyleOption *opt, const QWidg
return QFrame::StyledPanel | QFrame::Plain;
if(stylehint == QStyle::SH_ComboBox_Popup)
return false;
return 0;
if(stylehint == SH_ToolTipLabel_Opacity)
return 255;
+2 -1
View File
@@ -260,7 +260,8 @@ void TimelineBar::layout()
qreal virtualSize = m_dataArea.width() * m_zoom;
while(virtualSize > 0 && (maxEID / m_eidAxisLabelStep) * m_eidAxisLabelWidth > virtualSize)
while(virtualSize > 0 &&
(qreal(maxEID) / qreal(m_eidAxisLabelStep)) * m_eidAxisLabelWidth > virtualSize)
{
// increment 1, 2, 5, 10, 20, 50, 100, ...
if(stepSize == 1)
+4 -6
View File
@@ -414,8 +414,8 @@ void D3D11Replay::RenderMesh(uint32_t eventId, const rdcarray<MeshFormat> &secon
HRESULT hr = S_OK;
UINT strides[] = {sizeof(Vec4f)};
UINT offsets[] = {0};
m_pImmediateContext->IASetVertexBuffers(0, 1, &m_MeshRender.TriHighlightHelper,
(UINT *)&strides, (UINT *)&offsets);
m_pImmediateContext->IASetVertexBuffers(0, 1, &m_MeshRender.TriHighlightHelper, strides,
offsets);
////////////////////////////////////////////////////////////////
// render primitives
@@ -568,8 +568,7 @@ void D3D11Replay::RenderMesh(uint32_t eventId, const rdcarray<MeshFormat> &secon
// we want this to clip
m_pImmediateContext->OMSetDepthStencilState(m_MeshRender.LessEqualDepthState, 0);
m_pImmediateContext->IASetVertexBuffers(0, 1, &m_MeshRender.TriHighlightHelper,
(UINT *)&strides, (UINT *)&offsets);
m_pImmediateContext->IASetVertexBuffers(0, 1, &m_MeshRender.TriHighlightHelper, strides, offsets);
m_pImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST);
m_pImmediateContext->IASetInputLayout(m_MeshRender.GenericLayout);
@@ -591,8 +590,7 @@ void D3D11Replay::RenderMesh(uint32_t eventId, const rdcarray<MeshFormat> &secon
vertexData.ModelViewProj = projMat.Mul(camMat.Mul(guessProjInv));
GetDebugManager()->FillCBuffer(vsCBuf, &vertexData, sizeof(vertexData));
m_pImmediateContext->IASetVertexBuffers(0, 1, &m_MeshRender.FrustumHelper, (UINT *)&strides,
(UINT *)&offsets);
m_pImmediateContext->IASetVertexBuffers(0, 1, &m_MeshRender.FrustumHelper, strides, offsets);
m_pImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST);
m_pImmediateContext->IASetInputLayout(m_MeshRender.GenericLayout);
+4 -4
View File
@@ -60,7 +60,7 @@ void D3D12MarkerRegion::Begin(ID3D12GraphicsCommandList *list, const rdcstr &mar
// display one less character than specified by the size. Append a space to pad the
// output without visibly changing the event marker for other debuggers.
rdcwstr text = StringFormat::UTF82Wide(marker + " ");
UINT size = (UINT)text.length() * sizeof(wchar_t);
UINT size = UINT(text.length() * sizeof(wchar_t));
list->BeginEvent(0, text.c_str(), size);
}
}
@@ -70,7 +70,7 @@ void D3D12MarkerRegion::Begin(ID3D12CommandQueue *queue, const rdcstr &marker)
if(queue)
{
rdcwstr text = StringFormat::UTF82Wide(marker + " ");
UINT size = (UINT)text.length() * sizeof(wchar_t);
UINT size = UINT(text.length() * sizeof(wchar_t));
queue->BeginEvent(0, text.c_str(), size);
}
}
@@ -80,7 +80,7 @@ void D3D12MarkerRegion::Set(ID3D12GraphicsCommandList *list, const rdcstr &marke
if(list)
{
rdcwstr text = StringFormat::UTF82Wide(marker + " ");
UINT size = (UINT)text.length() * sizeof(wchar_t);
UINT size = UINT(text.length() * sizeof(wchar_t));
list->SetMarker(0, text.c_str(), size);
}
}
@@ -90,7 +90,7 @@ void D3D12MarkerRegion::Set(ID3D12CommandQueue *queue, const rdcstr &marker)
if(queue)
{
rdcwstr text = StringFormat::UTF82Wide(marker + " ");
UINT size = (UINT)text.length() * sizeof(wchar_t);
UINT size = UINT(text.length() * sizeof(wchar_t));
queue->SetMarker(0, text.c_str(), size);
}
}
+2 -2
View File
@@ -3383,7 +3383,7 @@ void WrappedID3D12Device::ReplayLog(uint32_t startEventID, uint32_t endEventID,
ID3D12GraphicsCommandList *beginList = GetNewList();
{
rdcwstr text = StringFormat::UTF82Wide(AMDRGPControl::GetBeginMarker());
UINT size = (UINT)text.length() * sizeof(wchar_t);
UINT size = UINT(text.length() * sizeof(wchar_t));
beginList->SetMarker(0, text.c_str(), size);
}
beginList->Close();
@@ -3448,7 +3448,7 @@ void WrappedID3D12Device::ReplayLog(uint32_t startEventID, uint32_t endEventID,
ID3D12GraphicsCommandList *list = GetNewList();
{
rdcwstr text = StringFormat::UTF82Wide(AMDRGPControl::GetEndMarker());
UINT size = (UINT)text.length() * sizeof(wchar_t);
UINT size = UINT(text.length() * sizeof(wchar_t));
list->SetMarker(0, text.c_str(), size);
}
+12 -8
View File
@@ -268,7 +268,7 @@ void GLReplay::InitPostVSBuffers(uint32_t eventId)
{
drv.glShaderBinary(1, &tmpShaders[i], eGL_SHADER_BINARY_FORMAT_SPIR_V,
shadDetails.spirvWords.data(),
(GLsizei)shadDetails.spirvWords.size() * sizeof(uint32_t));
GLsizei(shadDetails.spirvWords.size() * sizeof(uint32_t)));
drv.glSpecializeShader(tmpShaders[i], shadDetails.entryPoint.c_str(),
(GLuint)shadDetails.specIDs.size(),
@@ -1524,15 +1524,17 @@ void GLReplay::InitPostVSBuffers(uint32_t eventId)
{
drv.glDrawElementsInstancedBaseVertexBaseInstance(
drawtopo, drawcall->numIndices, idxType,
(const void *)uintptr_t(drawcall->indexOffset * drawcall->indexByteWidth), inst,
drawcall->baseVertex, drawcall->instanceOffset);
(const void *)(uintptr_t(drawcall->indexOffset) *
uintptr_t(drawcall->indexByteWidth)),
inst, drawcall->baseVertex, drawcall->instanceOffset);
}
else
{
drv.glDrawElementsInstancedBaseVertex(
drawtopo, drawcall->numIndices, idxType,
(const void *)uintptr_t(drawcall->indexOffset * drawcall->indexByteWidth), inst,
drawcall->baseVertex);
(const void *)(uintptr_t(drawcall->indexOffset) *
uintptr_t(drawcall->indexByteWidth)),
inst, drawcall->baseVertex);
}
}
@@ -1565,14 +1567,16 @@ void GLReplay::InitPostVSBuffers(uint32_t eventId)
{
drv.glDrawElementsInstancedBaseVertexBaseInstance(
drawtopo, drawcall->numIndices, idxType,
(const void *)uintptr_t(drawcall->indexOffset * drawcall->indexByteWidth),
(const void *)(uintptr_t(drawcall->indexOffset) *
uintptr_t(drawcall->indexByteWidth)),
drawcall->numInstances, drawcall->baseVertex, drawcall->instanceOffset);
}
else
{
drv.glDrawElementsInstancedBaseVertex(
drawtopo, drawcall->numIndices, idxType,
(const void *)uintptr_t(drawcall->indexOffset * drawcall->indexByteWidth),
(const void *)(uintptr_t(drawcall->indexOffset) *
uintptr_t(drawcall->indexByteWidth)),
drawcall->numInstances, drawcall->baseVertex);
}
}
@@ -1594,7 +1598,7 @@ void GLReplay::InitPostVSBuffers(uint32_t eventId)
{
drv.glDrawElementsBaseVertex(
drawtopo, drawcall->numIndices, idxType,
(const void *)uintptr_t(drawcall->indexOffset * drawcall->indexByteWidth),
(const void *)(uintptr_t(drawcall->indexOffset) * uintptr_t(drawcall->indexByteWidth)),
drawcall->baseVertex);
}
+1 -1
View File
@@ -125,7 +125,7 @@ GLInitParams WGLHook::GetInitParamsForDC(HDC dc)
ret.width = (r.right - r.left);
ret.height = (r.bottom - r.top);
ret.isSRGB = true;
ret.isSRGB = 1;
if(WGL.wglGetPixelFormatAttribivARB)
{
@@ -389,7 +389,7 @@ void IntelCounters::EndSample()
uint32_t calculatedReportCount = 0;
TCompletionCode res = m_subscribedMetricSets[m_passIndex]->CalculateMetrics(
(const unsigned char *)counter_data, metricSetParams->QueryReportSize, m_queryResult.data(),
(uint32_t)m_queryResult.size() * sizeof(TTypedValue_1_0), &calculatedReportCount, false);
uint32_t(m_queryResult.size() * sizeof(TTypedValue_1_0)), &calculatedReportCount, false);
if(res != TCompletionCode::CC_OK)
{
@@ -544,7 +544,7 @@ TEST_CASE("Check LLVM bitreader", "[llvm]")
b.SeekBit(0);
uint32_t read;
INFO("Bit width: " << (i + 1));
INFO("Bit width: " << uint32_t(i + 1));
read = b.fixed<uint32_t>(i + 1);
CHECK(read == expected[i][0]);
@@ -596,7 +596,7 @@ TEST_CASE("Check LLVM bitreader", "[llvm]")
for(size_t i = 2; i <= 8; i++)
{
INFO("VBR group size: " << i);
INFO("VBR group size: " << uint32_t(i));
b.SeekByte(i);
uint64_t val = b.vbr<uint64_t>(i);
@@ -657,7 +657,7 @@ TEST_CASE("Check LLVM bitreader", "[llvm]")
for(size_t i = 2; i <= 8; i++)
{
INFO("VBR group size: " << i);
INFO("VBR group size: " << uint32_t(i));
b.SeekByte(i * 2);
uint64_t val = b.vbr<uint64_t>(i);
@@ -717,7 +717,7 @@ TEST_CASE("Check LLVM bitreader", "[llvm]")
for(size_t i = 2; i <= 8; i++)
{
INFO("VBR group size: " << i);
INFO("VBR group size: " << uint32_t(i));
b.SeekByte(i * 5);
uint64_t val = b.vbr<uint64_t>(i);
+1 -1
View File
@@ -1389,7 +1389,7 @@ void WrappedVulkan::SubmitExtQBarriers(uint32_t queueFamilyIndex,
VkResult vkr = ObjDisp(extQCmd)->BeginCommandBuffer(Unwrap(extQCmd), &beginInfo);
RDCASSERTEQUAL(vkr, VK_SUCCESS);
DoPipelineBarrier(extQCmd, (uint32_t)queueFamilyBarriers.size(), queueFamilyBarriers.data());
DoPipelineBarrier(extQCmd, queueFamilyBarriers.size(), queueFamilyBarriers.data());
vkr = ObjDisp(extQCmd)->EndCommandBuffer(Unwrap(extQCmd));
RDCASSERTEQUAL(vkr, VK_SUCCESS);
+2 -2
View File
@@ -445,7 +445,7 @@ void VulkanResourceManager::SerialiseImageStates(SerialiserType &ser,
if(layouts.subresourceStates.size() > 1 &&
layouts.subresourceStates[0].subresourceRange.aspectMask == VK_IMAGE_ASPECT_COLOR_BIT &&
layouts.subresourceStates.size() == size_t(imageInfo.layerCount * imageInfo.levelCount))
layouts.subresourceStates.size() == size_t(imageInfo.layerCount) * size_t(imageInfo.levelCount))
{
VkImageLayout layout = layouts.subresourceStates[0].newLayout;
@@ -609,7 +609,7 @@ void VulkanResourceManager::InsertDeviceMemoryRefs(WriteSerialiser &ser)
data.push_back({mem, jt->start(), jt->value()});
}
uint32_t sizeEstimate = (uint32_t)data.size() * sizeof(MemRefInterval) + 32;
uint64_t sizeEstimate = data.size() * sizeof(MemRefInterval) + 32;
{
SCOPED_SERIALISE_CHUNK(VulkanChunk::DeviceMemoryRefs, sizeEstimate);
+1 -1
View File
@@ -510,7 +510,7 @@ struct VulkanOcclusionAndStencilCallback : public VulkanPixelHistoryCallback
pipestate.renderPass = GetResID(m_RenderPass);
pipestate.subpass = 0;
pipestate.graphics.pipeline = GetResID(replacements.fixedShaderStencil);
ReplayDraw(cmd, (uint32_t)m_OcclusionQueries.size(), eid, true, true);
ReplayDraw(cmd, m_OcclusionQueries.size(), eid, true, true);
m_OcclusionQueries.insert(
std::pair<uint32_t, uint32_t>(eid, (uint32_t)m_OcclusionQueries.size()));
+2 -2
View File
@@ -2002,13 +2002,13 @@ void VulkanReplay::FetchVSOut(uint32_t eventId)
if(vi->pVertexBindingDescriptions[vb].inputRate == VK_VERTEX_INPUT_RATE_INSTANCE)
{
len = uint64_t(maxInstance + 1) * vi->pVertexBindingDescriptions[vb].stride;
len = (uint64_t(maxInstance) + 1) * vi->pVertexBindingDescriptions[vb].stride;
offs += drawcall->instanceOffset * vi->pVertexBindingDescriptions[vb].stride;
}
else
{
len = uint64_t(maxIndex + 1) * vi->pVertexBindingDescriptions[vb].stride;
len = (uint64_t(maxIndex) + 1) * vi->pVertexBindingDescriptions[vb].stride;
offs += drawcall->vertexOffset * vi->pVertexBindingDescriptions[vb].stride;
}
@@ -2977,8 +2977,8 @@ VkResult WrappedVulkan::vkCreateDevice(VkPhysicalDevice physicalDevice,
{
uint32_t family = createInfo.pQueueCreateInfos[i].queueFamilyIndex;
uint32_t count = createInfo.pQueueCreateInfos[i].queueCount;
m_QueueFamilies.resize(RDCMAX(m_QueueFamilies.size(), size_t(family + 1)));
m_QueueFamilyCounts.resize(RDCMAX(m_QueueFamilies.size(), size_t(family + 1)));
m_QueueFamilies.resize(RDCMAX(m_QueueFamilies.size(), size_t(family) + 1));
m_QueueFamilyCounts.resize(RDCMAX(m_QueueFamilies.size(), size_t(family) + 1));
m_QueueFamilies[family] = new VkQueue[count];
m_QueueFamilyCounts[family] = count;
@@ -47,11 +47,11 @@ VkIndirectPatchData WrappedVulkan::FetchIndirectData(VkIndirectPatchType type,
case VkIndirectPatchType::DispatchIndirect: dataSize = sizeof(VkDispatchIndirectCommand); break;
case VkIndirectPatchType::DrawIndirect:
case VkIndirectPatchType::DrawIndirectCount:
dataSize = sizeof(VkDrawIndirectCommand) + (count > 0 ? count - 1 : 0) * stride;
dataSize = sizeof(VkDrawIndirectCommand) + (count - 1) * stride;
break;
case VkIndirectPatchType::DrawIndexedIndirect:
case VkIndirectPatchType::DrawIndexedIndirectCount:
dataSize = sizeof(VkDrawIndexedIndirectCommand) + (count > 0 ? count - 1 : 0) * stride;
dataSize = sizeof(VkDrawIndexedIndirectCommand) + (count - 1) * stride;
break;
case VkIndirectPatchType::DrawIndirectByteCount: dataSize = 4; break;
}
+1 -1
View File
@@ -819,7 +819,7 @@ rdcpair<ReplayStatus, uint32_t> Process::InjectIntoProcess(
_snwprintf_s(
paramsAlloc, 2047, 2047,
L"\"%ls\" capaltbit --pid=%d --capfile=\"%ls\" --debuglog=\"%ls\" --capopts=\"%hs\"",
L"\"%ls\" capaltbit --pid=%u --capfile=\"%ls\" --debuglog=\"%ls\" --capopts=\"%hs\"",
renderdocPath, pid, wcapturefile.c_str(), wdebugLogfile.c_str(), optstr.c_str());
RDCDEBUG("params %ls", paramsAlloc);
+3 -3
View File
@@ -75,7 +75,7 @@ static DrawcallDescription *SetupDrawcallPointers(rdcarray<DrawcallDescription *
{
{
RDCASSERT(drawcallTable.empty() || draw->eventId > drawcallTable.back()->eventId);
drawcallTable.resize(RDCMAX(drawcallTable.size(), size_t(draw->eventId + 1)));
drawcallTable.resize(RDCMAX(drawcallTable.size(), size_t(draw->eventId) + 1));
drawcallTable[draw->eventId] = draw;
}
@@ -91,7 +91,7 @@ static DrawcallDescription *SetupDrawcallPointers(rdcarray<DrawcallDescription *
RDCASSERT(drawcallTable.empty() || draw->eventId > drawcallTable.back()->eventId ||
(draw->eventId == drawcallTable.back()->eventId &&
(drawcallTable.back()->flags & DrawFlags::PushMarker)));
drawcallTable.resize(RDCMAX(drawcallTable.size(), size_t(draw->eventId + 1)));
drawcallTable.resize(RDCMAX(drawcallTable.size(), size_t(draw->eventId) + 1));
drawcallTable[draw->eventId] = draw;
}
}
@@ -106,7 +106,7 @@ static DrawcallDescription *SetupDrawcallPointers(rdcarray<DrawcallDescription *
RDCASSERT(drawcallTable.empty() || draw->eventId > drawcallTable.back()->eventId ||
(draw->eventId == drawcallTable.back()->eventId &&
(drawcallTable.back()->flags & DrawFlags::PushMarker)));
drawcallTable.resize(RDCMAX(drawcallTable.size(), size_t(draw->eventId + 1)));
drawcallTable.resize(RDCMAX(drawcallTable.size(), size_t(draw->eventId) + 1));
drawcallTable[draw->eventId] = draw;
}