Use snprintf() instead of sprintf().

All linker warnings should now be eliminated.
This commit is contained in:
Jordan Bancino 2023-04-25 22:01:58 +00:00
parent d83db35df0
commit e1367d5bff
4 changed files with 7 additions and 6 deletions

View file

@ -357,14 +357,15 @@ ConfigParse(HashMap * config)
} }
else else
{ {
tConfig->baseUrl = Malloc(strlen(tConfig->serverName) + 10); size_t len = strlen(tConfig->serverName) + 10;
tConfig->baseUrl = Malloc(len);
if (!tConfig->baseUrl) if (!tConfig->baseUrl)
{ {
tConfig->err = "Error allocating memory for default config value 'baseUrl'."; tConfig->err = "Error allocating memory for default config value 'baseUrl'.";
goto error; goto error;
} }
sprintf(tConfig->baseUrl, "https://%s", tConfig->serverName); snprintf(tConfig->baseUrl, len, "https://%s", tConfig->serverName);
} }
CONFIG_OPTIONAL_STRING(tConfig->identityServer, "identityServer", NULL); CONFIG_OPTIONAL_STRING(tConfig->identityServer, "identityServer", NULL);

View file

@ -81,7 +81,7 @@ HttpRequest(HttpRequestMethod method, int flags, unsigned short port, char *host
} }
else else
{ {
sprintf(serv, "%hu", port); snprintf(serv, sizeof(serv), "%hu", port);
} }

View file

@ -451,7 +451,7 @@ void
printFunc(pI - MEMORY_HEXDUMP_WIDTH, hexBuf, asciiBuf, args); printFunc(pI - MEMORY_HEXDUMP_WIDTH, hexBuf, asciiBuf, args);
sprintf(hexBuf, "%02x ", pc[pI]); snprintf(hexBuf, 4, "%02x ", pc[pI]);
hI = 3; hI = 3;
asciiBuf[0] = isprint(pc[pI]) ? pc[pI] : '.'; asciiBuf[0] = isprint(pc[pI]) ? pc[pI] : '.';
@ -463,7 +463,7 @@ void
asciiBuf[aI] = isprint(pc[pI]) ? pc[pI] : '.'; asciiBuf[aI] = isprint(pc[pI]) ? pc[pI] : '.';
aI++; aI++;
sprintf(hexBuf + hI, "%02x ", pc[pI]); snprintf(hexBuf + hI, 4, "%02x ", pc[pI]);
hI += 3; hI += 3;
} }
} }

View file

@ -231,7 +231,7 @@ Sha256(char *str)
/* Convert to string */ /* Convert to string */
for (i = 0; i < 32; i++) for (i = 0; i < 32; i++)
{ {
sprintf(outStr + (2 * i), "%02x", out[i]); snprintf(outStr + (2 * i), 3, "%02x", out[i]);
} }
return outStr; return outStr;