Use snprintf instead of sprintf (#1711)

Co-authored-by: sogaiu <983021772@users.noreply.github.com>
This commit is contained in:
sogaiu
2026-02-14 09:04:33 -06:00
committed by GitHub
co-authored by sogaiu
parent d81512723b
commit abd7bb1110
3 changed files with 3 additions and 3 deletions
+1 -1
View File
@@ -37,7 +37,7 @@ int system_test() {
/* Check the version defines are self consistent */ /* Check the version defines are self consistent */
char version_combined[256]; char version_combined[256];
sprintf(version_combined, "%d.%d.%d%s", JANET_VERSION_MAJOR, JANET_VERSION_MINOR, JANET_VERSION_PATCH, JANET_VERSION_EXTRA); snprintf(version_combined, sizeof(version_combined), "%d.%d.%d%s", JANET_VERSION_MAJOR, JANET_VERSION_MINOR, JANET_VERSION_PATCH, JANET_VERSION_EXTRA);
assert(!strcmp(JANET_VERSION, version_combined)); assert(!strcmp(JANET_VERSION, version_combined));
/* Reflexive testing and nanbox testing */ /* Reflexive testing and nanbox testing */
+1 -1
View File
@@ -2416,7 +2416,7 @@ Janet janet_ev_lasterr(void) {
msgbuf, msgbuf,
sizeof(msgbuf), sizeof(msgbuf),
NULL); NULL);
if (!*msgbuf) sprintf(msgbuf, "%d", code); if (!*msgbuf) snprintf(msgbuf, sizeof(msgbuf), "%d", code);
char *c = msgbuf; char *c = msgbuf;
while (*c) { while (*c) {
if (*c == '\n' || *c == '\r') { if (*c == '\n' || *c == '\r') {
+1 -1
View File
@@ -1331,7 +1331,7 @@ static Janet os_execute_impl(int32_t argc, Janet *argv, JanetExecuteMode mode) {
msgbuf, msgbuf,
sizeof(msgbuf), sizeof(msgbuf),
NULL); NULL);
if (!*msgbuf) sprintf(msgbuf, "%d", cp_error_code); if (!*msgbuf) snprintf(msgbuf, sizeof(msgbuf), "%d", cp_error_code);
char *c = msgbuf; char *c = msgbuf;
while (*c) { while (*c) {
if (*c == '\n' || *c == '\r') { if (*c == '\n' || *c == '\r') {