diff options
author | Nobuyoshi Nakada <[email protected]> | 2022-11-24 23:39:55 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2022-11-25 08:51:14 +0900 |
commit | 1a47521c4459fd61384c51ee58bc422ec69310d6 (patch) | |
tree | 8cc1ab944cfea5c0a93d27f6a889ac616d38465b /win32 | |
parent | bcdfe12919f967cad17c2c6a8c98454f373ca935 (diff) |
Use `rb_sprintf` instead of deprecated `sprintf`
Diffstat (limited to 'win32')
-rw-r--r-- | win32/win32.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/win32/win32.c b/win32/win32.c index b9af42d9c9..1a532c6c7c 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -1423,18 +1423,20 @@ w32_spawn(int mode, const char *cmd, const char *prog, UINT cp) while (ISSPACE(*cmd)) cmd++; if ((shell = w32_getenv("RUBYSHELL", cp)) && (redir = has_redirection(cmd, cp))) { size_t shell_len = strlen(shell); - char *tmp = ALLOCV(v, shell_len + strlen(cmd) + sizeof(" -c ") + 2); + size_t cmd_len = strlen(cmd) + sizeof(" -c ") + 2; + char *tmp = ALLOCV(v, shell_len + cmd_len); memcpy(tmp, shell, shell_len + 1); translate_char(tmp, '/', '\\', cp); - sprintf(tmp + shell_len, " -c \"%s\"", cmd); + snprintf(tmp + shell_len, cmd_len, " -c \"%s\"", cmd); cmd = tmp; } else if ((shell = w32_getenv("COMSPEC", cp)) && (nt = !is_command_com(shell), (redir < 0 ? has_redirection(cmd, cp) : redir) || is_internal_cmd(cmd, nt))) { - char *tmp = ALLOCV(v, strlen(shell) + strlen(cmd) + sizeof(" /c ") + (nt ? 2 : 0)); - sprintf(tmp, nt ? "%s /c \"%s\"" : "%s /c %s", shell, cmd); + size_t cmd_len = strlen(shell) + strlen(cmd) + sizeof(" /c ") + (nt ? 2 : 0); + char *tmp = ALLOCV(v, cmd_len); + snprintf(tmp, cmd_len, nt ? "%s /c \"%s\"" : "%s /c %s", shell, cmd); cmd = tmp; } else { |