Commit 6e485f13 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

msvcrt: NULL terminate program arguments list in __getmainargs.

parent 04fb8a91
......@@ -424,7 +424,7 @@ static int build_expanded_argv(int *argc, char **argv)
len = strlen(data.cFileName)+1;
if(argv) {
argv[args_no] = (char*)(argv+*argc)+size;
argv[args_no] = (char*)(argv+*argc+1)+size;
memcpy(argv[args_no], __wine_main_argv[i], path_len*sizeof(char));
memcpy(argv[args_no]+path_len, data.cFileName, len*sizeof(char));
}
......@@ -437,7 +437,7 @@ static int build_expanded_argv(int *argc, char **argv)
if(!len) {
len = strlen(__wine_main_argv[i])+1;
if(argv) {
argv[args_no] = (char*)(argv+*argc)+size;
argv[args_no] = (char*)(argv+*argc+1)+size;
memcpy(argv[args_no], __wine_main_argv[i], len*sizeof(char));
}
args_no++;
......@@ -445,7 +445,9 @@ static int build_expanded_argv(int *argc, char **argv)
}
}
size += args_no*sizeof(char*);
if(argv)
argv[args_no] = NULL;
size += (args_no+1)*sizeof(char*);
*argc = args_no;
return size;
}
......@@ -519,7 +521,7 @@ static int build_expanded_wargv(int *argc, MSVCRT_wchar_t **argv)
len = strlenW(data.cFileName)+1;
if(argv) {
argv[args_no] = (MSVCRT_wchar_t*)(argv+*argc)+size;
argv[args_no] = (MSVCRT_wchar_t*)(argv+*argc+1)+size;
memcpy(argv[args_no], __wine_main_wargv[i], path_len*sizeof(MSVCRT_wchar_t));
memcpy(argv[args_no]+path_len, data.cFileName, len*sizeof(MSVCRT_wchar_t));
}
......@@ -532,7 +534,7 @@ static int build_expanded_wargv(int *argc, MSVCRT_wchar_t **argv)
if(!len) {
len = strlenW(__wine_main_wargv[i])+1;
if(argv) {
argv[args_no] = (MSVCRT_wchar_t*)(argv+*argc)+size;
argv[args_no] = (MSVCRT_wchar_t*)(argv+*argc+1)+size;
memcpy(argv[args_no], __wine_main_wargv[i], len*sizeof(MSVCRT_wchar_t));
}
args_no++;
......@@ -540,8 +542,10 @@ static int build_expanded_wargv(int *argc, MSVCRT_wchar_t **argv)
}
}
if(argv)
argv[args_no] = NULL;
size *= sizeof(MSVCRT_wchar_t);
size += args_no*sizeof(MSVCRT_wchar_t*);
size += (args_no+1)*sizeof(MSVCRT_wchar_t*);
*argc = args_no;
return size;
}
......
......@@ -146,6 +146,7 @@ static void test___getmainargs(void)
ok(!strcmp(argv[2], filepath), "argv[2] = %s\n", argv[2]);
sprintf(filepath, "%swine_test/*", tmppath);
ok(!strcmp(argv[3], filepath), "argv[3] = %s\n", argv[3]);
ok(!argv[4], "argv[4] != NULL\n");
if(p___p___argc && p___p___argv) {
new_argc = *p___p___argc();
......@@ -172,6 +173,7 @@ static void test___getmainargs(void)
sprintf(filepath, "%swine_test/test", tmppath);
ok(!strcmp(argv[3], filepath), "argv[3] = %s\n", argv[3]);
}
ok(!argv[5], "argv[5] != NULL\n");
if(p___p___argc && p___p___argv) {
new_argc = *p___p___argc();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment