Improve error messages for zlib decompression errors

This commit is contained in:
Rogier 2014-05-08 09:55:45 +02:00
parent 21b9ffe0a1
commit d5b3b2a7da
3 changed files with 9 additions and 3 deletions

View File

@ -49,7 +49,7 @@ ustring ZlibDecompressor::decompress()
strm.avail_in = size; strm.avail_in = size;
if (inflateInit(&strm) != Z_OK) { if (inflateInit(&strm) != Z_OK) {
throw DecompressError(); throw DecompressError(strm.msg);
} }
strm.next_in = const_cast<unsigned char *>(data); strm.next_in = const_cast<unsigned char *>(data);
@ -61,7 +61,7 @@ ustring ZlibDecompressor::decompress()
buffer += ustring(reinterpret_cast<unsigned char *>(temp_buffer), BUFSIZE - strm.avail_out); buffer += ustring(reinterpret_cast<unsigned char *>(temp_buffer), BUFSIZE - strm.avail_out);
} while (ret == Z_OK); } while (ret == Z_OK);
if (ret != Z_STREAM_END) { if (ret != Z_STREAM_END) {
throw DecompressError(); throw DecompressError(strm.msg);
} }
m_seekPos += strm.next_in - data; m_seekPos += strm.next_in - data;
(void)inflateEnd(&strm); (void)inflateEnd(&strm);

View File

@ -18,7 +18,9 @@
class ZlibDecompressor class ZlibDecompressor
{ {
public: public:
class DecompressError { struct DecompressError {
DecompressError(std::string m = "(unknown error)") : message(m) {}
const std::string message;
}; };
ZlibDecompressor(const unsigned char *data, std::size_t size); ZlibDecompressor(const unsigned char *data, std::size_t size);

View File

@ -15,6 +15,7 @@
#include <sstream> #include <sstream>
#include <stdexcept> #include <stdexcept>
#include "TileGenerator.h" #include "TileGenerator.h"
#include "ZlibDecompressor.h"
using namespace std; using namespace std;
@ -379,6 +380,9 @@ int main(int argc, char *argv[])
} catch(std::runtime_error e) { } catch(std::runtime_error e) {
std::cout<<"Exception: "<<e.what()<<std::endl; std::cout<<"Exception: "<<e.what()<<std::endl;
return 1; return 1;
} catch(ZlibDecompressor::DecompressError e) {
std::cout<<"Block decompression failure: "<<e.message<<std::endl;
return 1;
} }
return 0; return 0;
} }