Fix for issue 27567 (inconsistent handling of invalid -D options

BUG=#27567
R=rmacnak@google.com

Review URL: https://codereview.chromium.org/2409263004 .
This commit is contained in:
Siva Annamalai 2016-10-12 18:42:30 -07:00
parent 72503ff98d
commit aae051e4c3
3 changed files with 19 additions and 8 deletions

View file

@ -276,32 +276,32 @@ static bool ProcessEnvironmentOption(const char* arg,
ASSERT(arg != NULL);
if (*arg == '\0') {
// Ignore empty -D option.
Log::PrintErr("No arguments given to -D option\n");
Log::PrintErr("No arguments given to -D option, ignoring it\n");
return true;
}
if (environment == NULL) {
environment = new HashMap(&HashMap::SameStringValue, 4);
}
// Split the name=value part of the -Dname=value argument.
const char* equals_pos = strchr(arg, '=');
if (equals_pos == NULL) {
// No equal sign (name without value) currently not supported.
Log::PrintErr("No value given to -D option\n");
return false;
Log::PrintErr("No value given in -D%s option, ignoring it\n", arg);
return true;
}
char* name;
char* value = NULL;
int name_len = equals_pos - arg;
if (name_len == 0) {
Log::PrintErr("No name given to -D option\n");
return false;
Log::PrintErr("No name given in -D%s option, ignoring it\n", arg);
return true;
}
// Split name=value into name and value.
name = reinterpret_cast<char*>(malloc(name_len + 1));
strncpy(name, arg, name_len);
name[name_len] = '\0';
value = strdup(equals_pos + 1);
if (environment == NULL) {
environment = new HashMap(&HashMap::SameStringValue, 4);
}
HashMap::Entry* entry = environment->Lookup(
GetHashmapKeyFromString(name), HashMap::StringHash(name), true);
ASSERT(entry != NULL); // Lookup adds an entry if key not found.

View file

@ -0,0 +1,10 @@
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// SharedOptions=-Dvar -D -D=var -Dvar=invalid -Dvar=valid -Dvar
import "package:expect/expect.dart";
main() {
Expect.equals('valid', const String.fromEnvironment('var'));
}

View file

@ -25,6 +25,7 @@ packages_file_test: Skip # Uses Platform.executable
[ ($runtime != vm && $runtime != dart_precompiled && $runtime != dart_app) && ($runtime != drt || $compiler != none)) ]
no_assert_test: Fail, OK # This is testing a vm flag.
env_test: Skip # This is testing a vm command line parsing scenario.
[ ($runtime == vm || $runtime == dart_precompiled || $runtime == dart_app) ]
package/package_isolate_test: Fail # Issue 12474