Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: runtime/bin/main.cc

Issue 2409263004: Fix for issue 27567 (inconsistent handling of invalid -D options (Closed)
Patch Set: Address code review comments. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests/standalone/env_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include <stdlib.h> 5 #include <stdlib.h>
6 #include <string.h> 6 #include <string.h>
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "include/dart_api.h" 9 #include "include/dart_api.h"
10 #include "include/dart_tools_api.h" 10 #include "include/dart_tools_api.h"
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 } 269 }
270 return false; 270 return false;
271 } 271 }
272 272
273 273
274 static bool ProcessEnvironmentOption(const char* arg, 274 static bool ProcessEnvironmentOption(const char* arg,
275 CommandLineOptions* vm_options) { 275 CommandLineOptions* vm_options) {
276 ASSERT(arg != NULL); 276 ASSERT(arg != NULL);
277 if (*arg == '\0') { 277 if (*arg == '\0') {
278 // Ignore empty -D option. 278 // Ignore empty -D option.
279 Log::PrintErr("No arguments given to -D option\n"); 279 Log::PrintErr("No arguments given to -D option, ignoring it\n");
280 return true; 280 return true;
281 } 281 }
282 if (environment == NULL) {
283 environment = new HashMap(&HashMap::SameStringValue, 4);
284 }
285 // Split the name=value part of the -Dname=value argument. 282 // Split the name=value part of the -Dname=value argument.
286 const char* equals_pos = strchr(arg, '='); 283 const char* equals_pos = strchr(arg, '=');
287 if (equals_pos == NULL) { 284 if (equals_pos == NULL) {
288 // No equal sign (name without value) currently not supported. 285 // No equal sign (name without value) currently not supported.
289 Log::PrintErr("No value given to -D option\n"); 286 Log::PrintErr("No value given in -D%s option, ignoring it\n", arg);
290 return false; 287 return true;
291 } 288 }
292 289
293 char* name; 290 char* name;
294 char* value = NULL; 291 char* value = NULL;
295 int name_len = equals_pos - arg; 292 int name_len = equals_pos - arg;
296 if (name_len == 0) { 293 if (name_len == 0) {
297 Log::PrintErr("No name given to -D option\n"); 294 Log::PrintErr("No name given in -D%s option, ignoring it\n", arg);
298 return false; 295 return true;
299 } 296 }
300 // Split name=value into name and value. 297 // Split name=value into name and value.
301 name = reinterpret_cast<char*>(malloc(name_len + 1)); 298 name = reinterpret_cast<char*>(malloc(name_len + 1));
302 strncpy(name, arg, name_len); 299 strncpy(name, arg, name_len);
303 name[name_len] = '\0'; 300 name[name_len] = '\0';
304 value = strdup(equals_pos + 1); 301 value = strdup(equals_pos + 1);
302 if (environment == NULL) {
303 environment = new HashMap(&HashMap::SameStringValue, 4);
304 }
305 HashMap::Entry* entry = environment->Lookup( 305 HashMap::Entry* entry = environment->Lookup(
306 GetHashmapKeyFromString(name), HashMap::StringHash(name), true); 306 GetHashmapKeyFromString(name), HashMap::StringHash(name), true);
307 ASSERT(entry != NULL); // Lookup adds an entry if key not found. 307 ASSERT(entry != NULL); // Lookup adds an entry if key not found.
308 if (entry->value != NULL) { 308 if (entry->value != NULL) {
309 free(name); 309 free(name);
310 free(entry->value); 310 free(entry->value);
311 } 311 }
312 entry->value = value; 312 entry->value = value;
313 return true; 313 return true;
314 } 314 }
(...skipping 1583 matching lines...) Expand 10 before | Expand all | Expand 10 after
1898 Platform::Exit(Process::GlobalExitCode()); 1898 Platform::Exit(Process::GlobalExitCode());
1899 } 1899 }
1900 1900
1901 } // namespace bin 1901 } // namespace bin
1902 } // namespace dart 1902 } // namespace dart
1903 1903
1904 int main(int argc, char** argv) { 1904 int main(int argc, char** argv) {
1905 dart::bin::main(argc, argv); 1905 dart::bin::main(argc, argv);
1906 UNREACHABLE(); 1906 UNREACHABLE();
1907 } 1907 }
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/env_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698