From a009035b2744be16836aebd81c18bb1a437d236e Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 22 Apr 2026 16:04:02 -0400 Subject: Use snprintf --- src/lib/core/conda.c | 2 +- src/lib/core/utils.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/lib/core') diff --git a/src/lib/core/conda.c b/src/lib/core/conda.c index 12d1a30..c8cdb25 100644 --- a/src/lib/core/conda.c +++ b/src/lib/core/conda.c @@ -63,7 +63,7 @@ int micromamba(const struct MicromambaInfo *info, char *command, ...) { } va_start(args, command); - cmd_len = vsnprintf(cmd + strlen(cmd), sizeof(cmd) - cmd_len, command, args); + cmd_len = vsnprintf(cmd + strlen(cmd), sizeof(cmd) - strlen(cmd) - cmd_len, command, args); if (cmd_len < 0) { SYSERROR("%s", "Unable to append arguments to micromamba command"); va_end(args); diff --git a/src/lib/core/utils.c b/src/lib/core/utils.c index f65a1d8..ea23024 100644 --- a/src/lib/core/utils.c +++ b/src/lib/core/utils.c @@ -322,7 +322,7 @@ int git_clone(struct Process *proc, char *url, char *destdir, char *gitref) { // Destination directory does not exist const char *command_fmt = " %s"; const int command_fmt_len = snprintf(NULL, 0, command_fmt, destdir); - snprintf(command + strlen(command), sizeof(command) - command_fmt_len, command_fmt, destdir); + snprintf(command + strlen(command), sizeof(command) - strlen(command) - command_fmt_len, command_fmt, destdir); // Clone the repo result = shell(proc, command); if (result) { @@ -928,7 +928,7 @@ void debug_hexdump(char *data, int len) { if (count == 0) { const char *pos_fmt = "%p"; const int pos_fmt_len = snprintf(NULL, 0, pos_fmt, pos); - snprintf(addr + strlen(addr), sizeof(addr) - pos_fmt_len, pos_fmt, pos); + snprintf(addr + strlen(addr), sizeof(addr) - strlen(addr) - pos_fmt_len, pos_fmt, pos); } if (count == 8) { strncat(bytes, " ", sizeof(bytes) - strlen(bytes) - 1); @@ -946,7 +946,7 @@ void debug_hexdump(char *data, int len) { const char *bytes_fmt = "%02X "; const int bytes_fmt_len = snprintf(NULL, 0, bytes_fmt, (unsigned char) *pos); - snprintf(bytes + strlen(bytes), sizeof(bytes) - bytes_fmt_len, bytes_fmt, (unsigned char) *pos); + snprintf(bytes + strlen(bytes), sizeof(bytes) - strlen(bytes) - bytes_fmt_len, bytes_fmt, (unsigned char) *pos); const char *ascii_fmt = "%c"; // no need to calculate length for a single character -- cgit