From 9d421d93f7b74b598fa6bf251e45f03bf06cc8eb Mon Sep 17 00:00:00 2001 From: stephena Date: Tue, 7 May 2013 14:44:50 +0000 Subject: [PATCH] Added better error messages for reading missing/zero-byte/invalid ROM files, and update ZLIB to latest version (1.2.8). git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2723 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- Changes.txt | 5 +-- src/common/FSNodeZIP.cxx | 6 ++-- src/common/FSNodeZIP.hxx | 8 ++--- src/common/ZipHandler.cxx | 28 +++++++++++++---- src/common/ZipHandler.hxx | 5 +-- src/common/mainSDL.cxx | 13 ++++---- src/emucore/FSNode.cxx | 22 +++++++++++--- src/emucore/FSNode.hxx | 14 +++++---- src/emucore/MD5.cxx | 8 ++++- src/emucore/OSystem.cxx | 55 +++++++++++++++++---------------- src/emucore/OSystem.hxx | 6 ++-- src/gui/LauncherDialog.cxx | 10 +++--- src/zlib/README | 24 +++++++-------- src/zlib/compress.c | 2 +- src/zlib/deflate.c | 12 +++++--- src/zlib/deflate.h | 2 +- src/zlib/gzguts.h | 22 ++++++++++++-- src/zlib/gzlib.c | 32 ++++++++++++++------ src/zlib/gzread.c | 13 +++++--- src/zlib/gzwrite.c | 60 +++++++++++++++++++++--------------- src/zlib/infback.c | 2 +- src/zlib/inffast.c | 6 ++-- src/zlib/inflate.c | 62 ++++++++++++++++++++++++-------------- src/zlib/inftrees.c | 14 ++++----- src/zlib/trees.c | 14 +++++---- src/zlib/uncompr.c | 2 +- src/zlib/zconf.h | 36 +++++++++++++--------- src/zlib/zlib.h | 48 +++++++++++++++++++++-------- src/zlib/zutil.c | 2 +- src/zlib/zutil.h | 9 +++--- 30 files changed, 341 insertions(+), 201 deletions(-) diff --git a/Changes.txt b/Changes.txt index 9c26a9ffc..19ec73898 100644 --- a/Changes.txt +++ b/Changes.txt @@ -41,7 +41,8 @@ a label in the case where it occurred in the middle of the data. * Fixed regression in handling ZIP files (as compared to version 3.7.5) - created with newer versions of the ZIP program. + created with newer versions of the ZIP program. Related to this, added + better error messages for invalid/missing/unreadable ROM files. * Fixed bug in Linux/OSX versions when starting Stella for the first time; it was previously creating mislabeled directories to store @@ -62,7 +63,7 @@ menus in the UI; they can now be navigated more fully by the keyboard and mouse. - * Updated included PNG library to latest stable version. + * Updated included PNG and ZLIB libraries to latest stable version. -Have fun! diff --git a/src/common/FSNodeZIP.cxx b/src/common/FSNodeZIP.cxx index 1ff9ea37b..105b82cfe 100644 --- a/src/common/FSNodeZIP.cxx +++ b/src/common/FSNodeZIP.cxx @@ -133,10 +133,10 @@ bool FilesystemNodeZIP::getChildren(AbstractFSList& myList, ListMode mode, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool FilesystemNodeZIP::read(uInt8*& image, uInt32& size) const +uInt32 FilesystemNodeZIP::read(uInt8*& image) const { if(!_isValid) - return false; + throw "ZIP file not found/readable"; ZipHandler& zip = OSystem::zip(_zipFile); @@ -144,7 +144,7 @@ bool FilesystemNodeZIP::read(uInt8*& image, uInt32& size) const while(zip.hasNext() && !found) found = zip.next() == _virtualFile; - return found ? zip.decompress(image, size) : false; + return found ? zip.decompress(image) : 0; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/common/FSNodeZIP.hxx b/src/common/FSNodeZIP.hxx index 695a78068..e81113632 100644 --- a/src/common/FSNodeZIP.hxx +++ b/src/common/FSNodeZIP.hxx @@ -51,15 +51,15 @@ class FilesystemNodeZIP : public AbstractFSNode */ FilesystemNodeZIP(const string& path); - bool exists() const { return _realNode->exists(); } + bool exists() const { return _realNode && _realNode->exists(); } const string& getName() const { return _virtualFile; } const string& getPath() const { return _path; } string getShortPath() const { return _shortPath; } bool isDirectory() const { return _numFiles > 1; } bool isFile() const { return _numFiles == 1; } - bool isReadable() const { return _realNode->isReadable(); } + bool isReadable() const { return _realNode && _realNode->isReadable(); } bool isWritable() const { return false; } - bool isAbsolute() const { return _realNode->isAbsolute(); } + bool isAbsolute() const { return _realNode && _realNode->isAbsolute(); } ////////////////////////////////////////////////////////// // For now, ZIP files cannot be modified in any way @@ -70,7 +70,7 @@ class FilesystemNodeZIP : public AbstractFSNode bool getChildren(AbstractFSList& list, ListMode mode, bool hidden) const; AbstractFSNode* getParent() const; - bool read(uInt8*& image, uInt32& size) const; + uInt32 read(uInt8*& image) const; private: FilesystemNodeZIP(const string& zipfile, const string& virtualfile, diff --git a/src/common/ZipHandler.cxx b/src/common/ZipHandler.cxx index e9dbbe72d..3cbb3fbae 100644 --- a/src/common/ZipHandler.cxx +++ b/src/common/ZipHandler.cxx @@ -87,22 +87,38 @@ string ZipHandler::next() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool ZipHandler::decompress(uInt8*& image, uInt32& length) +uInt32 ZipHandler::decompress(uInt8*& image) { + static const char* zip_error_s[] = { + "ZIPERR_NONE", + "ZIPERR_OUT_OF_MEMORY", + "ZIPERR_FILE_ERROR", + "ZIPERR_BAD_SIGNATURE", + "ZIPERR_DECOMPRESS_ERROR", + "ZIPERR_FILE_TRUNCATED", + "ZIPERR_FILE_CORRUPT", + "ZIPERR_UNSUPPORTED", + "ZIPERR_BUFFER_TOO_SMALL" + }; + if(myZip) { - length = myZip->header.uncompressed_length; + uInt32 length = myZip->header.uncompressed_length; image = new uInt8[length]; - if(zip_file_decompress(myZip, image, length) != ZIPERR_NONE) + + ZipHandler::zip_error err = zip_file_decompress(myZip, image, length); + if(err == ZIPERR_NONE) + return length; + else { delete[] image; image = 0; length = 0; - return false; + + throw zip_error_s[err]; } - return true; } else - return false; + throw "Invalid ZIP archive"; } /*------------------------------------------------- diff --git a/src/common/ZipHandler.hxx b/src/common/ZipHandler.hxx index 60e7db98b..0ba67e93d 100644 --- a/src/common/ZipHandler.hxx +++ b/src/common/ZipHandler.hxx @@ -79,8 +79,9 @@ class ZipHandler bool hasNext(); // Answer whether there are more files present string next(); // Get next file - // Decompress the currently selected file, return false on any errors - bool decompress(uInt8*& image, uInt32& length); + // Decompress the currently selected file and return its length + // An exception will be thrown on any errors + uInt32 decompress(uInt8*& image); // Answer the number of ROM files found in the archive // Currently, this means files with extension a26/bin/rom diff --git a/src/common/mainSDL.cxx b/src/common/mainSDL.cxx index ca7231fde..7174f2727 100644 --- a/src/common/mainSDL.cxx +++ b/src/common/mainSDL.cxx @@ -132,10 +132,7 @@ int main(int argc, char* argv[]) { theOSystem->logMessage("Showing output from 'rominfo' ...", 2); FilesystemNode romnode(romfile); - if(argc > 1 && romnode.exists() && romnode.isFile()) - theOSystem->logMessage(theOSystem->getROMInfo(romnode), 0); - else - theOSystem->logMessage("ERROR: ROM doesn't exist", 0); + theOSystem->logMessage(theOSystem->getROMInfo(romnode), 0); return Cleanup(); } @@ -175,8 +172,12 @@ int main(int argc, char* argv[]) return Cleanup(); } } - else if(theOSystem->createConsole(romnode)) + else { + const string& result = theOSystem->createConsole(romnode); + if(result != EmptyString) + return Cleanup(); + if(theOSystem->settings().getBool("takesnapshot")) { theOSystem->logMessage("Taking snapshots with 'takesnapshot' ...", 2); @@ -201,8 +202,6 @@ int main(int argc, char* argv[]) theOSystem->eventHandler().enterDebugMode(); #endif } - else - return Cleanup(); // Swallow any spurious events in the queue // These are normally caused by joystick/mouse jitter diff --git a/src/emucore/FSNode.cxx b/src/emucore/FSNode.cxx index 922d25780..19ee3566a 100644 --- a/src/emucore/FSNode.cxx +++ b/src/emucore/FSNode.cxx @@ -154,11 +154,17 @@ bool FilesystemNode::rename(const string& newfile) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool FilesystemNode::read(uInt8*& image, uInt32& size) const +uInt32 FilesystemNode::read(uInt8*& image) const { + uInt32 size = 0; + // First let the private subclass attempt to open the file - if(_realNode->read(image, size)) - return true; + if((size = _realNode->read(image)) > 0) + return size; + + // File must actually exist + if(!(exists() && isReadable())) + throw "File not found/readable"; // Otherwise, assume the file is either gzip'ed or not compressed at all gzFile f = gzopen(getPath().c_str(), "rb"); @@ -168,9 +174,15 @@ bool FilesystemNode::read(uInt8*& image, uInt32& size) const size = gzread(f, image, 512 * 1024); gzclose(f); - return true; + if(size == 0) + { + delete[] image; image = 0; + throw "Zero-byte file"; + } + return size; } - return false; + else + throw "ZLIB open/read error"; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/FSNode.hxx b/src/emucore/FSNode.hxx index db32756e5..c1dc3c87a 100644 --- a/src/emucore/FSNode.hxx +++ b/src/emucore/FSNode.hxx @@ -240,10 +240,11 @@ class FilesystemNode * @param buffer The buffer to containing the data * This will be allocated by the method, and must be * freed by the caller. - * @param size Holds the size of the created buffer. - * @return True if the read succeeded, else false for any reason + * @return The number of bytes read (0 in the case of failure) + * This method can throw exceptions, and should be used inside + * a try-catch block. */ - virtual bool read(uInt8*& buffer, uInt32& size) const; + virtual uInt32 read(uInt8*& buffer) const; // TODO - this function is deprecated, and will be removed soon ... /** @@ -389,10 +390,11 @@ class AbstractFSNode * @param buffer The buffer to containing the data * This will be allocated by the method, and must be * freed by the caller. - * @param size Holds the size of the created buffer. - * @return True if the read succeeded, else false for any reason + * @return The number of bytes read (0 in the case of failure) + * This method can throw exceptions, and should be used inside + * a try-catch block. */ - virtual bool read(uInt8*& buffer, uInt32& size) const { return false; } + virtual uInt32 read(uInt8*& buffer) const { return 0; } /** * The parent node of this directory. diff --git a/src/emucore/MD5.cxx b/src/emucore/MD5.cxx index f203699eb..cc76c66a0 100644 --- a/src/emucore/MD5.cxx +++ b/src/emucore/MD5.cxx @@ -351,8 +351,14 @@ string MD5(const FilesystemNode& node) { uInt8* image = 0; uInt32 size = 0; - if(!node.read(image, size)) + try + { + size = node.read(image); + } + catch(...) + { return EmptyString; + } const string& md5 = MD5(image, size); delete[] image; diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index 7b7f5f9ae..c454ebf3a 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -502,8 +502,8 @@ void OSystem::createSound() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool OSystem::createConsole(const FilesystemNode& rom, const string& md5sum, - bool newrom) +string OSystem::createConsole(const FilesystemNode& rom, const string& md5sum, + bool newrom) { // Do a little error checking; it shouldn't be necessary if(myConsole) deleteConsole(); @@ -529,7 +529,18 @@ bool OSystem::createConsole(const FilesystemNode& rom, const string& md5sum, // Create an instance of the 2600 game console ostringstream buf; string type, id; - myConsole = openConsole(myRomFile, myRomMD5, type, id); + try + { + myConsole = openConsole(myRomFile, myRomMD5, type, id); + } + catch(const char* err_msg) + { + myConsole = 0; + buf << "ERROR: Couldn't create console (" << err_msg << ")"; + logMessage(buf.str(), 0); + return buf.str(); + } + if(myConsole) { #ifdef DEBUGGER_SUPPORT @@ -554,7 +565,7 @@ bool OSystem::createConsole(const FilesystemNode& rom, const string& md5sum, { logMessage("ERROR: Couldn't create framebuffer for console", 0); myEventHandler->reset(EventHandler::S_LAUNCHER); - return false; + return "ERROR: Couldn't create framebuffer for console"; } if(showmessage) @@ -582,15 +593,8 @@ bool OSystem::createConsole(const FilesystemNode& rom, const string& md5sum, myEventHandler->handleEvent(Event::ConsoleSelect, 1); if(mySettings->getBool("holdbutton0")) myEventHandler->handleEvent(Event::JoystickZeroFire, 1); - - return true; - } - else - { - buf << "ERROR: Couldn't create console for " << myRomFile.getShortPath() << endl; - logMessage(buf.str(), 0); - return false; } + return EmptyString; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -623,7 +627,7 @@ void OSystem::deleteConsole() bool OSystem::reloadConsole() { deleteConsole(); - return createConsole(myRomFile, myRomMD5, false); + return createConsole(myRomFile, myRomMD5, false) == EmptyString; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -654,15 +658,20 @@ bool OSystem::createLauncher(const string& startdir) string OSystem::getROMInfo(const FilesystemNode& romfile) { string md5, type, id, result = ""; - Console* console = openConsole(romfile, md5, type, id); - if(console) + Console* console = 0; + try { - result = getROMInfo(console); - delete console; + console = openConsole(romfile, md5, type, id); + } + catch(const char* err_msg) + { + ostringstream buf; + buf << "ERROR: Couldn't get ROM info (" << err_msg << ")"; + return buf.str(); } - else - result = "ERROR: Couldn't get ROM info for " + romfile.getShortPath() + " ..."; + result = getROMInfo(console); + delete console; return result; } @@ -746,12 +755,6 @@ Console* OSystem::openConsole(const FilesystemNode& romfile, string& md5, if(cart) console = new Console(this, cart, props); } - else - { - ostringstream buf; - buf << "ERROR: Couldn't open \'" << romfile.getShortPath() << "\'" << endl; - logMessage(buf.str(), 0); - } // Free the image since we don't need it any longer if(image != 0 && size > 0) @@ -769,7 +772,7 @@ uInt8* OSystem::openROM(const FilesystemNode& rom, string& md5, uInt32& size) // contain a valid name uInt8* image = 0; - if(!rom.read(image, size)) + if((size = rom.read(image)) == 0) { delete[] image; return (uInt8*) 0; diff --git a/src/emucore/OSystem.hxx b/src/emucore/OSystem.hxx index 8e1428952..551ee5aa1 100644 --- a/src/emucore/OSystem.hxx +++ b/src/emucore/OSystem.hxx @@ -377,10 +377,10 @@ class OSystem @param md5 The MD5sum of the ROM @param newrom Whether this is a new ROM, or a reload of current one - @return True on successful creation, otherwise false + @return String indicating any error message (EmptyString for no errors) */ - bool createConsole(const FilesystemNode& rom, const string& md5 = "", - bool newrom = true); + string createConsole(const FilesystemNode& rom, const string& md5 = "", + bool newrom = true); /** Deletes the currently defined console, if it exists. diff --git a/src/gui/LauncherDialog.cxx b/src/gui/LauncherDialog.cxx index ba762b87a..4be63c265 100644 --- a/src/gui/LauncherDialog.cxx +++ b/src/gui/LauncherDialog.cxx @@ -523,15 +523,15 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd, string extension; if(LauncherFilterDialog::isValidRomName(romnode, extension)) { - if(instance().createConsole(romnode, myGameList->md5(item))) + const string& result = + instance().createConsole(romnode, myGameList->md5(item)); + if(result == EmptyString) instance().settings().setString("lastrom", myList->getSelectedString()); else - instance().frameBuffer().showMessage( - "Error creating console (check ROM file/bankswitch scheme)", - kMiddleCenter, true); + instance().frameBuffer().showMessage(result, kMiddleCenter, true); } else - instance().frameBuffer().showMessage("Not a valid ROM file", + instance().frameBuffer().showMessage("Not a valid ROM filename", kMiddleCenter, true); } } diff --git a/src/zlib/README b/src/zlib/README index d4219bf88..5ca9d127e 100644 --- a/src/zlib/README +++ b/src/zlib/README @@ -1,22 +1,22 @@ ZLIB DATA COMPRESSION LIBRARY -zlib 1.2.5 is a general purpose data compression library. All the code is +zlib 1.2.8 is a general purpose data compression library. All the code is thread safe. The data format used by the zlib library is described by RFCs (Request for Comments) 1950 to 1952 in the files -http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format) -and rfc1952.txt (gzip format). +http://tools.ietf.org/html/rfc1950 (zlib format), rfc1951 (deflate format) and +rfc1952 (gzip format). All functions of the compression library are documented in the file zlib.h (volunteer to write man pages welcome, contact zlib@gzip.org). A usage example -of the library is given in the file example.c which also tests that the library -is working correctly. Another example is given in the file minigzip.c. The -compression library itself is composed of all source files except example.c and -minigzip.c. +of the library is given in the file test/example.c which also tests that +the library is working correctly. Another example is given in the file +test/minigzip.c. The compression library itself is composed of all source +files in the root directory. To compile all files and run the test program, follow the instructions given at the top of Makefile.in. In short "./configure; make test", and if that goes -well, "make install" should work for most flavors of Unix. For Windows, use one -of the special makefiles in win32/ or contrib/vstudio/ . For VMS, use +well, "make install" should work for most flavors of Unix. For Windows, use +one of the special makefiles in win32/ or contrib/vstudio/ . For VMS, use make_vms.com. Questions about zlib should be sent to , or to Gilles Vollant @@ -31,7 +31,7 @@ Mark Nelson wrote an article about zlib for the Jan. 1997 issue of Dr. Dobb's Journal; a copy of the article is available at http://marknelson.us/1997/01/01/zlib-engine/ . -The changes made in version 1.2.5 are documented in the file ChangeLog. +The changes made in version 1.2.8 are documented in the file ChangeLog. Unsupported third party contributions are provided in directory contrib/ . @@ -44,7 +44,7 @@ http://search.cpan.org/~pmqs/IO-Compress-Zlib/ . A Python interface to zlib written by A.M. Kuchling is available in Python 1.5 and later versions, see -http://www.python.org/doc/lib/module-zlib.html . +http://docs.python.org/library/zlib.html . zlib is built into tcl: http://wiki.tcl.tk/4610 . @@ -84,7 +84,7 @@ Acknowledgments: Copyright notice: - (C) 1995-2010 Jean-loup Gailly and Mark Adler + (C) 1995-2013 Jean-loup Gailly and Mark Adler This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages diff --git a/src/zlib/compress.c b/src/zlib/compress.c index 1cb602b92..0314fbc61 100644 --- a/src/zlib/compress.c +++ b/src/zlib/compress.c @@ -29,7 +29,7 @@ int ZEXPORT compress2 ( z_stream stream; int err; - stream.next_in = (Bytef*)source; + stream.next_in = (z_const Bytef *)source; stream.avail_in = (uInt)sourceLen; #ifdef MAXSEG_64K /* Check for source > 64K on 16-bit machine: */ diff --git a/src/zlib/deflate.c b/src/zlib/deflate.c index 154858c58..6310612f1 100644 --- a/src/zlib/deflate.c +++ b/src/zlib/deflate.c @@ -1,5 +1,5 @@ /* deflate.c -- compress data using the deflation algorithm - * Copyright (C) 1995-2012 Jean-loup Gailly and Mark Adler + * Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -52,7 +52,7 @@ #include "deflate.h" const char deflate_copyright[] = - " deflate 1.2.7 Copyright 1995-2012 Jean-loup Gailly and Mark Adler "; + " deflate 1.2.8 Copyright 1995-2013 Jean-loup Gailly and Mark Adler "; /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot @@ -304,7 +304,7 @@ int ZEXPORT deflateInit2_( if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || s->pending_buf == Z_NULL) { s->status = FINISH_STATE; - strm->msg = (char*)ERR_MSG(Z_MEM_ERROR); + strm->msg = ERR_MSG(Z_MEM_ERROR); deflateEnd (strm); return Z_MEM_ERROR; } @@ -328,7 +328,7 @@ int ZEXPORT deflateSetDictionary ( uInt str, n; int wrap; unsigned avail; - unsigned char *next; + z_const unsigned char *next; if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL) return Z_STREAM_ERROR; @@ -358,7 +358,7 @@ int ZEXPORT deflateSetDictionary ( avail = strm->avail_in; next = strm->next_in; strm->avail_in = dictLength; - strm->next_in = (Bytef *)dictionary; + strm->next_in = (z_const Bytef *)dictionary; fill_window(s); while (s->lookahead >= MIN_MATCH) { str = s->strstart; @@ -512,6 +512,8 @@ int ZEXPORT deflateParams( strm->total_in != 0) { /* Flush the last buffer: */ err = deflate(strm, Z_BLOCK); + if (err == Z_BUF_ERROR && s->pending == 0) + err = Z_OK; } if (s->level != level) { s->level = level; diff --git a/src/zlib/deflate.h b/src/zlib/deflate.h index fbac44d90..ce0299edd 100644 --- a/src/zlib/deflate.h +++ b/src/zlib/deflate.h @@ -104,7 +104,7 @@ typedef struct internal_state { int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ gz_headerp gzhead; /* gzip header information to write */ uInt gzindex; /* where in extra, name, or comment */ - Byte method; /* STORED (for zip only) or DEFLATED */ + Byte method; /* can only be DEFLATED */ int last_flush; /* value of flush param for previous deflate call */ /* used by deflate.c: */ diff --git a/src/zlib/gzguts.h b/src/zlib/gzguts.h index ee3f281aa..d87659d03 100644 --- a/src/zlib/gzguts.h +++ b/src/zlib/gzguts.h @@ -1,5 +1,5 @@ /* gzguts.h -- zlib internal header definitions for gz* operations - * Copyright (C) 2004, 2005, 2010, 2011, 2012 Mark Adler + * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -35,6 +35,13 @@ # include #endif +#ifdef WINAPI_FAMILY +# define open _open +# define read _read +# define write _write +# define close _close +#endif + #ifdef NO_DEFLATE /* for compatibility with old definition */ # define NO_GZCOMPRESS #endif @@ -60,7 +67,7 @@ #ifndef HAVE_VSNPRINTF # ifdef MSDOS /* vsnprintf may exist on some MS-DOS compilers (DJGPP?), - but for now we just assume it doesn't. */ + but for now we just assume it doesn't. */ # define NO_vsnprintf # endif # ifdef __TURBOC__ @@ -88,6 +95,14 @@ # endif #endif +/* unlike snprintf (which is required in C99, yet still not supported by + Microsoft more than a decade later!), _snprintf does not guarantee null + termination of the result -- however this is only used in gzlib.c where + the result is assured to fit in the space provided */ +#ifdef _MSC_VER +# define snprintf _snprintf +#endif + #ifndef local # define local static #endif @@ -127,7 +142,8 @@ # define DEF_MEM_LEVEL MAX_MEM_LEVEL #endif -/* default i/o buffer size -- double this for output when reading */ +/* default i/o buffer size -- double this for output when reading (this and + twice this must be able to fit in an unsigned type) */ #define GZBUFSIZE 8192 /* gzip modes, also provide a little integrity check on the passed structure */ diff --git a/src/zlib/gzlib.c b/src/zlib/gzlib.c index 011f1f530..349b0ff50 100644 --- a/src/zlib/gzlib.c +++ b/src/zlib/gzlib.c @@ -1,5 +1,5 @@ /* gzlib.c -- zlib functions common to reading and writing gzip files - * Copyright (C) 2004, 2010, 2011, 2012 Mark Adler + * Copyright (C) 2004, 2010, 2011, 2012, 2013 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -162,8 +162,10 @@ local gzFile gz_open( break; case 'F': state->strategy = Z_FIXED; + break; case 'T': state->direct = 1; + break; default: /* could consider as an error, but just ignore */ ; } @@ -208,7 +210,11 @@ local gzFile gz_open( *(state->path) = 0; else #endif - strcpy((char *)state->path, (const char *)path); +#if !defined(NO_snprintf) && !defined(NO_vsnprintf) + snprintf(state->path, len + 1, "%s", (const char *)path); +#else + strcpy(state->path, path); +#endif /* compute the flags for open() */ oflag = @@ -284,7 +290,11 @@ gzFile ZEXPORT gzdopen( if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL) return NULL; +#if !defined(NO_snprintf) && !defined(NO_vsnprintf) + snprintf(path, 7 + 3 * sizeof(int), "", fd); /* for debugging */ +#else sprintf(path, "", fd); /* for debugging */ +#endif gz = gz_open(path, fd, mode); free(path); return gz; @@ -531,7 +541,8 @@ const char * ZEXPORT gzerror( /* return error information */ if (errnum != NULL) *errnum = state->err; - return state->msg == NULL ? "" : state->msg; + return state->err == Z_MEM_ERROR ? "out of memory" : + (state->msg == NULL ? "" : state->msg); } /* -- see zlib.h -- */ @@ -582,21 +593,24 @@ void ZLIB_INTERNAL gz_error( if (msg == NULL) return; - /* for an out of memory error, save as static string */ - if (err == Z_MEM_ERROR) { - state->msg = (char *)msg; + /* for an out of memory error, return literal string when requested */ + if (err == Z_MEM_ERROR) return; - } /* construct error message with path */ - if ((state->msg = (char *)malloc(strlen(state->path) + strlen(msg) + 3)) == NULL) { + if ((state->msg = (char *)malloc(strlen(state->path) + strlen(msg) + 3)) == + NULL) { state->err = Z_MEM_ERROR; - state->msg = (char *)"out of memory"; return; } +#if !defined(NO_snprintf) && !defined(NO_vsnprintf) + snprintf(state->msg, strlen(state->path) + strlen(msg) + 3, + "%s%s%s", state->path, ": ", msg); +#else strcpy(state->msg, state->path); strcat(state->msg, ": "); strcat(state->msg, msg); +#endif return; } diff --git a/src/zlib/gzread.c b/src/zlib/gzread.c index 967950181..8b8463df0 100644 --- a/src/zlib/gzread.c +++ b/src/zlib/gzread.c @@ -1,5 +1,5 @@ /* gzread.c -- zlib functions for reading gzip files - * Copyright (C) 2004, 2005, 2010, 2011, 2012 Mark Adler + * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -58,7 +58,8 @@ local int gz_avail( return -1; if (state->eof == 0) { if (strm->avail_in) { /* copy what's there to the start */ - unsigned char *p = state->in, *q = strm->next_in; + unsigned char *p = state->in; + unsigned const char *q = strm->next_in; unsigned n = strm->avail_in; do { *p++ = *q++; @@ -359,7 +360,7 @@ int ZEXPORT gzread( /* large len -- decompress directly into user buffer */ else { /* state->how == GZIP */ strm->avail_out = len; - strm->next_out = (Bytef *)buf; + strm->next_out = (unsigned char *)buf; if (gz_decomp(state) == -1) return -1; n = state->x.have; @@ -378,7 +379,11 @@ int ZEXPORT gzread( } /* -- see zlib.h -- */ -#undef gzgetc +#ifdef Z_PREFIX_SET +# undef z_gzgetc +#else +# undef gzgetc +#endif int ZEXPORT gzgetc( gzFile file) { diff --git a/src/zlib/gzwrite.c b/src/zlib/gzwrite.c index 82770bb1a..ae28ba421 100644 --- a/src/zlib/gzwrite.c +++ b/src/zlib/gzwrite.c @@ -1,5 +1,5 @@ /* gzwrite.c -- zlib functions for writing gzip files - * Copyright (C) 2004, 2005, 2010, 2011, 2012 Mark Adler + * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -168,7 +168,6 @@ int ZEXPORT gzwrite( unsigned len) { unsigned put = len; - unsigned n; gz_statep state; z_streamp strm; @@ -208,16 +207,19 @@ int ZEXPORT gzwrite( if (len < state->size) { /* copy to input buffer, compress when full */ do { + unsigned have, copy; + if (strm->avail_in == 0) strm->next_in = state->in; - n = state->size - strm->avail_in; - if (n > len) - n = len; - memcpy(strm->next_in + strm->avail_in, buf, n); - strm->avail_in += n; - state->x.pos += n; - buf = (char *)buf + n; - len -= n; + have = (unsigned)((strm->next_in + strm->avail_in) - state->in); + copy = state->size - have; + if (copy > len) + copy = len; + memcpy(state->in + have, buf, copy); + strm->avail_in += copy; + state->x.pos += copy; + buf = (const char *)buf + copy; + len -= copy; if (len && gz_comp(state, Z_NO_FLUSH) == -1) return 0; } while (len); @@ -229,7 +231,7 @@ int ZEXPORT gzwrite( /* directly compress user buffer to file */ strm->avail_in = len; - strm->next_in = (Bytef *)buf; + strm->next_in = (z_const Bytef *)buf; state->x.pos += len; if (gz_comp(state, Z_NO_FLUSH) == -1) return 0; @@ -244,6 +246,7 @@ int ZEXPORT gzputc( gzFile file, int c) { + unsigned have; unsigned char buf[1]; gz_statep state; z_streamp strm; @@ -267,12 +270,16 @@ int ZEXPORT gzputc( /* try writing to input buffer for speed (state->size == 0 if buffer not initialized) */ - if (strm->avail_in < state->size) { + if (state->size) { if (strm->avail_in == 0) strm->next_in = state->in; - strm->next_in[strm->avail_in++] = c; - state->x.pos++; - return c & 0xff; + have = (unsigned)((strm->next_in + strm->avail_in) - state->in); + if (have < state->size) { + state->in[have] = c; + strm->avail_in++; + state->x.pos++; + return c & 0xff; + } } /* no room in buffer or not initialized, use gz_write() */ @@ -300,12 +307,11 @@ int ZEXPORT gzputs( #include /* -- see zlib.h -- */ -int ZEXPORTVA gzprintf (gzFile file, const char *format, ...) +int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) { int size, len; gz_statep state; z_streamp strm; - va_list va; /* get internal structure */ if (file == NULL) @@ -335,25 +341,20 @@ int ZEXPORTVA gzprintf (gzFile file, const char *format, ...) /* do the printf() into the input buffer, put length in len */ size = (int)(state->size); state->in[size - 1] = 0; - va_start(va, format); #ifdef NO_vsnprintf # ifdef HAS_vsprintf_void (void)vsprintf((char *)(state->in), format, va); - va_end(va); for (len = 0; len < size; len++) if (state->in[len] == 0) break; # else len = vsprintf((char *)(state->in), format, va); - va_end(va); # endif #else # ifdef HAS_vsnprintf_void (void)vsnprintf((char *)(state->in), size, format, va); - va_end(va); len = strlen((char *)(state->in)); # else len = vsnprintf((char *)(state->in), size, format, va); - va_end(va); # endif #endif @@ -368,6 +369,17 @@ int ZEXPORTVA gzprintf (gzFile file, const char *format, ...) return len; } +int ZEXPORTVA gzprintf(gzFile file, const char *format, ...) +{ + va_list va; + int ret; + + va_start(va, format); + ret = gzvprintf(file, format, va); + va_end(va); + return ret; +} + #else /* !STDC && !Z_HAVE_STDARG_H */ /* -- see zlib.h -- */ @@ -564,9 +576,9 @@ int ZEXPORT gzclose_w( } /* flush, free memory, and close file */ + if (gz_comp(state, Z_FINISH) == -1) + ret = state->err; if (state->size) { - if (gz_comp(state, Z_FINISH) == -1) - ret = state->err; if (!state->direct) { (void)deflateEnd(&(state->strm)); free(state->out); diff --git a/src/zlib/infback.c b/src/zlib/infback.c index 60f78dc98..cff17ee2f 100644 --- a/src/zlib/infback.c +++ b/src/zlib/infback.c @@ -255,7 +255,7 @@ int ZEXPORT inflateBack( void FAR *out_desc) { struct inflate_state FAR *state; - unsigned char FAR *next; /* next input */ + z_const unsigned char FAR *next; /* next input */ unsigned char FAR *put; /* next output */ unsigned have, left; /* available input and output */ unsigned long hold; /* bit buffer */ diff --git a/src/zlib/inffast.c b/src/zlib/inffast.c index 155dcc7bd..436b0b2bf 100644 --- a/src/zlib/inffast.c +++ b/src/zlib/inffast.c @@ -1,5 +1,5 @@ /* inffast.c -- fast decoding - * Copyright (C) 1995-2008, 2010 Mark Adler + * Copyright (C) 1995-2008, 2010, 2013 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -69,8 +69,8 @@ void ZLIB_INTERNAL inflate_fast( unsigned start) { struct inflate_state FAR *state; - unsigned char FAR *in; /* local strm->next_in */ - unsigned char FAR *last; /* while in < last, enough input available */ + z_const unsigned char FAR *in; /* local strm->next_in */ + z_const unsigned char FAR *last; /* have enough input while in < last */ unsigned char FAR *out; /* local strm->next_out */ unsigned char FAR *beg; /* inflate()'s initial strm->next_out */ unsigned char FAR *end; /* while out < end, enough space available */ diff --git a/src/zlib/inflate.c b/src/zlib/inflate.c index 9a1a09b75..91dbd65f0 100644 --- a/src/zlib/inflate.c +++ b/src/zlib/inflate.c @@ -93,11 +93,12 @@ /* function prototypes */ local void fixedtables OF((struct inflate_state FAR *state)); -local int updatewindow OF((z_streamp strm, unsigned out)); +local int updatewindow OF((z_streamp strm, const unsigned char FAR *end, + unsigned copy)); #ifdef BUILDFIXED void makefixed OF((void)); #endif -local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf, +local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf, unsigned len)); int ZEXPORT inflateResetKeep( @@ -377,10 +378,11 @@ void makefixed() */ local int updatewindow( z_streamp strm, - unsigned out) + const Bytef *end, + unsigned copy) { struct inflate_state FAR *state; - unsigned copy, dist; + unsigned dist; state = (struct inflate_state FAR *)strm->state; @@ -400,19 +402,18 @@ local int updatewindow( } /* copy state->wsize or less output bytes into the circular window */ - copy = out - strm->avail_out; if (copy >= state->wsize) { - zmemcpy(state->window, strm->next_out - state->wsize, state->wsize); + zmemcpy(state->window, end - state->wsize, state->wsize); state->wnext = 0; state->whave = state->wsize; } else { dist = state->wsize - state->wnext; if (dist > copy) dist = copy; - zmemcpy(state->window + state->wnext, strm->next_out - copy, dist); + zmemcpy(state->window + state->wnext, end - copy, dist); copy -= dist; if (copy) { - zmemcpy(state->window, strm->next_out - copy, copy); + zmemcpy(state->window, end - copy, copy); state->wnext = copy; state->whave = state->wsize; } @@ -606,7 +607,7 @@ int ZEXPORT inflate( int flush) { struct inflate_state FAR *state; - unsigned char FAR *next; /* next input */ + z_const unsigned char FAR *next; /* next input */ unsigned char FAR *put; /* next output */ unsigned have, left; /* available input and output */ unsigned long hold; /* bit buffer */ @@ -920,7 +921,7 @@ int ZEXPORT inflate( while (state->have < 19) state->lens[order[state->have++]] = 0; state->next = state->codes; - state->lencode = (code const FAR *)(state->next); + state->lencode = (const code FAR *)(state->next); state->lenbits = 7; ret = inflate_table(CODES, state->lens, 19, &(state->next), &(state->lenbits), state->work); @@ -994,7 +995,7 @@ int ZEXPORT inflate( values here (9 and 6) without reading the comments in inftrees.h concerning the ENOUGH constants, which depend on those values */ state->next = state->codes; - state->lencode = (code const FAR *)(state->next); + state->lencode = (const code FAR *)(state->next); state->lenbits = 9; ret = inflate_table(LENS, state->lens, state->nlen, &(state->next), &(state->lenbits), state->work); @@ -1003,7 +1004,7 @@ int ZEXPORT inflate( state->mode = BAD; break; } - state->distcode = (code const FAR *)(state->next); + state->distcode = (const code FAR *)(state->next); state->distbits = 6; ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist, &(state->next), &(state->distbits), state->work); @@ -1230,7 +1231,7 @@ int ZEXPORT inflate( RESTORE(); if (state->wsize || (out != strm->avail_out && state->mode < BAD && (state->mode < CHECK || flush != Z_FINISH))) - if (updatewindow(strm, out)) { + if (updatewindow(strm, strm->next_out, out - strm->avail_out)) { state->mode = MEM; return Z_MEM_ERROR; } @@ -1264,6 +1265,29 @@ int ZEXPORT inflateEnd( return Z_OK; } +int ZEXPORT inflateGetDictionary( + z_streamp strm, + Bytef *dictionary, + uInt *dictLength) +{ + struct inflate_state FAR *state; + + /* check state */ + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + state = (struct inflate_state FAR *)strm->state; + + /* copy dictionary */ + if (state->whave && dictionary != Z_NULL) { + zmemcpy(dictionary, state->window + state->wnext, + state->whave - state->wnext); + zmemcpy(dictionary + state->whave - state->wnext, + state->window, state->wnext); + } + if (dictLength != Z_NULL) + *dictLength = state->whave; + return Z_OK; +} + int ZEXPORT inflateSetDictionary( z_streamp strm, const Bytef *dictionary, @@ -1271,8 +1295,6 @@ int ZEXPORT inflateSetDictionary( { struct inflate_state FAR *state; unsigned long dictid; - unsigned char *next; - unsigned avail; int ret; /* check state */ @@ -1291,13 +1313,7 @@ int ZEXPORT inflateSetDictionary( /* copy dictionary to window using updatewindow(), which will amend the existing dictionary if appropriate */ - next = strm->next_out; - avail = strm->avail_out; - strm->next_out = (Bytef *)dictionary + dictLength; - strm->avail_out = 0; - ret = updatewindow(strm, dictLength); - strm->avail_out = avail; - strm->next_out = next; + ret = updatewindow(strm, dictionary + dictLength, dictLength); if (ret) { state->mode = MEM; return Z_MEM_ERROR; @@ -1337,7 +1353,7 @@ int ZEXPORT inflateGetHeader( */ local unsigned syncsearch( unsigned FAR *have, - unsigned char FAR *buf, + const unsigned char FAR *buf, unsigned len) { unsigned got; diff --git a/src/zlib/inftrees.c b/src/zlib/inftrees.c index ed1082dc3..039222a95 100644 --- a/src/zlib/inftrees.c +++ b/src/zlib/inftrees.c @@ -1,5 +1,5 @@ /* inftrees.c -- generate Huffman trees for efficient decoding - * Copyright (C) 1995-2012 Mark Adler + * Copyright (C) 1995-2013 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -9,7 +9,7 @@ #define MAXBITS 15 const char inflate_copyright[] = - " inflate 1.2.7 Copyright 1995-2012 Mark Adler "; + " inflate 1.2.8 Copyright 1995-2013 Mark Adler "; /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot @@ -62,7 +62,7 @@ int ZLIB_INTERNAL inflate_table( 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; static const unsigned short lext[31] = { /* Length codes 257..285 extra */ 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, - 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 78, 68}; + 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78}; static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, @@ -208,8 +208,8 @@ int ZLIB_INTERNAL inflate_table( mask = used - 1; /* mask for comparing low */ /* check available table space */ - if ((type == LENS && used >= ENOUGH_LENS) || - (type == DISTS && used >= ENOUGH_DISTS)) + if ((type == LENS && used > ENOUGH_LENS) || + (type == DISTS && used > ENOUGH_DISTS)) return 1; /* process all codes and make table entries */ @@ -277,8 +277,8 @@ int ZLIB_INTERNAL inflate_table( /* check for enough space */ used += 1U << curr; - if ((type == LENS && used >= ENOUGH_LENS) || - (type == DISTS && used >= ENOUGH_DISTS)) + if ((type == LENS && used > ENOUGH_LENS) || + (type == DISTS && used > ENOUGH_DISTS)) return 1; /* point entry in root table to sub-table */ diff --git a/src/zlib/trees.c b/src/zlib/trees.c index de0b7f210..9dbd905e1 100644 --- a/src/zlib/trees.c +++ b/src/zlib/trees.c @@ -146,8 +146,8 @@ local void send_tree OF((deflate_state *s, ct_data *tree, int max_code)); local int build_bl_tree OF((deflate_state *s)); local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes, int blcodes)); -local void compress_block OF((deflate_state *s, ct_data *ltree, - ct_data *dtree)); +local void compress_block OF((deflate_state *s, const ct_data *ltree, + const ct_data *dtree)); local int detect_data_type OF((deflate_state *s)); local unsigned bi_reverse OF((unsigned value, int length)); local void bi_windup OF((deflate_state *s)); @@ -974,7 +974,8 @@ void ZLIB_INTERNAL _tr_flush_block( } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) { #endif send_bits(s, (STATIC_TREES<<1)+last, 3); - compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree); + compress_block(s, (const ct_data *)static_ltree, + (const ct_data *)static_dtree); #ifdef DEBUG s->compressed_len += 3 + s->static_len; #endif @@ -982,7 +983,8 @@ void ZLIB_INTERNAL _tr_flush_block( send_bits(s, (DYN_TREES<<1)+last, 3); send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1, max_blindex+1); - compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree); + compress_block(s, (const ct_data *)s->dyn_ltree, + (const ct_data *)s->dyn_dtree); #ifdef DEBUG s->compressed_len += 3 + s->opt_len; #endif @@ -1059,8 +1061,8 @@ int ZLIB_INTERNAL _tr_tally ( */ local void compress_block( deflate_state *s, - ct_data *ltree, - ct_data *dtree) + const ct_data *ltree, + const ct_data *dtree) { unsigned dist; /* distance of matched string */ int lc; /* match length or unmatched char (if dist == 0) */ diff --git a/src/zlib/uncompr.c b/src/zlib/uncompr.c index 9b272e983..d3cb8fe18 100644 --- a/src/zlib/uncompr.c +++ b/src/zlib/uncompr.c @@ -30,7 +30,7 @@ int ZEXPORT uncompress ( z_stream stream; int err; - stream.next_in = (Bytef*)source; + stream.next_in = (z_const Bytef *)source; stream.avail_in = (uInt)sourceLen; /* Check for source > 64K on 16-bit machine: */ if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; diff --git a/src/zlib/zconf.h b/src/zlib/zconf.h index 2bf6a564b..cc75b952b 100644 --- a/src/zlib/zconf.h +++ b/src/zlib/zconf.h @@ -1,5 +1,5 @@ /* zconf.h -- configuration of the zlib compression library - * Copyright (C) 1995-2012 Jean-loup Gailly. + * Copyright (C) 1995-2013 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -8,9 +8,12 @@ #ifndef ZCONF_H #define ZCONF_H +/** Added by SA *********/ #ifdef HAVE_INTTYPES #define Z_HAVE_UNISTD_H #endif +#define ZLIB_CONST +/**************************/ /* * If you *really* need a unique prefix for all types and library functions, @@ -25,6 +28,7 @@ # define _dist_code z__dist_code # define _length_code z__length_code # define _tr_align z__tr_align +# define _tr_flush_bits z__tr_flush_bits # define _tr_flush_block z__tr_flush_block # define _tr_init z__tr_init # define _tr_stored_block z__tr_stored_block @@ -81,6 +85,7 @@ # define gzopen_w z_gzopen_w # endif # define gzprintf z_gzprintf +# define gzvprintf z_gzvprintf # define gzputc z_gzputc # define gzputs z_gzputs # define gzread z_gzread @@ -107,6 +112,7 @@ # define inflateReset z_inflateReset # define inflateReset2 z_inflateReset2 # define inflateSetDictionary z_inflateSetDictionary +# define inflateGetDictionary z_inflateGetDictionary # define inflateSync z_inflateSync # define inflateSyncPoint z_inflateSyncPoint # define inflateUndermine z_inflateUndermine @@ -392,20 +398,14 @@ typedef uLong FAR uLongf; typedef Byte *voidp; #endif -/* ./configure may #define Z_U4 here */ - #if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC) # include # if (UINT_MAX == 0xffffffffUL) # define Z_U4 unsigned -# else -# if (ULONG_MAX == 0xffffffffUL) -# define Z_U4 unsigned long -# else -# if (USHRT_MAX == 0xffffffffUL) -# define Z_U4 unsigned short -# endif -# endif +# elif (ULONG_MAX == 0xffffffffUL) +# define Z_U4 unsigned long +# elif (USHRT_MAX == 0xffffffffUL) +# define Z_U4 unsigned short # endif #endif @@ -429,8 +429,16 @@ typedef uLong FAR uLongf; # endif #endif +#if defined(STDC) || defined(Z_HAVE_STDARG_H) +# ifndef Z_SOLO +# include /* for va_list */ +# endif +#endif + #ifdef _WIN32 -# include /* for wchar_t */ +# ifndef Z_SOLO +# include /* for wchar_t */ +# endif #endif /* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and @@ -439,7 +447,7 @@ typedef uLong FAR uLongf; * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as * equivalently requesting no 64-bit operations */ -#if defined(LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1 +#if defined(_LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1 # undef _LARGEFILE64_SOURCE #endif @@ -447,7 +455,7 @@ typedef uLong FAR uLongf; # define Z_HAVE_UNISTD_H #endif #ifndef Z_SOLO -# if defined(Z_HAVE_UNISTD_H) || defined(LARGEFILE64_SOURCE) +# if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE) # include /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ # ifdef VMS # include /* for off_t */ diff --git a/src/zlib/zlib.h b/src/zlib/zlib.h index 3edf3acdb..3e0c7672a 100644 --- a/src/zlib/zlib.h +++ b/src/zlib/zlib.h @@ -1,7 +1,7 @@ /* zlib.h -- interface of the 'zlib' general purpose compression library - version 1.2.7, May 2nd, 2012 + version 1.2.8, April 28th, 2013 - Copyright (C) 1995-2012 Jean-loup Gailly and Mark Adler + Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages @@ -37,11 +37,11 @@ extern "C" { #endif -#define ZLIB_VERSION "1.2.7" -#define ZLIB_VERNUM 0x1270 +#define ZLIB_VERSION "1.2.8" +#define ZLIB_VERNUM 0x1280 #define ZLIB_VER_MAJOR 1 #define ZLIB_VER_MINOR 2 -#define ZLIB_VER_REVISION 7 +#define ZLIB_VER_REVISION 8 #define ZLIB_VER_SUBREVISION 0 /* @@ -839,6 +839,21 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, inflate(). */ +ZEXTERN int ZEXPORT inflateGetDictionary OF((z_streamp strm, + Bytef *dictionary, + uInt *dictLength)); +/* + Returns the sliding dictionary being maintained by inflate. dictLength is + set to the number of bytes in the dictionary, and that many bytes are copied + to dictionary. dictionary must have enough space, where 32768 bytes is + always enough. If inflateGetDictionary() is called with dictionary equal to + Z_NULL, then only the dictionary length is returned, and nothing is copied. + Similary, if dictLength is Z_NULL, then it is not set. + + inflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the + stream state is inconsistent. +*/ + ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); /* Skips invalid compressed data until a possible full flush point (see above @@ -846,7 +861,7 @@ ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); available input is skipped. No output is provided. inflateSync searches for a 00 00 FF FF pattern in the compressed data. - All full flush points have this pattern, but not all occurences of this + All full flush points have this pattern, but not all occurrences of this pattern are full flush points. inflateSync returns Z_OK if a possible full flush point has been found, @@ -1007,7 +1022,8 @@ ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, the version of the header file. */ -typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *)); +typedef unsigned (*in_func) OF((void FAR *, + z_const unsigned char FAR * FAR *)); typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, @@ -1015,11 +1031,12 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, out_func out, void FAR *out_desc)); /* inflateBack() does a raw inflate with a single call using a call-back - interface for input and output. This is more efficient than inflate() for - file i/o applications in that it avoids copying between the output and the - sliding window by simply making the window itself the output buffer. This - function trusts the application to not change the output buffer passed by - the output function, at least until inflateBack() returns. + interface for input and output. This is potentially more efficient than + inflate() for file i/o applications, in that it avoids copying between the + output and the sliding window by simply making the window itself the output + buffer. inflate() can be faster on modern CPUs when used with large + buffers. inflateBack() trusts the application to not change the output + buffer passed by the output function, at least until inflateBack() returns. inflateBackInit() must be called first to allocate the internal state and to initialize the state with the user-provided window buffer. @@ -1736,6 +1753,13 @@ ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp)); ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path, const char *mode)); #endif +#if defined(STDC) || defined(Z_HAVE_STDARG_H) +# ifndef Z_SOLO +ZEXTERN int ZEXPORTVA gzvprintf Z_ARG((gzFile file, + const char *format, + va_list va)); +# endif +#endif #ifdef __cplusplus } diff --git a/src/zlib/zutil.c b/src/zlib/zutil.c index 6498287e3..6e6e538b7 100644 --- a/src/zlib/zutil.c +++ b/src/zlib/zutil.c @@ -14,7 +14,7 @@ struct internal_state {int dummy;}; /* for buggy compilers */ #endif -const char * const z_errmsg[10] = { +z_const char * const z_errmsg[10] = { "need dictionary", /* Z_NEED_DICT 2 */ "stream end", /* Z_STREAM_END 1 */ "", /* Z_OK 0 */ diff --git a/src/zlib/zutil.h b/src/zlib/zutil.h index 4e3dcc6ae..24ab06b1c 100644 --- a/src/zlib/zutil.h +++ b/src/zlib/zutil.h @@ -1,5 +1,5 @@ /* zutil.h -- internal interface and configuration of the compression library - * Copyright (C) 1995-2012 Jean-loup Gailly. + * Copyright (C) 1995-2013 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -44,13 +44,13 @@ typedef unsigned short ush; typedef ush FAR ushf; typedef unsigned long ulg; -extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ +extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ /* (size given to avoid silly warnings with Visual C++) */ #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] #define ERR_RETURN(strm,err) \ - return (strm->msg = (char*)ERR_MSG(err), (err)) + return (strm->msg = ERR_MSG(err), (err)) /* To be used only when the state is known to be valid */ /* common constants */ @@ -168,7 +168,8 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ #endif /* provide prototypes for these when building zlib without LFS */ -#if !defined(_WIN32) && (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) +#if !defined(_WIN32) && \ + (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); #endif