Quote arguments in clang-target-wrapper.c
We quote each passed through argument, and escape quote chars in them. For cases when the passed through argument ends with a backslash, this fails though, since whatever is unescaping it doesn't seem to handle double backslashes for escaping backslashes themselves.
This commit is contained in:
1 parent
22b5681765
commit
99b6407196
1 file changed
+20
-1
@@ -46,6 +46,25 @@ typedef char TCHAR;
|
|||||||
#define EXECVP_CAST (char **)
|
#define EXECVP_CAST (char **)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
TCHAR *escape(const TCHAR *str) {
|
||||||
|
#ifdef _WIN32
|
||||||
|
TCHAR *out = malloc((_tcslen(str) * 2 + 3) * sizeof(*out));
|
||||||
|
TCHAR *ptr = out;
|
||||||
|
int i;
|
||||||
|
*ptr++ = '"';
|
||||||
|
for (i = 0; str[i]; i++) {
|
||||||
|
if (str[i] == '"')
|
||||||
|
*ptr++ = '\\';
|
||||||
|
*ptr++ = str[i];
|
||||||
|
}
|
||||||
|
*ptr++ = '"';
|
||||||
|
*ptr++ = '\0';
|
||||||
|
return out;
|
||||||
|
#else
|
||||||
|
return _tcsdup(str);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
int _tmain(int argc, TCHAR* argv[]) {
|
int _tmain(int argc, TCHAR* argv[]) {
|
||||||
const TCHAR *argv0 = argv[0];
|
const TCHAR *argv0 = argv[0];
|
||||||
const TCHAR *sep = _tcsrchr(argv0, '/');
|
const TCHAR *sep = _tcsrchr(argv0, '/');
|
||||||
@@ -124,7 +143,7 @@ int _tmain(int argc, TCHAR* argv[]) {
|
|||||||
exec_argv[arg++] = _T("-Qunused-arguments");
|
exec_argv[arg++] = _T("-Qunused-arguments");
|
||||||
|
|
||||||
for (int i = 1; i < argc; i++)
|
for (int i = 1; i < argc; i++)
|
||||||
exec_argv[arg++] = argv[i];
|
exec_argv[arg++] = escape(argv[i]);
|
||||||
|
|
||||||
exec_argv[arg] = NULL;
|
exec_argv[arg] = NULL;
|
||||||
if (arg > max_arg) {
|
if (arg > max_arg) {
|
||||||
|
|||||||
Reference in new issue
Block a user