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

Side by Side Diff: samples/shell.cc

Issue 290453003: Avoid memset(NULL, ...). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | src/d8.cc » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 v8::Handle<v8::String> ReadFile(v8::Isolate* isolate, const char* name); 61 v8::Handle<v8::String> ReadFile(v8::Isolate* isolate, const char* name);
62 void ReportException(v8::Isolate* isolate, v8::TryCatch* handler); 62 void ReportException(v8::Isolate* isolate, v8::TryCatch* handler);
63 63
64 64
65 static bool run_shell; 65 static bool run_shell;
66 66
67 67
68 class ShellArrayBufferAllocator : public v8::ArrayBuffer::Allocator { 68 class ShellArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
69 public: 69 public:
70 virtual void* Allocate(size_t length) { 70 virtual void* Allocate(size_t length) {
71 return memset(AllocateUninitialized(length), 0, length); 71 void* data = AllocateUninitialized(length);
72 return data == NULL ? data : memset(data, 0, length);
72 } 73 }
73 virtual void* AllocateUninitialized(size_t length) { return malloc(length); } 74 virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
74 virtual void Free(void* data, size_t) { free(data); } 75 virtual void Free(void* data, size_t) { free(data); }
75 }; 76 };
76 77
77 78
78 int main(int argc, char* argv[]) { 79 int main(int argc, char* argv[]) {
79 v8::V8::InitializeICU(); 80 v8::V8::InitializeICU();
80 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); 81 v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
81 ShellArrayBufferAllocator array_buffer_allocator; 82 ShellArrayBufferAllocator array_buffer_allocator;
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 fprintf(stderr, "^"); 376 fprintf(stderr, "^");
376 } 377 }
377 fprintf(stderr, "\n"); 378 fprintf(stderr, "\n");
378 v8::String::Utf8Value stack_trace(try_catch->StackTrace()); 379 v8::String::Utf8Value stack_trace(try_catch->StackTrace());
379 if (stack_trace.length() > 0) { 380 if (stack_trace.length() > 0) {
380 const char* stack_trace_string = ToCString(stack_trace); 381 const char* stack_trace_string = ToCString(stack_trace);
381 fprintf(stderr, "%s\n", stack_trace_string); 382 fprintf(stderr, "%s\n", stack_trace_string);
382 } 383 }
383 } 384 }
384 } 385 }
OLDNEW
« no previous file with comments | « no previous file | src/d8.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698