From 5723519be38287501aa4dd273a7ff907128b3407 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Mon, 11 Feb 2013 19:32:33 +0100 Subject: Dropped duplicate code for dom/io and io/ (Bug #1120585 ) (bzr r12118) --- src/io/gzipstream.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/io/gzipstream.cpp') diff --git a/src/io/gzipstream.cpp b/src/io/gzipstream.cpp index cbe29a41e..91b51140b 100644 --- a/src/io/gzipstream.cpp +++ b/src/io/gzipstream.cpp @@ -8,9 +8,22 @@ * Authors: * Bob Jamison * - * Copyright (C) 2004 Inkscape.org + * Copyright (C) 2004 * - * Released under GNU GPL, read the file 'COPYING' for more information + + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "gzipstream.h" -- cgit v1.2.3 From c8a761256b40300761c7ff6a0d642ac75b6f541a Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Mon, 11 Feb 2013 23:34:59 +0000 Subject: A couple of forward declarations (bzr r12119) --- src/io/gzipstream.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/io/gzipstream.cpp') diff --git a/src/io/gzipstream.cpp b/src/io/gzipstream.cpp index 91b51140b..f9e30de91 100644 --- a/src/io/gzipstream.cpp +++ b/src/io/gzipstream.cpp @@ -28,6 +28,7 @@ #include "gzipstream.h" #include +#include #include #include -- cgit v1.2.3 From 1c481ecbd68f2d67985729941fb26fb4bff3c60a Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Thu, 14 Feb 2013 07:55:49 +0100 Subject: fix warnings introduced in revision 12123 (bzr r12125) --- src/io/gzipstream.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/io/gzipstream.cpp') diff --git a/src/io/gzipstream.cpp b/src/io/gzipstream.cpp index f9e30de91..071179b48 100644 --- a/src/io/gzipstream.cpp +++ b/src/io/gzipstream.cpp @@ -433,7 +433,7 @@ void GzipOutputStream::flush() /** * Writes the specified byte to this output stream. */ -void GzipOutputStream::put(int ch) +void GzipOutputStream::put(gunichar ch) { if (closed) { -- cgit v1.2.3 From 1279e676eccb0b3786d21fd390e4965f78a003c1 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Sun, 3 Mar 2013 10:18:37 +0100 Subject: Preparation to merge /dom/io and /io code (bug #1120585 ) (bzr r12168) --- src/io/gzipstream.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/io/gzipstream.cpp') diff --git a/src/io/gzipstream.cpp b/src/io/gzipstream.cpp index 071179b48..8db7155db 100644 --- a/src/io/gzipstream.cpp +++ b/src/io/gzipstream.cpp @@ -433,19 +433,19 @@ void GzipOutputStream::flush() /** * Writes the specified byte to this output stream. */ -void GzipOutputStream::put(gunichar ch) +int GzipOutputStream::put(gunichar ch) { if (closed) { //probably throw an exception here - return; + return -1; } //Add char to buffer inputBuf.push_back(ch); totalIn++; - + return 1; } -- cgit v1.2.3 From 6a0dbf1a55aaa6dad63135c9a4f1294daa55a4f2 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Tue, 12 Mar 2013 18:51:03 +0100 Subject: cppcheck (bzr r12197) --- src/io/gzipstream.cpp | 67 +++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 34 deletions(-) (limited to 'src/io/gzipstream.cpp') 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(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(malloc(srcLen * sizeof(Byte))); if (!srcBuf) { return false; } - outputBuf = (unsigned char *)malloc(OUT_SIZE); + outputBuf = static_cast(malloc(OUT_SIZE)); if ( !outputBuf ) { free(srcBuf); srcBuf = 0; @@ -187,33 +187,35 @@ bool GzipInputStream::load() std::vector::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(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(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(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(malloc(srclen * sizeof(Byte))); if (!srcbuf) { return; } uLong destlen = srclen; - Bytef *destbuf = (Bytef *)malloc((destlen + (srclen/100) + 13) * sizeof(Byte)); + Bytef *destbuf = static_cast(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(srcbuf), srclen); - int zerr = compress(destbuf, (uLongf *)&destlen, srcbuf, srclen); + int zerr = compress(destbuf, static_cast(&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"); - } -- cgit v1.2.3 From 43d08fe814a052519421650df92da57ab91d391e Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Tue, 12 Mar 2013 19:45:10 +0100 Subject: c++ify (bzr r12198) --- src/io/gzipstream.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/io/gzipstream.cpp') diff --git a/src/io/gzipstream.cpp b/src/io/gzipstream.cpp index da8181ab4..380c42411 100644 --- a/src/io/gzipstream.cpp +++ b/src/io/gzipstream.cpp @@ -71,11 +71,11 @@ GzipInputStream::~GzipInputStream() { close(); if ( srcBuf ) { - free(srcBuf); + delete[] srcBuf; srcBuf = NULL; } if ( outputBuf ) { - free(outputBuf); + delete[] outputBuf; outputBuf = NULL; } } @@ -108,11 +108,11 @@ void GzipInputStream::close() } if ( srcBuf ) { - free(srcBuf); + delete[] srcBuf; srcBuf = NULL; } if ( outputBuf ) { - free(outputBuf); + delete[] outputBuf; outputBuf = NULL; } closed = true; @@ -171,15 +171,15 @@ bool GzipInputStream::load() } srcLen = inputBuf.size(); - srcBuf = static_cast(malloc(srcLen * sizeof(Byte))); + srcBuf = new Byte [srcLen]; if (!srcBuf) { return false; } - outputBuf = static_cast(malloc(OUT_SIZE)); + outputBuf = new unsigned char [OUT_SIZE]; if ( !outputBuf ) { - free(srcBuf); - srcBuf = 0; + delete[] srcBuf; + srcBuf = NULL; return false; } outputBufLen = 0; // Not filled in yet @@ -204,7 +204,7 @@ bool GzipInputStream::load() ////printf("val:%x\n", val); //flags - int flags = (int)srcBuf[3]; + int flags = static_cast(srcBuf[3]); ////time //val = (int)srcBuf[4]; @@ -386,17 +386,17 @@ void GzipOutputStream::flush() } uLong srclen = inputBuf.size(); - Bytef *srcbuf = static_cast(malloc(srclen * sizeof(Byte))); + Bytef *srcbuf = new Bytef [srclen]; if (!srcbuf) { return; } uLong destlen = srclen; - Bytef *destbuf = static_cast(malloc((destlen + (srclen/100) + 13) * sizeof(Byte))); + Bytef *destbuf = new Bytef [(destlen + (srclen/100) + 13)]; if (!destbuf) { - free(srcbuf); + delete[] srcbuf; return; } @@ -423,8 +423,8 @@ void GzipOutputStream::flush() destination.flush(); inputBuf.clear(); - free(srcbuf); - free(destbuf); + delete[] srcbuf; + delete[] destbuf; } -- cgit v1.2.3