Fix some memcpy/pointer access issues identified by PVS Studio

* I don't think any of these were bugs, but they're certainly better off being
  fixed.
This commit is contained in:
baldurk
2020-01-21 14:24:24 +00:00
parent 7dd116abd4
commit 322e3c667d
12 changed files with 461 additions and 454 deletions
+1 -1
View File
@@ -123,7 +123,7 @@ D3D11TextRenderer::D3D11TextRenderer(WrappedID3D11Device *wrapper)
stbtt_BakeFontBitmap(ttfdata, 0, pixelHeight, buf, width, height, firstChar, numChars, chardata);
CharSize = pixelHeight;
CharAspect = chardata->xadvance / pixelHeight;
CharAspect = chardata[0].xadvance / pixelHeight;
stbtt_fontinfo f = {0};
stbtt_InitFont(&f, ttfdata, 0);
+1 -1
View File
@@ -133,7 +133,7 @@ D3D12TextRenderer::D3D12TextRenderer(WrappedID3D12Device *wrapper)
stbtt_BakeFontBitmap(ttfdata, 0, pixelHeight, buf, width, height, firstChar, numChars, chardata);
CharSize = pixelHeight;
CharAspect = chardata->xadvance / pixelHeight;
CharAspect = chardata[0].xadvance / pixelHeight;
stbtt_fontinfo f = {0};
stbtt_InitFont(&f, ttfdata, 0);
+2 -2
View File
@@ -262,7 +262,7 @@ void D3D8DebugManager::RenderTextInternal(float x, float y, const rdcstr &text)
// create text VB
quads = new Quad[quadCount];
float textStartingPositionX = (-width / 2.f) + (x * m_Font.charData->xadvance);
float textStartingPositionX = (-width / 2.f) + (x * m_Font.charData[0].xadvance);
float textStartingPositionY = (-height / 2.f) + ((y + 1.f) * m_Font.maxHeight);
float textPositionX = textStartingPositionX;
@@ -274,7 +274,7 @@ void D3D8DebugManager::RenderTextInternal(float x, float y, const rdcstr &text)
if(glyphIndex < 0)
{
float currentX = textPositionX;
textPositionX += m_Font.charData->xadvance;
textPositionX += m_Font.charData[0].xadvance;
quads[i] = Quad(currentX, textPositionY - m_Font.maxHeight, 0.5f, 0.f, 0.f, textPositionX,
textPositionY, 0.f, 0.f);
}
+2 -2
View File
@@ -269,7 +269,7 @@ void D3D9DebugManager::RenderTextInternal(float x, float y, const rdcstr &text)
// create text VB
quads = new Quad[quadCount];
float textStartingPositionX = (-width / 2.f) + (x * m_Font.charData->xadvance);
float textStartingPositionX = (-width / 2.f) + (x * m_Font.charData[0].xadvance);
float textStartingPositionY = (-height / 2.f) + ((y + 1.f) * m_Font.maxHeight);
float textPositionX = textStartingPositionX;
@@ -281,7 +281,7 @@ void D3D9DebugManager::RenderTextInternal(float x, float y, const rdcstr &text)
if(glyphIndex < 0)
{
float currentX = textPositionX;
textPositionX += m_Font.charData->xadvance;
textPositionX += m_Font.charData[0].xadvance;
quads[i] = Quad(currentX, textPositionY - m_Font.maxHeight, 0.5f, 0.f, 0.f, textPositionX,
textPositionY, 0.f, 0.f);
}
+2 -2
View File
@@ -1417,8 +1417,8 @@ bool GLReplay::GetMinMax(ResourceId texid, const Subresource &sub, CompType type
depth[0].y = float(stencil[0].x) / rangeScale;
depth[1].y = float(stencil[1].x) / rangeScale;
memcpy(minval, &depth[0].x, sizeof(depth[0]));
memcpy(maxval, &depth[1].x, sizeof(depth[1]));
memcpy(minval, &depth[0], sizeof(depth[0]));
memcpy(maxval, &depth[1], sizeof(depth[1]));
return true;
}
+1 -1
View File
@@ -61,7 +61,7 @@ void WrappedOpenGL::ContextData::CreateDebugData()
#if ENABLED(RDOC_ANDROID)
CharSize *= 2.0f;
#endif
CharAspect = chardata->xadvance / charPixelHeight;
CharAspect = chardata[0].xadvance / charPixelHeight;
stbtt_fontinfo f = {0};
stbtt_InitFont(&f, ttfdata, 0);
@@ -73,7 +73,7 @@ copyright = '''
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2020 Baldur Karlsson
* Copyright (c) 2019-2020 Baldur Karlsson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -924,7 +924,7 @@ for inst in spirv['instructions']:
construct_size = 'FixedWordSize'
size = 1 # opcode / wordcount packed
all_size = 1 # size, but with all optionals included
iter_init = ' memcpy(this, &(*it), sizeof(*this));'
iter_init = ' memcpy(this, it.words(), sizeof(*this));'
complex_type = False
manual_init = ' this->op = OpCode;\n'
manual_init += ' this->wordCount = (uint16_t)it.size();\n'
+15 -7
View File
@@ -63,21 +63,22 @@ public:
bool operator!=(const IterBase<ConstOrNotVector> &it) const = delete;
bool operator<(const IterBase<ConstOrNotVector> &it) const
{
return words == it.words && offset < it.offset;
return wordsVector == it.wordsVector && offset < it.offset;
}
// utility functions
explicit operator bool() const { return words != NULL && offset < words->size(); }
explicit operator bool() const { return wordsVector != NULL && offset < wordsVector->size(); }
const uint32_t &operator*() const { return cur(); }
rdcspv::Op opcode() const { return rdcspv::Op(cur() & rdcspv::OpCodeMask); }
const uint32_t &word(size_t idx) const { return words->at(offset + idx); }
const uint32_t &word(size_t idx) const { return wordsVector->at(offset + idx); }
const uint32_t *words() const { return wordsVector->data() + offset; }
size_t offs() const { return offset; }
size_t size() const { return cur() >> rdcspv::WordCountShift; }
protected:
IterBase() = default;
IterBase(ConstOrNotVector &w, size_t o) : words(&w), offset(o) {}
inline const uint32_t &cur() const { return words->at(offset); }
IterBase(ConstOrNotVector &w, size_t o) : wordsVector(&w), offset(o) {}
inline const uint32_t &cur() const { return wordsVector->at(offset); }
size_t offset = 0;
ConstOrNotVector *words = NULL;
ConstOrNotVector *wordsVector = NULL;
};
class ConstIter : public IterBase<const rdcarray<uint32_t>>
@@ -109,7 +110,7 @@ public:
private:
friend class Operation;
inline uint32_t &cur() { return mutable_words()->at(offset); }
rdcarray<uint32_t> *mutable_words() { return (rdcarray<uint32_t> *)words; }
rdcarray<uint32_t> *mutable_words() { return (rdcarray<uint32_t> *)wordsVector; }
};
class Operation
@@ -131,6 +132,13 @@ public:
iter = Iter(words, 0);
}
Operation &operator=(const Operation &op)
{
words = op.words;
iter = Iter(words, 0);
return *this;
}
static Operation copy(Iter it)
{
File diff suppressed because it is too large Load Diff
+1 -2
View File
@@ -1619,8 +1619,7 @@ ResourceId VulkanReplay::RenderOverlay(ResourceId texid, CompType typeCast, Floa
m_pDriver->m_RenderState.BeginRenderPassAndApplyState(cmd, VulkanRenderState::BindGraphics);
VkClearAttachment clearatt = {VK_IMAGE_ASPECT_COLOR_BIT, 0, {}};
memcpy(clearatt.clearValue.color.float32, &clearCol.x,
sizeof(clearatt.clearValue.color.float32));
memcpy(clearatt.clearValue.color.float32, &clearCol, sizeof(clearatt.clearValue.color.float32));
rdcarray<VkClearAttachment> atts;
VulkanCreationInfo::Framebuffer &fb =
+1 -1
View File
@@ -339,7 +339,7 @@ VulkanTextRenderer::VulkanTextRenderer(WrappedVulkan *driver)
m_FontCharSize *= 2.0f;
#endif
m_FontCharAspect = chardata->xadvance / pixelHeight;
m_FontCharAspect = chardata[0].xadvance / pixelHeight;
stbtt_fontinfo f = {0};
stbtt_InitFont(&f, ttfdata, 0);
+2 -2
View File
@@ -2139,8 +2139,8 @@ bool VulkanReplay::GetMinMax(ResourceId texid, const Subresource &sub, CompType
depth[0].y = float(stencil[0].x) / 255.0f;
depth[1].y = float(stencil[1].x) / 255.0f;
memcpy(minval, &depth[0].x, sizeof(depth[0]));
memcpy(maxval, &depth[1].x, sizeof(depth[1]));
memcpy(minval, &depth[0], sizeof(depth[0]));
memcpy(maxval, &depth[1], sizeof(depth[1]));
return true;
}