Properly clamp some iterative snprintf()s.

This commit is contained in:
Unknown W. Brackets 2014-11-05 08:06:15 -08:00
parent ebb9f68c3e
commit fba0110073
3 changed files with 13 additions and 13 deletions

View File

@ -57,27 +57,27 @@ void GeDescribeVertexType(u32 op, char *buffer, int len) {
char *w = buffer, *end = buffer + len;
if (through)
w += snprintf(w, end - w, "through, ");
if (typeNames[tc])
if (typeNames[tc] && w < end)
w += snprintf(w, end - w, "%s texcoords, ", typeNames[tc]);
if (colorNames[col])
if (colorNames[col] && w < end)
w += snprintf(w, end - w, "%s colors, ", colorNames[col]);
if (typeNames[nrm])
if (typeNames[nrm] && w < end)
w += snprintf(w, end - w, "%s normals, ", typeNamesS[nrm]);
if (typeNames[pos])
if (typeNames[pos] && w < end)
w += snprintf(w, end - w, "%s positions, ", typeNamesS[pos]);
if (typeNames[weight])
if (typeNames[weight] && w < end)
w += snprintf(w, end - w, "%s weights (%d), ", typeNames[weight], weightCount);
else if (weightCount > 0)
else if (weightCount > 0 && w < end)
w += snprintf(w, end - w, "unknown weights (%d), ", weightCount);
if (morphCount > 0)
if (morphCount > 0 && w < end)
w += snprintf(w, end - w, "%d morphs, ", morphCount);
if (typeNames[idx])
if (typeNames[idx] && w < end)
w += snprintf(w, end - w, "%s indexes, ", typeNames[idx]);
if (w < buffer + 2)
snprintf(buffer, len, "none");
// Otherwise, get rid of the pesky trailing comma.
else
else if (w < end)
w[-2] = '\0';
}

View File

@ -905,12 +905,12 @@ void CtrlDisAsmView::copyInstructions(u32 startAddr, u32 endAddr, bool withDisas
char *temp = new char[space];
char *p = temp, *end = temp + space;
for (u32 pos = startAddr; pos < endAddr; pos += instructionSize)
for (u32 pos = startAddr; pos < endAddr && p < end; pos += instructionSize)
{
p += snprintf(p, end - p, "%08X", debugger->readMemory(pos));
// Don't leave a trailing newline.
if (pos + instructionSize < endAddr)
if (pos + instructionSize < endAddr && p < end)
p += snprintf(p, end - p, "\r\n");
}
W32Util::CopyTextToClipboard(wnd, temp);

View File

@ -314,7 +314,7 @@ void CtrlDisplayListView::onMouseUp(WPARAM wParam, LPARAM lParam, int button)
char *temp = new char[space];
char *p = temp, *end = temp + space;
for (u32 pos = selectRangeStart; pos < selectRangeEnd; pos += instructionSize)
for (u32 pos = selectRangeStart; pos < selectRangeEnd && p < end; pos += instructionSize)
{
GPUDebugOp op = gpuDebug->DissassembleOp(pos);
p += snprintf(p, end - p, "%s\r\n", op.desc.c_str());
@ -351,7 +351,7 @@ void CtrlDisplayListView::onMouseUp(WPARAM wParam, LPARAM lParam, int button)
char *temp = new char[space];
char *p = temp, *end = temp + space;
for (u32 pos = selectRangeStart; pos < selectRangeEnd; pos += instructionSize)
for (u32 pos = selectRangeStart; pos < selectRangeEnd && p < end; pos += instructionSize)
p += snprintf(p, end - p, "%08X\r\n", Memory::ReadUnchecked_U32(pos));
W32Util::CopyTextToClipboard(wnd, temp);