From 7005b65901f2ca8af207c3b7faf61cb39b7a19d9 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 23 May 2017 15:10:39 +0200 Subject: [PATCH] Check that 'M/Counter' exists before trying to read it. Some old zim files may not have a 'Counter` metadata article. We have to handle this correctly. --- src/reader.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/reader.cpp b/src/reader.cpp index 39fd8d901..bfd3e78b8 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -103,15 +103,17 @@ namespace kiwix { zim::Article article = this->zimFileHandler->getArticle('M',"Counter"); - stringstream ssContent(article.getData()); + if ( article.good() ) { + stringstream ssContent(article.getData()); - while(getline(ssContent, item, ';')) { - stringstream ssItem(item); - getline(ssItem, mimeType, '='); - getline(ssItem, counterString, '='); - if (!counterString.empty() && !mimeType.empty()) { - sscanf(counterString.c_str(), "%u", &counter); - counters.insert(pair(mimeType, counter)); + while(getline(ssContent, item, ';')) { + stringstream ssItem(item); + getline(ssItem, mimeType, '='); + getline(ssItem, counterString, '='); + if (!counterString.empty() && !mimeType.empty()) { + sscanf(counterString.c_str(), "%u", &counter); + counters.insert(pair(mimeType, counter)); + } } }