Add explicit comparisons where we were implicitly checking for non-zero

* This fixes some warnings from PVS Studio, though none of these checks were
  actually wrong it's better to be explicit.
This commit is contained in:
baldurk
2020-01-21 13:45:12 +00:00
parent 421201df7a
commit 68b9d223b0
23 changed files with 42 additions and 45 deletions
+1 -1
View File
@@ -413,7 +413,7 @@ struct LogLine
if(idx + 64 > line.length())
return false;
if(strncmp(&line[idx], "RDOC ", 5))
if(strncmp(&line[idx], "RDOC ", 5) != 0)
return false;
idx += 5;
+1 -1
View File
@@ -63,7 +63,7 @@ Connection::Connection(Network::Socket *sock)
char response[15] = {};
reader.Read(response, handshakeLength);
if(memcmp(handshake, response, 14))
if(memcmp(handshake, response, 14) != 0)
{
RDCERR("handshake failed - received >%s< - expected >%s<", response, handshake);
error = true;
+2 -2
View File
@@ -1995,7 +1995,7 @@ void ReplayProxy::DeltaTransferBytes(SerialiserType &xferser, bytebuf &reference
// if there are still some bytes remaining at the end of the image, smaller than the chunk
// size, just diff directly and send if needed. We could combine this with the last delta if
// we ended in the active state.
if(bytesRemain > 0 && memcmp(src, dst, bytesRemain))
if(bytesRemain > 0 && memcmp(src, dst, bytesRemain) != 0)
{
deltasList.push_back(DeltaSection());
deltasList.back().offs = src - srcBegin;
@@ -2378,7 +2378,7 @@ void ReplayProxy::InitPreviewWindow()
if(data.system != WindowingSystem::Unknown)
{
// if the data has changed, destroy the old window so we'll recreate
if(m_PreviewWindow == 0 || memcmp(&m_PreviewWindowingData, &data, sizeof(data)))
if(m_PreviewWindow == 0 || memcmp(&m_PreviewWindowingData, &data, sizeof(data)) != 0)
{
if(m_PreviewWindow)
{
+2 -2
View File
@@ -210,10 +210,10 @@ private:
bool Verify()
{
if(ptr[0] && memcmp(ptr[0] + size, markerValue, sizeof(markerValue)))
if(ptr[0] && memcmp(ptr[0] + size, markerValue, sizeof(markerValue)) != 0)
return false;
if(ptr[1] && memcmp(ptr[1] + size, markerValue, sizeof(markerValue)))
if(ptr[1] && memcmp(ptr[1] + size, markerValue, sizeof(markerValue)) != 0)
return false;
return true;
+1 -1
View File
@@ -1567,7 +1567,7 @@ rdcarray<uint32_t> D3D11Replay::GetPassEvents(uint32_t eventId)
{
const DrawcallDescription *prev = start->previous;
if(memcmp(start->outputs, prev->outputs, sizeof(start->outputs)) ||
if(memcmp(start->outputs, prev->outputs, sizeof(start->outputs)) != 0 ||
start->depthOut != prev->depthOut)
break;
@@ -123,7 +123,7 @@ bool WrappedID3D12GraphicsCommandList::Serialise_BeginRenderPass(
D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_CLEAR)
flags |= D3D12_CLEAR_FLAG_STENCIL;
if(flags)
if(flags != 0)
{
// we can safely read from either depth/stencil clear values because if the access
// type isn't clear the corresponding flag will be unset - so whatever garbage value
@@ -199,7 +199,7 @@ bool WrappedID3D12GraphicsCommandList::Serialise_BeginRenderPass(
if(pDepthStencil->StencilBeginningAccess.Type == D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_CLEAR)
flags |= D3D12_CLEAR_FLAG_STENCIL;
if(flags)
if(flags != 0)
{
// we can safely read from either depth/stencil clear values because if the access
// type isn't clear the corresponding flag will be unset - so whatever garbage value
+4 -9
View File
@@ -594,12 +594,12 @@ rdcstr D3D12Replay::DisassembleShader(ResourceId pipeline, const ShaderReflectio
idx += 11; // stage=".S">
if(strncmp(contents.c_str() + idx, "<comment>", 9))
if(strncmp(contents.c_str() + idx, "<comment>", 9) != 0)
return "; Unknown error fetching disassembly, invalid string returned\n\n\n" + contents;
idx += 9; // <comment>
if(strncmp(contents.c_str() + idx, "<![CDATA[\n", 10))
if(strncmp(contents.c_str() + idx, "<![CDATA[\n", 10) != 0)
return "; Unknown error fetching disassembly, invalid string returned\n\n\n" + contents;
idx += 10; // <![CDATA[\n
@@ -2629,19 +2629,14 @@ rdcarray<uint32_t> D3D12Replay::GetPassEvents(uint32_t eventId)
// if we've come to the start of the log we were outside of a list
// to start with
if(start->previous == 0)
if(start->previous == NULL)
return passEvents;
// step back
const DrawcallDescription *prev = start->previous;
// something went wrong, start->previous was non-zero but we didn't
// get a draw. Abort
if(!prev)
return passEvents;
// if the outputs changed, we're done
if(memcmp(start->outputs, prev->outputs, sizeof(start->outputs)) ||
if(memcmp(start->outputs, prev->outputs, sizeof(start->outputs)) != 0 ||
start->depthOut != prev->depthOut)
break;
+3 -3
View File
@@ -629,7 +629,7 @@ void DoVendorChecks(GLPlatform &platform, GLWindowingData context)
RDCCOMPILE_ASSERT(sizeof(buf) == sizeof(buf), "Buffers are not matching sizes");
if(memcmp(buf, cmp, sizeof(buf)))
if(memcmp(buf, cmp, sizeof(buf)) != 0)
{
RDCERR("glGetTexImage from the source texture returns incorrect data!");
VendorCheck[VendorCheck_AMD_copy_compressed_cubemaps] =
@@ -647,7 +647,7 @@ void DoVendorChecks(GLPlatform &platform, GLWindowingData context)
RDCCOMPILE_ASSERT(sizeof(buf) == sizeof(buf), "Buffers are not matching sizes");
if(memcmp(buf, cmp, sizeof(buf)))
if(memcmp(buf, cmp, sizeof(buf)) != 0)
{
RDCWARN("Using hack to avoid glCopyImageSubData on cubemap textures");
VendorCheck[VendorCheck_AMD_copy_compressed_cubemaps] = true;
@@ -1451,7 +1451,7 @@ void ClearGLErrors()
{
int i = 0;
GLenum err = GL.glGetError();
while(err)
while(err != eGL_NONE)
{
err = GL.glGetError();
i++;
+3 -3
View File
@@ -266,7 +266,7 @@ void GLReplay::FillTimers(GLCounterContext &ctx, const DrawcallDescription &draw
for(uint32_t c = 0; c < counters.size(); c++)
{
m_pDriver->glGenQueries(1, &queries->obj[(uint32_t)counters[c]]);
if(m_pDriver->glGetError())
if(m_pDriver->glGetError() != eGL_NONE)
queries->obj[(uint32_t)counters[c]] = 0;
}
}
@@ -281,7 +281,7 @@ void GLReplay::FillTimers(GLCounterContext &ctx, const DrawcallDescription &draw
if(queries->obj[q])
{
m_pDriver->glBeginQuery(glCounters[q], queries->obj[q]);
if(m_pDriver->glGetError())
if(m_pDriver->glGetError() != eGL_NONE)
{
m_pDriver->glDeleteQueries(1, &queries->obj[q]);
queries->obj[q] = 0;
@@ -540,7 +540,7 @@ rdcarray<CounterResult> GLReplay::FetchCounters(const rdcarray<GPUCounter> &allC
double duration = double(data) * nanosToSecs;
if(m_pDriver->glGetError())
if(m_pDriver->glGetError() != eGL_NONE)
{
data = (uint64_t)-1;
duration = -1;
+1 -1
View File
@@ -115,7 +115,7 @@ rdcarray<uint32_t> GLReplay::GetPassEvents(uint32_t eventId)
{
const DrawcallDescription *prev = start->previous;
if(memcmp(start->outputs, prev->outputs, sizeof(start->outputs)) ||
if(memcmp(start->outputs, prev->outputs, sizeof(start->outputs)) != 0 ||
start->depthOut != prev->depthOut)
break;
+2 -2
View File
@@ -289,10 +289,10 @@ struct GLResourceRecord : public ResourceRecord
bool VerifyShadowStorage()
{
if(ShadowPtr[0] && memcmp(ShadowPtr[0] + ShadowSize, markerValue, sizeof(markerValue)))
if(ShadowPtr[0] && memcmp(ShadowPtr[0] + ShadowSize, markerValue, sizeof(markerValue)) != 0)
return false;
if(ShadowPtr[1] && memcmp(ShadowPtr[1] + ShadowSize, markerValue, sizeof(markerValue)))
if(ShadowPtr[1] && memcmp(ShadowPtr[1] + ShadowSize, markerValue, sizeof(markerValue)) != 0)
return false;
return true;
+1 -1
View File
@@ -1055,7 +1055,7 @@ void MakeChildByteOffsetsRelative(ShaderConstant &member)
int ParseVersionStatement(const char *version)
{
if(strncmp(version, "#version", 8))
if(strncmp(version, "#version", 8) != 0)
return 0;
version += 8;
+1 -1
View File
@@ -584,7 +584,7 @@ static PROC WINAPI wglGetProcAddress_hooked(const char *func)
// assume wgl functions are safe to just pass straight through, but don't pass through the wgl DX
// interop functions
if(!strncmp(func, "wgl", 3) && strncmp(func, "wglDX", 5))
if(strncmp(func, "wgl", 3) == 0 && strncmp(func, "wglDX", 5) != 0)
return realFunc;
// otherwise, consult our database of hooks
@@ -1254,7 +1254,7 @@ DXBCContainer::DXBCContainer(const void *ByteCode, size_t ByteCodeLength)
continue;
}
if(c + 5 > end || strncmp(c, "#line", 5))
if(c + 5 > end || strncmp(c, "#line", 5) != 0)
{
// resize up to account for the current line, if necessary
dstFile->resize(RDCMAX(dstLine + 1, dstFile->size()));
@@ -265,7 +265,7 @@ bool Operand::operator==(const Operand &o) const
return false;
if(numComponents != o.numComponents)
return false;
if(memcmp(comps, o.comps, 4))
if(memcmp(comps, o.comps, 4) != 0)
return false;
if(modifier != o.modifier)
return false;
+2 -1
View File
@@ -64,7 +64,8 @@ SPDBChunk::SPDBChunk(Reflection *reflection, void *chunk)
FileHeaderPage *header = (FileHeaderPage *)data;
if(memcmp(header->identifier, "Microsoft C/C++ MSF 7.00\r\n\032DS\0\0", sizeof(header->identifier)))
if(memcmp(header->identifier, "Microsoft C/C++ MSF 7.00\r\n\032DS\0\0",
sizeof(header->identifier)) != 0)
{
RDCWARN("Unexpected SPDB type");
return;
+1 -1
View File
@@ -1069,7 +1069,7 @@ void VulkanCreationInfo::ShaderModule::Init(VulkanResourceManager *resourceMan,
const VkShaderModuleCreateInfo *pCreateInfo)
{
const uint32_t SPIRVMagic = 0x07230203;
if(pCreateInfo->codeSize < 4 || memcmp(pCreateInfo->pCode, &SPIRVMagic, sizeof(SPIRVMagic)))
if(pCreateInfo->codeSize < 4 || memcmp(pCreateInfo->pCode, &SPIRVMagic, sizeof(SPIRVMagic)) != 0)
{
RDCWARN("Shader not provided with SPIR-V");
}
+2 -1
View File
@@ -251,7 +251,8 @@ VK_LAYER_RENDERDOC_CaptureEnumerateDeviceExtensionProperties(VkPhysicalDevice ph
{
// if pLayerName is NULL or not ours we're calling down through the layer chain to the ICD.
// This is our chance to filter out any reported extensions that we don't support
if(physicalDevice != NULL && (pLayerName == NULL || strcmp(pLayerName, RENDERDOC_VULKAN_LAYER_NAME)))
if(physicalDevice != NULL &&
(pLayerName == NULL || strcmp(pLayerName, RENDERDOC_VULKAN_LAYER_NAME) != 0))
return CoreDisp(physicalDevice)
->FilterDeviceExtensionProperties(physicalDevice, pLayerName, pPropertyCount, pProperties);
+1 -1
View File
@@ -1342,7 +1342,7 @@ void VulkanReplay::PatchReservedDescriptors(const VulkanStatePipeline &pipe,
// Instead of trying to remap offsets to match, we simply make every binding compute
// visible so the ordering is still the same. Since compute and graphics are disjoint this
// is safe.
if(patchedBindingStage)
if(patchedBindingStage != 0)
newBind.stageFlags = patchedBindingStage;
else
newBind.stageFlags = bind.stageFlags;
+1 -1
View File
@@ -1097,7 +1097,7 @@ Stackwalk *Create()
StackResolver *MakeResolver(bool interactive, byte *moduleDB, size_t DBSize,
RENDERDOC_ProgressCallback progress)
{
if(DBSize < 8 || memcmp(moduleDB, "WN32CALL", 8))
if(DBSize < 8 || memcmp(moduleDB, "WN32CALL", 8) != 0)
{
RDCWARN("Can't load callstack resolve for this log. Possibly from another platform?");
return NULL;
+1 -1
View File
@@ -156,7 +156,7 @@ struct RDCThumbnailProvider : public IThumbnailProvider, IInitializeWithStream
byte *readEnd = readPtr + captureHeader.size();
if(captureHeader.size() < sizeof(MAGIC_HEADER) ||
memcmp(&MAGIC_HEADER, readPtr, sizeof(MAGIC_HEADER)))
memcmp(&MAGIC_HEADER, readPtr, sizeof(MAGIC_HEADER)) != 0)
{
RDCDEBUG("Legacy header did not have expected magic number");
return;
+3 -3
View File
@@ -221,7 +221,7 @@ ReplayStatus CaptureFile::OpenFile(const char *filename, const char *filetype,
}
else
{
if(filetype != NULL && strcmp(filetype, "") && strcmp(filetype, "rdc"))
if(filetype != NULL && strcmp(filetype, "") != 0 && strcmp(filetype, "rdc") != 0)
RDCWARN("Opening file with unrecognised filetype '%s' - treating as 'rdc'", filetype);
if(progress)
@@ -262,7 +262,7 @@ ReplayStatus CaptureFile::OpenBuffer(const bytebuf &buffer, const char *filetype
}
else
{
if(filetype != NULL && strcmp(filetype, "") && strcmp(filetype, "rdc"))
if(filetype != NULL && strcmp(filetype, "") != 0 && strcmp(filetype, "rdc") != 0)
RDCWARN("Opening file with unrecognised filetype '%s' - treating as 'rdc'", filetype);
if(progress)
@@ -438,7 +438,7 @@ ReplayStatus CaptureFile::Convert(const char *filename, const char *filetype, co
}
}
if(filetype != NULL && strcmp(filetype, "") && strcmp(filetype, "rdc"))
if(filetype != NULL && strcmp(filetype, "") != 0 && strcmp(filetype, "rdc") != 0)
RDCWARN("Converting file to unrecognised filetype '%s' - treating as 'rdc'", filetype);
RDCFile output;
+5 -5
View File
@@ -564,7 +564,7 @@ static ReplayStatus XML2Structured(const char *xml, const ThumbTypeAndData &thum
pugi::xml_node xHeader = root.first_child();
if(strcmp(xHeader.name(), "header"))
if(strcmp(xHeader.name(), "header") != 0)
{
RDCERR("Malformed document, expected header node");
return ReplayStatus::FileCorrupted;
@@ -574,7 +574,7 @@ static ReplayStatus XML2Structured(const char *xml, const ThumbTypeAndData &thum
{
pugi::xml_node xDriver = xHeader.first_child();
if(strcmp(xDriver.name(), "driver"))
if(strcmp(xDriver.name(), "driver") != 0)
{
RDCERR("Malformed document, expected driver node");
return ReplayStatus::FileCorrupted;
@@ -589,7 +589,7 @@ static ReplayStatus XML2Structured(const char *xml, const ThumbTypeAndData &thum
pugi::xml_node xThumbnail = xIdent.next_sibling();
if(strcmp(xThumbnail.name(), "thumbnail"))
if(strcmp(xThumbnail.name(), "thumbnail") != 0)
{
RDCERR("Malformed document, expected driver node");
return ReplayStatus::FileCorrupted;
@@ -714,7 +714,7 @@ static ReplayStatus XML2Structured(const char *xml, const ThumbTypeAndData &thum
pugi::xml_node xChunks = xSection;
if(strcmp(xSection.name(), "chunks"))
if(strcmp(xSection.name(), "chunks") != 0)
{
RDCERR("Malformed document, expected chunks node");
return ReplayStatus::FileCorrupted;
@@ -733,7 +733,7 @@ static ReplayStatus XML2Structured(const char *xml, const ThumbTypeAndData &thum
for(pugi::xml_node xChunk = xChunks.first_child(); xChunk; xChunk = xChunk.next_sibling())
{
if(strcmp(xChunk.name(), "chunk"))
if(strcmp(xChunk.name(), "chunk") != 0)
return ReplayStatus::FileCorrupted;
SDChunk *chunk = new SDChunk(xChunk.attribute("name").as_string());