diff options
| author | Kris De Gussem <kris.degussem@gmail.com> | 2013-03-12 17:51:03 +0000 |
|---|---|---|
| committer | Kris <Kris.De.Gussem@hotmail.com> | 2013-03-12 17:51:03 +0000 |
| commit | 6a0dbf1a55aaa6dad63135c9a4f1294daa55a4f2 (patch) | |
| tree | ea0931b6153b5b08c36dbe50ec4a5ad51b35cf01 /src/io/gzipstream.cpp | |
| parent | Further migration to Gtk::Grid (diff) | |
| download | inkscape-6a0dbf1a55aaa6dad63135c9a4f1294daa55a4f2.tar.gz inkscape-6a0dbf1a55aaa6dad63135c9a4f1294daa55a4f2.zip | |
cppcheck
(bzr r12197)
Diffstat (limited to 'src/io/gzipstream.cpp')
| -rw-r--r-- | src/io/gzipstream.cpp | 67 |
1 files changed, 33 insertions, 34 deletions
diff --git a/src/io/gzipstream.cpp b/src/io/gzipstream.cpp index 8db7155db..da8181ab4 100644 --- a/src/io/gzipstream.cpp +++ b/src/io/gzipstream.cpp @@ -161,7 +161,7 @@ bool GzipInputStream::load() int ch = source.get(); if (ch<0) break; - inputBuf.push_back((Byte)(ch & 0xff)); + inputBuf.push_back(static_cast<Byte>(ch & 0xff)); } long inputBufLen = inputBuf.size(); @@ -171,12 +171,12 @@ bool GzipInputStream::load() } srcLen = inputBuf.size(); - srcBuf = (Bytef *)malloc(srcLen * sizeof(Byte)); + srcBuf = static_cast<Bytef *>(malloc(srcLen * sizeof(Byte))); if (!srcBuf) { return false; } - outputBuf = (unsigned char *)malloc(OUT_SIZE); + outputBuf = static_cast<unsigned char *>(malloc(OUT_SIZE)); if ( !outputBuf ) { free(srcBuf); srcBuf = 0; @@ -187,33 +187,35 @@ bool GzipInputStream::load() std::vector<unsigned char>::iterator iter; Bytef *p = srcBuf; for (iter=inputBuf.begin() ; iter != inputBuf.end() ; ++iter) + { *p++ = *iter; + } int headerLen = 10; //Magic - int val = (int)srcBuf[0]; - //printf("val:%x\n", val); - val = (int)srcBuf[1]; - //printf("val:%x\n", val); + //int val = (int)srcBuf[0]; + ////printf("val:%x\n", val); + //val = (int)srcBuf[1]; + ////printf("val:%x\n", val); - //Method - val = (int)srcBuf[2]; - //printf("val:%x\n", val); + ////Method + //val = (int)srcBuf[2]; + ////printf("val:%x\n", val); //flags int flags = (int)srcBuf[3]; - //time - val = (int)srcBuf[4]; - val = (int)srcBuf[5]; - val = (int)srcBuf[6]; - val = (int)srcBuf[7]; + ////time + //val = (int)srcBuf[4]; + //val = (int)srcBuf[5]; + //val = (int)srcBuf[6]; + //val = (int)srcBuf[7]; - //xflags - val = (int)srcBuf[8]; - //OS - val = (int)srcBuf[9]; + ////xflags + //val = (int)srcBuf[8]; + ////OS + //val = (int)srcBuf[9]; // if ( flags & FEXTRA ) { // headerLen += 2; @@ -272,19 +274,17 @@ bool GzipInputStream::load() int GzipInputStream::fetchMore() { - int zerr = Z_OK; - // TODO assumes we aren't called till the buffer is empty d_stream.next_out = outputBuf; d_stream.avail_out = OUT_SIZE; outputBufLen = 0; outputBufPos = 0; - zerr = inflate( &d_stream, Z_SYNC_FLUSH ); + int zerr = inflate( &d_stream, Z_SYNC_FLUSH ); if ( zerr == Z_OK || zerr == Z_STREAM_END ) { outputBufLen = OUT_SIZE - d_stream.avail_out; if ( outputBufLen ) { - crc = crc32(crc, (const Bytef *)outputBuf, outputBufLen); + crc = crc32(crc, const_cast<const Bytef *>(outputBuf), outputBufLen); } //printf("crc:%lx\n", crc); // } else if ( zerr != Z_STREAM_END ) { @@ -359,14 +359,14 @@ void GzipOutputStream::close() uLong outlong = crc; for (int n = 0; n < 4; n++) { - destination.put((int)(outlong & 0xff)); + destination.put(static_cast<gunichar>(outlong & 0xff)); outlong >>= 8; } //# send the file length outlong = totalIn & 0xffffffffL; for (int n = 0; n < 4; n++) { - destination.put((int)(outlong & 0xff)); + destination.put(static_cast<gunichar>(outlong & 0xff)); outlong >>= 8; } @@ -380,18 +380,20 @@ void GzipOutputStream::close() */ void GzipOutputStream::flush() { - if (closed || inputBuf.size()<1) + if (closed || inputBuf.empty()) + { return; - + } + uLong srclen = inputBuf.size(); - Bytef *srcbuf = (Bytef *)malloc(srclen * sizeof(Byte)); + Bytef *srcbuf = static_cast<Bytef *>(malloc(srclen * sizeof(Byte))); if (!srcbuf) { return; } uLong destlen = srclen; - Bytef *destbuf = (Bytef *)malloc((destlen + (srclen/100) + 13) * sizeof(Byte)); + Bytef *destbuf = static_cast<Bytef *>(malloc((destlen + (srclen/100) + 13) * sizeof(Byte))); if (!destbuf) { free(srcbuf); @@ -403,9 +405,9 @@ void GzipOutputStream::flush() for (iter=inputBuf.begin() ; iter != inputBuf.end() ; ++iter) *p++ = *iter; - crc = crc32(crc, (const Bytef *)srcbuf, srclen); + crc = crc32(crc, const_cast<const Bytef *>(srcbuf), srclen); - int zerr = compress(destbuf, (uLongf *)&destlen, srcbuf, srclen); + int zerr = compress(destbuf, static_cast<uLongf *>(&destlen), srcbuf, srclen); if (zerr != Z_OK) { printf("Some kind of problem\n"); @@ -423,9 +425,6 @@ void GzipOutputStream::flush() inputBuf.clear(); free(srcbuf); free(destbuf); - - //printf("done\n"); - } |
