mirror of https://github.com/kiwix/libkiwix.git
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.
This commit is contained in:
parent
d360b9143c
commit
7005b65901
|
@ -103,15 +103,17 @@ namespace kiwix {
|
||||||
|
|
||||||
zim::Article article = this->zimFileHandler->getArticle('M',"Counter");
|
zim::Article article = this->zimFileHandler->getArticle('M',"Counter");
|
||||||
|
|
||||||
stringstream ssContent(article.getData());
|
if ( article.good() ) {
|
||||||
|
stringstream ssContent(article.getData());
|
||||||
|
|
||||||
while(getline(ssContent, item, ';')) {
|
while(getline(ssContent, item, ';')) {
|
||||||
stringstream ssItem(item);
|
stringstream ssItem(item);
|
||||||
getline(ssItem, mimeType, '=');
|
getline(ssItem, mimeType, '=');
|
||||||
getline(ssItem, counterString, '=');
|
getline(ssItem, counterString, '=');
|
||||||
if (!counterString.empty() && !mimeType.empty()) {
|
if (!counterString.empty() && !mimeType.empty()) {
|
||||||
sscanf(counterString.c_str(), "%u", &counter);
|
sscanf(counterString.c_str(), "%u", &counter);
|
||||||
counters.insert(pair<string, int>(mimeType, counter));
|
counters.insert(pair<string, int>(mimeType, counter));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue