Revert "use dynamic buffer for argv"

This reverts commit ffd9f0868b.
This commit is contained in:
Wirtos_new 2021-06-19 18:11:53 +03:00
parent 757e95dd18
commit 9f206af083
2 changed files with 13 additions and 33 deletions

View file

@ -81,18 +81,14 @@ show_adb_installation_msg() {
static void
show_adb_err_msg(enum process_result err, const char *const argv[]) {
size_t n_args, len;
char *buf = NULL;
len = xargvlen(argv, &n_args) + (n_args * 3 - 1) + 1;
/* buffer large enough to store argv_to_string repr + nul terminator */
buf = malloc(len);
char buf[512];
switch (err) {
case PROCESS_ERROR_GENERIC:
argv_to_string(argv, buf, len);
argv_to_string(argv, buf, sizeof(buf));
LOGE("Failed to execute: %s", buf);
break;
case PROCESS_ERROR_MISSING_BINARY:
argv_to_string(argv, buf, len);
argv_to_string(argv, buf, sizeof(buf));
LOGE("Command not found: %s", buf);
LOGE("(make 'adb' accessible from your PATH or define its full"
"path in the ADB environment variable)");
@ -102,7 +98,6 @@ show_adb_err_msg(enum process_result err, const char *const argv[]) {
// do nothing
break;
}
free(buf);
}
process_t

View file

@ -6,11 +6,6 @@
#include "util/log.h"
#include "util/str_util.h"
#if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#endif
static int
build_cmd(char *cmd, size_t len, const char *const argv[]) {
// Windows command-line parsing is WTF:
@ -29,44 +24,34 @@ enum process_result
process_execute(const char *const argv[], HANDLE *handle) {
STARTUPINFOW si;
PROCESS_INFORMATION pi;
wchar_t *wide = NULL;
char *cmd = NULL;
enum process_result res = PROCESS_SUCCESS;
size_t len = xargvlen(argv, NULL) + 1;
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
cmd = malloc(len);
if (cmd == NULL || build_cmd(cmd, len, argv) != 0) {
char cmd[256];
if (build_cmd(cmd, sizeof(cmd), argv)) {
*handle = NULL;
res = PROCESS_ERROR_GENERIC;
goto end;
return PROCESS_ERROR_GENERIC;
}
wide = utf8_to_wide_char(cmd);
wchar_t *wide = utf8_to_wide_char(cmd);
if (!wide) {
LOGC("Could not allocate wide char string");
res = PROCESS_ERROR_GENERIC;
goto end;
return PROCESS_ERROR_GENERIC;
}
if (!CreateProcessW(NULL, wide, NULL, NULL, FALSE, 0, NULL, NULL, &si,
&pi)) {
free(wide);
*handle = NULL;
if (GetLastError() == ERROR_FILE_NOT_FOUND) {
res = PROCESS_ERROR_MISSING_BINARY;
} else {
res = PROCESS_ERROR_GENERIC;
return PROCESS_ERROR_MISSING_BINARY;
}
goto end;
return PROCESS_ERROR_GENERIC;
}
*handle = pi.hProcess;
end:
free(wide);
free(cmd);
return res;
*handle = pi.hProcess;
return PROCESS_SUCCESS;
}
bool