Get rid of some fixed-size char buffers

This commit is contained in:
Rangi42
2024-03-07 13:39:51 -05:00
parent 184957c0ed
commit 2fd95381a6
3 changed files with 19 additions and 18 deletions

View File

@@ -356,11 +356,8 @@ void fstk_RunMacro(char const *macroName, MacroArgs &args) {
std::vector<uint32_t> const &srcIters = macro->src->iters(); std::vector<uint32_t> const &srcIters = macro->src->iters();
for (uint32_t i = srcIters.size(); i--;) { for (uint32_t i = srcIters.size(); i--;) {
char buf[sizeof("::REPT~4294967295")]; // UINT32_MAX fileInfoName.append("::REPT~");
fileInfoName.append(std::to_string(srcIters[i]));
if (sprintf(buf, "::REPT~%" PRIu32, srcIters[i]) < 0)
fatalerror("Failed to write macro invocation info: %s\n", strerror(errno));
fileInfoName.append(buf);
} }
} }
fileInfoName.append("::"); fileInfoName.append("::");

View File

@@ -462,10 +462,9 @@ static void readAssertion(
uint32_t i, uint32_t i,
std::vector<FileStackNode> const &fileNodes std::vector<FileStackNode> const &fileNodes
) { ) {
char assertName[sizeof("Assertion #4294967295")]; // UINT32_MAX std::string assertName("Assertion #");
snprintf(assertName, sizeof(assertName), "Assertion #%" PRIu32, i);
assertName += std::to_string(i);
readPatch(file, assert.patch, fileName, assertName, 0, fileNodes); readPatch(file, assert.patch, fileName, assertName, 0, fileNodes);
tryReadstring(assert.message, file, "%s: Cannot read assertion's message: %s", fileName); tryReadstring(assert.message, file, "%s: Cannot read assertion's message: %s", fileName);
} }

View File

@@ -349,17 +349,13 @@ static char *execProg(char const *name, char * const *argv) {
return buf; return buf;
}; };
char cmdLine[32768]; // Max command line size on Windows std::vector<char> cmdLine;
char *ptr = cmdLine;
for (size_t i = 0; argv[i]; ++i) { for (size_t i = 0; argv[i]; ++i) {
char const *src = argv[i]; if (i > 0)
// I miss you, `stpcpy` cmdLine.push_back(' ');
while (*src) { cmdLine.insert(cmdLine.end(), argv[i], argv[i] + strlen(argv[i]));
*ptr++ = *src++;
}
*ptr++ = ' ';
} }
*ptr = '\0'; cmdLine.push_back('\0');
STARTUPINFOA startupInfo; STARTUPINFOA startupInfo;
GetStartupInfoA(&startupInfo); GetStartupInfoA(&startupInfo);
@@ -386,7 +382,16 @@ static char *execProg(char const *name, char * const *argv) {
PROCESS_INFORMATION child; PROCESS_INFORMATION child;
if (CreateProcessA( if (CreateProcessA(
nullptr, cmdLine, nullptr, nullptr, true, 0, nullptr, nullptr, &childStartupInfo, &child nullptr,
cmdLine.data(),
nullptr,
nullptr,
true,
0,
nullptr,
nullptr,
&childStartupInfo,
&child
) )
== 0) { == 0) {
return winStrerror(GetLastError()); return winStrerror(GetLastError());