diff options
author | Maxim Kalaev <maximus.ka@gmail.com> | 2013-07-01 18:33:12 (GMT) |
---|---|---|
committer | Maxim Kalaev <maximus.ka@gmail.com> | 2013-07-01 18:33:12 (GMT) |
commit | 4cc869a7c99227749ff98d4449420d393958c53a (patch) | |
tree | 54bddca7dfe959e624db663cf1e8588908476f12 /src/deps_log.cc | |
parent | c8ac05c871a22cdd3b41ab76e72544524cedafae (diff) | |
download | Ninja-4cc869a7c99227749ff98d4449420d393958c53a.zip Ninja-4cc869a7c99227749ff98d4449420d393958c53a.tar.gz Ninja-4cc869a7c99227749ff98d4449420d393958c53a.tar.bz2 |
Adding error checking on fwrite/fflush in deps_log
Diffstat (limited to 'src/deps_log.cc')
-rw-r--r-- | src/deps_log.cc | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/src/deps_log.cc b/src/deps_log.cc index ce9bf06..b172d4b 100644 --- a/src/deps_log.cc +++ b/src/deps_log.cc @@ -70,8 +70,10 @@ bool DepsLog::OpenForWrite(const string& path, string* err) { return false; } } - fflush(file_); - + if (fflush(file_) != 0) { + *err = strerror(errno); + return false; + } return true; } @@ -88,12 +90,14 @@ bool DepsLog::RecordDeps(Node* node, TimeStamp mtime, // Assign ids to all nodes that are missing one. if (node->id() < 0) { - RecordId(node); + if (!RecordId(node)) + return false; made_change = true; } for (int i = 0; i < node_count; ++i) { if (nodes[i]->id() < 0) { - RecordId(nodes[i]); + if (!RecordId(nodes[i])) + return false; made_change = true; } } @@ -122,16 +126,21 @@ bool DepsLog::RecordDeps(Node* node, TimeStamp mtime, // Update on-disk representation. uint16_t size = 4 * (1 + 1 + (uint16_t)node_count); size |= 0x8000; // Deps record: set high bit. - fwrite(&size, 2, 1, file_); + if (fwrite(&size, 2, 1, file_) < 1) + return false; int id = node->id(); - fwrite(&id, 4, 1, file_); + if (fwrite(&id, 4, 1, file_) < 1) + return false; int timestamp = mtime; - fwrite(×tamp, 4, 1, file_); + if (fwrite(×tamp, 4, 1, file_) < 1) + return false; for (int i = 0; i < node_count; ++i) { id = nodes[i]->id(); - fwrite(&id, 4, 1, file_); + if (fwrite(&id, 4, 1, file_) < 1) + return false; } - fflush(file_); + if (fflush(file_) != 0) + return false; // Update in-memory representation. Deps* deps = new Deps(mtime, node_count); @@ -324,9 +333,12 @@ bool DepsLog::UpdateDeps(int out_id, Deps* deps) { bool DepsLog::RecordId(Node* node) { uint16_t size = (uint16_t)node->path().size(); - fwrite(&size, 2, 1, file_); - fwrite(node->path().data(), node->path().size(), 1, file_); - fflush(file_); + if (fwrite(&size, 2, 1, file_) < 1) + return false; + if (fwrite(node->path().data(), node->path().size(), 1, file_) < 1) + return false; // assuming node->path().size() > 0 + if (fflush(file_) != 0) + return false; node->set_id(nodes_.size()); nodes_.push_back(node); |