mirror of
https://github.com/neovim/neovim.git
synced 2025-10-08 19:06:31 +00:00
shell/logging: Fix E730 with verbose system({List}) #9009
ref https://github.com/neovim/neovim/issues/9001#issuecomment-421843790 Steps to reproduce: :set verbose=9 :call system(['echo']) E730: using List as a String
This commit is contained in:
@@ -16471,13 +16471,12 @@ static void get_system_output_as_rettv(typval_T *argvars, typval_T *rettv,
|
||||
}
|
||||
|
||||
if (p_verbose > 3) {
|
||||
char buf[NUMBUFLEN];
|
||||
const char * cmd = tv_get_string_buf(argvars, buf);
|
||||
|
||||
char *cmdstr = shell_argv_to_str(argv);
|
||||
verbose_enter_scroll();
|
||||
smsg(_("Calling shell to execute: \"%s\""), cmd);
|
||||
smsg(_("Executing command: \"%s\""), cmdstr);
|
||||
msg_puts("\n\n");
|
||||
verbose_leave_scroll();
|
||||
xfree(cmdstr);
|
||||
}
|
||||
|
||||
if (do_profiling == PROF_YES) {
|
||||
|
@@ -2632,7 +2632,7 @@ static const char *const str_errors[] = {
|
||||
|
||||
#undef FUNC_ERROR
|
||||
|
||||
/// Check that given value is a string or can be converted to it
|
||||
/// Check that given value is a VimL String or can be "cast" to it.
|
||||
///
|
||||
/// Error messages are compatible with tv_get_string_chk() previously used for
|
||||
/// the same purpose.
|
||||
@@ -2805,7 +2805,7 @@ float_T tv_get_float(const typval_T *const tv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// Get the string value of a VimL object
|
||||
/// Get the string value of a "stringish" VimL object.
|
||||
///
|
||||
/// @param[in] tv Object to get value of.
|
||||
/// @param buf Buffer used to hold numbers and special variables converted to
|
||||
@@ -2847,7 +2847,7 @@ const char *tv_get_string_buf_chk(const typval_T *const tv, char *const buf)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/// Get the string value of a VimL object
|
||||
/// Get the string value of a "stringish" VimL object.
|
||||
///
|
||||
/// @warning For number and special values it uses a single, static buffer. It
|
||||
/// may be used only once, next call to get_tv_string may reuse it. Use
|
||||
@@ -2866,7 +2866,7 @@ const char *tv_get_string_chk(const typval_T *const tv)
|
||||
return tv_get_string_buf_chk(tv, mybuf);
|
||||
}
|
||||
|
||||
/// Get the string value of a VimL object
|
||||
/// Get the string value of a "stringish" VimL object.
|
||||
///
|
||||
/// @warning For number and special values it uses a single, static buffer. It
|
||||
/// may be used only once, next call to get_tv_string may reuse it. Use
|
||||
@@ -2888,7 +2888,7 @@ const char *tv_get_string(const typval_T *const tv)
|
||||
return tv_get_string_buf((typval_T *)tv, mybuf);
|
||||
}
|
||||
|
||||
/// Get the string value of a VimL object
|
||||
/// Get the string value of a "stringish" VimL object.
|
||||
///
|
||||
/// @note tv_get_string_chk() and tv_get_string_buf_chk() are similar, but
|
||||
/// return NULL on error.
|
||||
|
@@ -2718,7 +2718,7 @@ int call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg)
|
||||
|
||||
if (p_verbose > 3) {
|
||||
verbose_enter();
|
||||
smsg(_("Calling shell to execute: \"%s\""), cmd == NULL ? p_sh : cmd);
|
||||
smsg(_("Executing command: \"%s\""), cmd == NULL ? p_sh : cmd);
|
||||
msg_putchar('\n');
|
||||
verbose_leave();
|
||||
}
|
||||
|
@@ -80,21 +80,53 @@ char **shell_build_argv(const char *cmd, const char *extra_args)
|
||||
void shell_free_argv(char **argv)
|
||||
{
|
||||
char **p = argv;
|
||||
|
||||
if (p == NULL) {
|
||||
// Nothing was allocated, return
|
||||
return;
|
||||
}
|
||||
|
||||
while (*p != NULL) {
|
||||
// Free each argument
|
||||
xfree(*p);
|
||||
p++;
|
||||
}
|
||||
|
||||
xfree(argv);
|
||||
}
|
||||
|
||||
/// Joins shell arguments from `argv` into a new string.
|
||||
/// If the result is too long it is truncated with ellipsis ("...").
|
||||
///
|
||||
/// @returns[allocated] `argv` joined to a string.
|
||||
char *shell_argv_to_str(char **const argv)
|
||||
FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
size_t n = 0;
|
||||
char **p = argv;
|
||||
char *rv = xcalloc(256, sizeof(*rv));
|
||||
const size_t maxsize = (256 * sizeof(*rv));
|
||||
if (*p == NULL) {
|
||||
return rv;
|
||||
}
|
||||
while (*p != NULL) {
|
||||
xstrlcat(rv, "'", maxsize);
|
||||
xstrlcat(rv, *p, maxsize);
|
||||
n = xstrlcat(rv, "' ", maxsize);
|
||||
if (n >= maxsize) {
|
||||
break;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
if (n < maxsize) {
|
||||
rv[n - 1] = '\0';
|
||||
} else {
|
||||
// Command too long, show ellipsis: "/bin/bash 'foo' 'bar'..."
|
||||
rv[maxsize - 4] = '.';
|
||||
rv[maxsize - 3] = '.';
|
||||
rv[maxsize - 2] = '.';
|
||||
rv[maxsize - 1] = '\0';
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
/// Calls the user-configured 'shell' (p_sh) for running a command or wildcard
|
||||
/// expansion.
|
||||
///
|
||||
|
Reference in New Issue
Block a user