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

Unified Diff: base/files/file_util.cc

Issue 640373006: Don't use 64KB of stack on a single call. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/master
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/files/file_util.cc
diff --git a/base/files/file_util.cc b/base/files/file_util.cc
index 17b596946baadcd59928e4ce179c9b0aa25348b8..e60dcd9d346df70f5387051a072bcc8389eaf590 100644
--- a/base/files/file_util.cc
+++ b/base/files/file_util.cc
@@ -139,16 +139,17 @@ bool ReadFileToString(const FilePath& path,
return false;
}
- char buf[1 << 16];
+ const size_t kBufferSize = 1 << 16;
+ scoped_ptr<char[]> buf(new char[kBufferSize]);
size_t len;
size_t size = 0;
bool read_status = true;
// Many files supplied in |path| have incorrect size (proc files etc).
// Hence, the file is read sequentially as opposed to a one-shot read.
- while ((len = fread(buf, 1, sizeof(buf), file)) > 0) {
+ while ((len = fread(buf.get(), 1, kBufferSize, file)) > 0) {
if (contents)
- contents->append(buf, std::min(len, max_size - size));
+ contents->append(buf.get(), std::min(len, max_size - size));
if ((max_size - size) < len) {
read_status = false;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698