* Reworked James Woodcock/stippi's patch a bit: since the remaining entries
are NULL pointers anyway, we just adjust argc. * Made argv processing more safe, it will now check if the allocation of the argv array succeeded in the first place. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25496 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
9765d74881
commit
32f1d45867
@ -1424,8 +1424,9 @@ BApplication::_ArgvReceived(BMessage *message)
|
||||
char **argv = NULL;
|
||||
if (message->FindInt32("argc", &argc) == B_OK && argc > 0) {
|
||||
// allocate a NULL terminated array
|
||||
argv = new char*[argc + 1];
|
||||
memset(argv, 0, sizeof(char*) * (argc + 1));
|
||||
argv = new(std::nothrow) char*[argc + 1];
|
||||
if (argv == NULL)
|
||||
return;
|
||||
|
||||
// copy the arguments
|
||||
for (int32 i = 0; error == B_OK && i < argc; i++) {
|
||||
@ -1435,8 +1436,11 @@ BApplication::_ArgvReceived(BMessage *message)
|
||||
argv[i] = strdup(arg);
|
||||
if (argv[i] == NULL)
|
||||
error = B_NO_MEMORY;
|
||||
}
|
||||
} else
|
||||
argc = i;
|
||||
}
|
||||
|
||||
argv[argc] = NULL;
|
||||
}
|
||||
|
||||
// call the hook
|
||||
@ -1562,8 +1566,10 @@ fill_argv_message(BMessage &message)
|
||||
message.AddInt32("argc", argc);
|
||||
|
||||
// add argv
|
||||
for (int32 i = 0; i < argc; i++)
|
||||
message.AddString("argv", argv[i]);
|
||||
for (int32 i = 0; i < argc; i++) {
|
||||
if (argv[i] != NULL)
|
||||
message.AddString("argv", argv[i]);
|
||||
}
|
||||
|
||||
// add current working directory
|
||||
char cwd[B_PATH_NAME_LENGTH];
|
||||
|
Loading…
x
Reference in New Issue
Block a user