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

Unified Diff: samples/shell.cc

Issue 1111733002: [clang] Use -Wshorten-64-to-32 to enable warnings about 64bit to 32bit truncations. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix Win warnings. Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « samples/process.cc ('k') | src/base/platform/platform.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samples/shell.cc
diff --git a/samples/shell.cc b/samples/shell.cc
index 0ed742d3e368ffbb3d5b60e14020e542ab01fccb..a061aa469af8e52aff31c8ed58dc460caa57da5e 100644
--- a/samples/shell.cc
+++ b/samples/shell.cc
@@ -238,18 +238,21 @@ v8::Handle<v8::String> ReadFile(v8::Isolate* isolate, const char* name) {
if (file == NULL) return v8::Handle<v8::String>();
fseek(file, 0, SEEK_END);
- int size = ftell(file);
+ size_t size = ftell(file);
rewind(file);
char* chars = new char[size + 1];
chars[size] = '\0';
- for (int i = 0; i < size;) {
- int read = static_cast<int>(fread(&chars[i], 1, size - i, file));
- i += read;
+ for (size_t i = 0; i < size;) {
+ i += fread(&chars[i], 1, size - i, file);
+ if (ferror(file)) {
+ fclose(file);
+ return v8::Handle<v8::String>();
+ }
}
fclose(file);
- v8::Handle<v8::String> result =
- v8::String::NewFromUtf8(isolate, chars, v8::String::kNormalString, size);
+ v8::Handle<v8::String> result = v8::String::NewFromUtf8(
+ isolate, chars, v8::String::kNormalString, static_cast<int>(size));
delete[] chars;
return result;
}
« no previous file with comments | « samples/process.cc ('k') | src/base/platform/platform.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698