From 90994464a59dbd3bc8313ac99201fcd872937522 Mon Sep 17 00:00:00 2001 From: Michael Grupp Date: Thu, 22 Feb 2018 16:21:15 +0100 Subject: [PATCH] Check ifstream::good() in proto_stream.cc (#929) Check for basic stream errors before doing more involved read actions. The log message in this case is also more descriptive than `Check failed: reader->ReadProto(&pose_graph)`. --- cartographer/io/proto_stream.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cartographer/io/proto_stream.cc b/cartographer/io/proto_stream.cc index 790dd66..f55a3a6 100644 --- a/cartographer/io/proto_stream.cc +++ b/cartographer/io/proto_stream.cc @@ -15,6 +15,7 @@ */ #include "cartographer/io/proto_stream.h" +#include "glog/logging.h" namespace cartographer { namespace io { @@ -71,6 +72,7 @@ ProtoStreamReader::ProtoStreamReader(const std::string& filename) if (!ReadSizeAsLittleEndian(&in_, &magic) || magic != kMagic) { in_.setstate(std::ios::failbit); } + CHECK(in_.good()) << "Failed to open proto stream '" << filename << "'."; } bool ProtoStreamReader::Read(std::string* decompressed_data) {