From 32f1d458677bdf0e03fa45e089982292d7f96838 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 14 May 2008 19:57:12 +0000 Subject: [PATCH] * 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 --- src/kits/app/Application.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/kits/app/Application.cpp b/src/kits/app/Application.cpp index d9c57ea778..f9cf24eb92 100644 --- a/src/kits/app/Application.cpp +++ b/src/kits/app/Application.cpp @@ -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];