diff options
Diffstat (limited to 'common')
68 files changed, 543 insertions, 445 deletions
diff --git a/common/EventDispatcher.cpp b/common/EventDispatcher.cpp index 5c8a9a3119..617ce32d36 100644 --- a/common/EventDispatcher.cpp +++ b/common/EventDispatcher.cpp @@ -24,7 +24,7 @@ namespace Common { -EventDispatcher::EventDispatcher() : _autoFreeMapper(false), _mapper(0) { +EventDispatcher::EventDispatcher() : _autoFreeMapper(false), _mapper(nullptr) { } EventDispatcher::~EventDispatcher() { @@ -41,7 +41,7 @@ EventDispatcher::~EventDispatcher() { if (_autoFreeMapper) { delete _mapper; } - _mapper = 0; + _mapper = nullptr; } void EventDispatcher::dispatch() { diff --git a/common/algorithm.h b/common/algorithm.h index 0d3a11b348..8384eb7089 100644 --- a/common/algorithm.h +++ b/common/algorithm.h @@ -141,7 +141,8 @@ In find_if(In first, In last, Pred p) { */ template<class In, class Op> Op for_each(In first, In last, Op f) { - while (first != last) f(*first++); + while (first != last) + f(*first++); return f; } diff --git a/common/archive.cpp b/common/archive.cpp index 5a339900b6..7e189654a6 100644 --- a/common/archive.cpp +++ b/common/archive.cpp @@ -253,7 +253,7 @@ const ArchiveMemberPtr SearchSet::getMember(const String &name) const { SeekableReadStream *SearchSet::createReadStreamForMember(const String &name) const { if (name.empty()) - return 0; + return nullptr; ArchiveNodeList::const_iterator it = _list.begin(); for (; it != _list.end(); ++it) { @@ -262,12 +262,12 @@ SeekableReadStream *SearchSet::createReadStreamForMember(const String &name) con return stream; } - return 0; + return nullptr; } SearchManager::SearchManager() { - clear(); // Force a reset + clear(); // Force a reset } void SearchManager::clear() { diff --git a/common/array.h b/common/array.h index d4dac35866..5e8ecb57ab 100644 --- a/common/array.h +++ b/common/array.h @@ -57,7 +57,7 @@ protected: T *_storage; public: - Array() : _capacity(0), _size(0), _storage(0) {} + Array() : _capacity(0), _size(0), _storage(nullptr) {} /** * Constructs an array with `count` default-inserted instances of T. No @@ -77,7 +77,7 @@ public: uninitialized_fill_n(_storage, count, value); } - Array(const Array<T> &array) : _capacity(array._size), _size(array._size), _storage(0) { + Array(const Array<T> &array) : _capacity(array._size), _size(array._size), _storage(nullptr) { if (array._storage) { allocCapacity(_size); uninitialized_copy(array._storage, array._storage + _size, _storage); @@ -96,7 +96,7 @@ public: ~Array() { freeStorage(_storage, _size); - _storage = 0; + _storage = nullptr; _capacity = _size = 0; } @@ -216,7 +216,7 @@ public: void clear() { freeStorage(_storage, _size); - _storage = 0; + _storage = nullptr; _size = 0; _capacity = 0; } @@ -310,7 +310,7 @@ protected: if (!_storage) ::error("Common::Array: failure to allocate %u bytes", capacity * (size_type)sizeof(T)); } else { - _storage = 0; + _storage = nullptr; } } diff --git a/common/config-manager.cpp b/common/config-manager.cpp index fdd0c6f033..e3f0831b47 100644 --- a/common/config-manager.cpp +++ b/common/config-manager.cpp @@ -52,7 +52,7 @@ char const *const ConfigManager::kCloudDomain = "cloud"; #pragma mark - -ConfigManager::ConfigManager() : _activeDomain(0) { +ConfigManager::ConfigManager() : _activeDomain(nullptr) { } void ConfigManager::defragment() { @@ -85,7 +85,7 @@ void ConfigManager::loadDefaultConfigFile() { // Open the default config file assert(g_system); SeekableReadStream *stream = g_system->createConfigReadStream(); - _filename.clear(); // clear the filename to indicate that we are using the default config file + _filename.clear(); // clear the filename to indicate that we are using the default config file // ... load it, if available ... if (stream) { @@ -321,7 +321,7 @@ void ConfigManager::flushToDisk() { void ConfigManager::writeDomain(WriteStream &stream, const String &name, const Domain &domain) { if (domain.empty()) - return; // Don't bother writing empty domains. + return; // Don't bother writing empty domains. // WORKAROUND: Fix for bug #1972625 "ALL: On-the-fly targets are // written to the config file": Do not save domains that came from @@ -386,7 +386,7 @@ const ConfigManager::Domain *ConfigManager::getDomain(const String &domName) con if (_miscDomains.contains(domName)) return &_miscDomains[domName]; - return 0; + return nullptr; } ConfigManager::Domain *ConfigManager::getDomain(const String &domName) { @@ -410,7 +410,7 @@ ConfigManager::Domain *ConfigManager::getDomain(const String &domName) { if (_miscDomains.contains(domName)) return &_miscDomains[domName]; - return 0; + return nullptr; } @@ -620,7 +620,7 @@ void ConfigManager::registerDefault(const String &key, bool value) { void ConfigManager::setActiveDomain(const String &domName) { if (domName.empty()) { - _activeDomain = 0; + _activeDomain = nullptr; } else { assert(isValidDomainName(domName)); _activeDomain = &_gameDomains[domName]; @@ -654,7 +654,7 @@ void ConfigManager::removeGameDomain(const String &domName) { assert(isValidDomainName(domName)); if (domName == _activeDomainName) { _activeDomainName.clear(); - _activeDomain = 0; + _activeDomain = nullptr; } _gameDomains.erase(domName); } diff --git a/common/config-manager.h b/common/config-manager.h index 669faaaf88..58f4373dde 100644 --- a/common/config-manager.h +++ b/common/config-manager.h @@ -171,7 +171,7 @@ public: DomainMap::iterator beginGameDomains() { return _gameDomains.begin(); } DomainMap::iterator endGameDomains() { return _gameDomains.end(); } - static void defragment(); // move in memory to reduce fragmentation + static void defragment(); // move in memory to reduce fragmentation void copyFrom(ConfigManager &source); private: @@ -185,7 +185,7 @@ private: Domain _transientDomain; DomainMap _gameDomains; - DomainMap _miscDomains; // Any other domains + DomainMap _miscDomains; // Any other domains Domain _appDomain; Domain _defaultsDomain; diff --git a/common/coroutines.cpp b/common/coroutines.cpp index 248777febd..0e7a1098cf 100644 --- a/common/coroutines.cpp +++ b/common/coroutines.cpp @@ -31,7 +31,7 @@ namespace Common { /** Helper null context instance */ -CoroContext nullContext = NULL; +CoroContext nullContext = nullptr; DECLARE_SINGLETON(CoroutineScheduler); @@ -73,7 +73,7 @@ static void displayCoroStats() { #endif CoroBaseContext::CoroBaseContext(const char *func) - : _line(0), _sleep(0), _subctx(0) { + : _line(0), _sleep(0), _subctx(nullptr) { #ifdef COROUTINE_DEBUG _funcName = func; changeCoroStats(_funcName, +1); @@ -95,9 +95,9 @@ CoroBaseContext::~CoroBaseContext() { //--------------------- Scheduler Class ------------------------ CoroutineScheduler::CoroutineScheduler() { - processList = NULL; - pFreeProcesses = NULL; - pCurrent = NULL; + processList = nullptr; + pFreeProcesses = nullptr; + pCurrent = nullptr; #ifdef DEBUG // diagnostic process counters @@ -105,12 +105,12 @@ CoroutineScheduler::CoroutineScheduler() { maxProcs = 0; #endif - pRCfunction = NULL; + pRCfunction = nullptr; pidCounter = 0; active = new PROCESS; - active->pPrevious = NULL; - active->pNext = NULL; + active->pPrevious = nullptr; + active->pNext = nullptr; reset(); } @@ -118,17 +118,17 @@ CoroutineScheduler::CoroutineScheduler() { CoroutineScheduler::~CoroutineScheduler() { // Kill all running processes (i.e. free memory allocated for their state). PROCESS *pProc = active->pNext; - while (pProc != NULL) { + while (pProc != nullptr) { delete pProc->state; - pProc->state = 0; + pProc->state = nullptr; pProc = pProc->pNext; } free(processList); - processList = NULL; + processList = nullptr; delete active; - active = 0; + active = nullptr; // Clear the event list Common::List<EVENT *>::iterator i; @@ -142,12 +142,12 @@ void CoroutineScheduler::reset() { numProcs = 0; #endif - if (processList == NULL) { + if (processList == nullptr) { // first time - allocate memory for process list processList = (PROCESS *)calloc(CORO_MAX_PROCESSES, sizeof(PROCESS)); // make sure memory allocated - if (processList == NULL) { + if (processList == nullptr) { error("Cannot allocate memory for process data"); } @@ -157,22 +157,22 @@ void CoroutineScheduler::reset() { // Kill all running processes (i.e. free memory allocated for their state). PROCESS *pProc = active->pNext; - while (pProc != NULL) { + while (pProc != nullptr) { delete pProc->state; - pProc->state = 0; + pProc->state = nullptr; Common::fill(&pProc->pidWaiting[0], &pProc->pidWaiting[CORO_MAX_PID_WAITING], 0); pProc = pProc->pNext; } // no active processes - pCurrent = active->pNext = NULL; + pCurrent = active->pNext = nullptr; // place first process on free list pFreeProcesses = processList; // link all other processes after first for (int i = 1; i <= CORO_NUM_PROCESS; i++) { - processList[i - 1].pNext = (i == CORO_NUM_PROCESS) ? NULL : processList + i; + processList[i - 1].pNext = (i == CORO_NUM_PROCESS) ? nullptr : processList + i; processList[i - 1].pPrevious = (i == 1) ? active : processList + (i - 2); } } @@ -223,7 +223,7 @@ void CoroutineScheduler::schedule() { // start dispatching active process list PROCESS *pNext; PROCESS *pProc = active->pNext; - while (pProc != NULL) { + while (pProc != nullptr) { pNext = pProc->pNext; if (--pProc->sleepTime <= 0) { @@ -241,7 +241,7 @@ void CoroutineScheduler::schedule() { // pCurrent may have been changed pNext = pCurrent->pNext; - pCurrent = NULL; + pCurrent = nullptr; } pProc = pNext; @@ -284,16 +284,16 @@ void CoroutineScheduler::reschedule(PPROCESS pReSchedProc) { // Find the last process in the list. // But if the target process is down the list from here, do nothing - for (pEnd = pCurrent; pEnd->pNext != NULL; pEnd = pEnd->pNext) { + for (pEnd = pCurrent; pEnd->pNext != nullptr; pEnd = pEnd->pNext) { if (pEnd->pNext == pReSchedProc) return; } - assert(pEnd->pNext == NULL); + assert(pEnd->pNext == nullptr); // Could be in the middle of a KillProc()! // Dying process was last and this process was penultimate - if (pReSchedProc->pNext == NULL) + if (pReSchedProc->pNext == nullptr) return; // If we're moving the current process, move it back by one, so that the next @@ -306,7 +306,7 @@ void CoroutineScheduler::reschedule(PPROCESS pReSchedProc) { pReSchedProc->pNext->pPrevious = pReSchedProc->pPrevious; pEnd->pNext = pReSchedProc; pReSchedProc->pPrevious = pEnd; - pReSchedProc->pNext = NULL; + pReSchedProc->pNext = nullptr; } void CoroutineScheduler::giveWay(PPROCESS pReSchedProc) { @@ -324,9 +324,9 @@ void CoroutineScheduler::giveWay(PPROCESS pReSchedProc) { PPROCESS pEnd; // Find the last process in the list. - for (pEnd = pCurrent; pEnd->pNext != NULL; pEnd = pEnd->pNext) + for (pEnd = pCurrent; pEnd->pNext != nullptr; pEnd = pEnd->pNext) ; - assert(pEnd->pNext == NULL); + assert(pEnd->pNext == nullptr); // If we're moving the current process, move it back by one, so that the next @@ -339,7 +339,7 @@ void CoroutineScheduler::giveWay(PPROCESS pReSchedProc) { pReSchedProc->pNext->pPrevious = pReSchedProc->pPrevious; pEnd->pNext = pReSchedProc; pReSchedProc->pPrevious = pEnd; - pReSchedProc->pNext = NULL; + pReSchedProc->pNext = nullptr; } void CoroutineScheduler::waitForSingleObject(CORO_PARAM, int pid, uint32 duration, bool *expired) { @@ -366,11 +366,11 @@ void CoroutineScheduler::waitForSingleObject(CORO_PARAM, int pid, uint32 duratio while (g_system->getMillis() <= _ctx->endTime) { // Check to see if a process or event with the given Id exists _ctx->pProcess = getProcess(pid); - _ctx->pEvent = !_ctx->pProcess ? getEvent(pid) : NULL; + _ctx->pEvent = !_ctx->pProcess ? getEvent(pid) : nullptr; // If there's no active process or event, presume it's a process that's finished, // so the waiting can immediately exit - if ((_ctx->pProcess == NULL) && (_ctx->pEvent == NULL)) { + if ((_ctx->pProcess == nullptr) && (_ctx->pEvent == nullptr)) { if (expired) *expired = false; break; @@ -378,7 +378,7 @@ void CoroutineScheduler::waitForSingleObject(CORO_PARAM, int pid, uint32 duratio // If a process was found, don't go into the if statement, and keep waiting. // Likewise if it's an event that's not yet signalled - if ((_ctx->pEvent != NULL) && _ctx->pEvent->signalled) { + if ((_ctx->pEvent != nullptr) && _ctx->pEvent->signalled) { // Unless the event is flagged for manual reset, reset it now if (!_ctx->pEvent->manualReset) _ctx->pEvent->signalled = false; @@ -429,7 +429,7 @@ void CoroutineScheduler::waitForMultipleObjects(CORO_PARAM, int nCount, uint32 * for (_ctx->i = 0; _ctx->i < nCount; ++_ctx->i) { _ctx->pProcess = getProcess(pidList[_ctx->i]); - _ctx->pEvent = !_ctx->pProcess ? getEvent(pidList[_ctx->i]) : NULL; + _ctx->pEvent = !_ctx->pProcess ? getEvent(pidList[_ctx->i]) : nullptr; // Determine the signalled state _ctx->pidSignalled = (_ctx->pProcess) || !_ctx->pEvent ? false : _ctx->pEvent->signalled; @@ -495,7 +495,7 @@ PROCESS *CoroutineScheduler::createProcess(uint32 pid, CORO_ADDR coroAddr, const pProc = pFreeProcesses; // trap no free process - assert(pProc != NULL); // Out of processes + assert(pProc != nullptr); // Out of processes #ifdef DEBUG // one more process in use @@ -506,9 +506,9 @@ PROCESS *CoroutineScheduler::createProcess(uint32 pid, CORO_ADDR coroAddr, const // get link to next free process pFreeProcesses = pProc->pNext; if (pFreeProcesses) - pFreeProcesses->pPrevious = NULL; + pFreeProcesses->pPrevious = nullptr; - if (pCurrent != NULL) { + if (pCurrent != nullptr) { // place new process before the next active process pProc->pNext = pCurrent->pNext; if (pProc->pNext) @@ -532,7 +532,7 @@ PROCESS *CoroutineScheduler::createProcess(uint32 pid, CORO_ADDR coroAddr, const pProc->coroAddr = coroAddr; // clear coroutine state - pProc->state = 0; + pProc->state = nullptr; // wake process up as soon as possible pProc->sleepTime = 1; @@ -575,11 +575,11 @@ void CoroutineScheduler::killProcess(PROCESS *pKillProc) { #endif // Free process' resources - if (pRCfunction != NULL) + if (pRCfunction != nullptr) (pRCfunction)(pKillProc); delete pKillProc->state; - pKillProc->state = 0; + pKillProc->state = nullptr; // Take the process out of the active chain list pKillProc->pPrevious->pNext = pKillProc->pNext; @@ -590,7 +590,7 @@ void CoroutineScheduler::killProcess(PROCESS *pKillProc) { pKillProc->pNext = pFreeProcesses; if (pFreeProcesses) pKillProc->pNext->pPrevious = pKillProc; - pKillProc->pPrevious = NULL; + pKillProc->pPrevious = nullptr; // make pKillProc the first free process pFreeProcesses = pKillProc; @@ -614,7 +614,7 @@ int CoroutineScheduler::killMatchingProcess(uint32 pidKill, int pidMask) { int numKilled = 0; PROCESS *pProc, *pPrev; // process list pointers - for (pProc = active->pNext, pPrev = active; pProc != NULL; pPrev = pProc, pProc = pProc->pNext) { + for (pProc = active->pNext, pPrev = active; pProc != nullptr; pPrev = pProc, pProc = pProc->pNext) { if ((pProc->pid & (uint32)pidMask) == pidKill) { // found a matching process @@ -624,11 +624,11 @@ int CoroutineScheduler::killMatchingProcess(uint32 pidKill, int pidMask) { numKilled++; // Free the process' resources - if (pRCfunction != NULL) + if (pRCfunction != nullptr) (pRCfunction)(pProc); delete pProc->state; - pProc->state = 0; + pProc->state = nullptr; // make prev point to next to unlink pProc pPrev->pNext = pProc->pNext; @@ -637,7 +637,7 @@ int CoroutineScheduler::killMatchingProcess(uint32 pidKill, int pidMask) { // link first free process after pProc pProc->pNext = pFreeProcesses; - pProc->pPrevious = NULL; + pProc->pPrevious = nullptr; pFreeProcesses->pPrevious = pProc; // make pProc the first free process @@ -665,7 +665,7 @@ void CoroutineScheduler::setResourceCallback(VFPTRPP pFunc) { PROCESS *CoroutineScheduler::getProcess(uint32 pid) { PROCESS *pProc = active->pNext; - while ((pProc != NULL) && (pProc->pid != pid)) + while ((pProc != nullptr) && (pProc->pid != pid)) pProc = pProc->pNext; return pProc; @@ -679,7 +679,7 @@ EVENT *CoroutineScheduler::getEvent(uint32 pid) { return evt; } - return NULL; + return nullptr; } diff --git a/common/coroutines.h b/common/coroutines.h index 4fef1a0d4e..5e3fb4cf0e 100644 --- a/common/coroutines.h +++ b/common/coroutines.h @@ -97,7 +97,7 @@ public: ~CoroContextHolder() { if (_ctx && _ctx->_sleep == 0) { delete _ctx; - _ctx = 0; + _ctx = nullptr; } } }; @@ -409,14 +409,14 @@ public: * If the specified process has already run on this tick, make it run * again on the current tick. */ - void reschedule(PPROCESS pReSchedProc = NULL); + void reschedule(PPROCESS pReSchedProc = nullptr); /** * Moves the specified process to the end of the dispatch queue * allowing it to run again within the current game cycle. * @param pGiveProc Which process */ - void giveWay(PPROCESS pReSchedProc = NULL); + void giveWay(PPROCESS pReSchedProc = nullptr); /** * Continously makes a given process wait for another process to finish or event to signal. @@ -425,7 +425,7 @@ public: * @param duration Duration in milliseconds * @param expired If specified, set to true if delay period expired */ - void waitForSingleObject(CORO_PARAM, int pid, uint32 duration, bool *expired = NULL); + void waitForSingleObject(CORO_PARAM, int pid, uint32 duration, bool *expired = nullptr); /** * Continously makes a given process wait for given prcesses to finished or events to be set @@ -437,7 +437,7 @@ public: * @param expired Set to true if delay period expired */ void waitForMultipleObjects(CORO_PARAM, int nCount, uint32 *pidList, bool bWaitAll, - uint32 duration, bool *expired = NULL); + uint32 duration, bool *expired = nullptr); /** * Make the active process sleep for the given duration in milliseconds diff --git a/common/dcl.cpp b/common/dcl.cpp index 75a533aa9d..7c2fc2ce80 100644 --- a/common/dcl.cpp +++ b/common/dcl.cpp @@ -98,7 +98,7 @@ uint32 DecompressorDCL::getBitsLSB(int n) { // Fetching more data to buffer if needed if (_nBits < n) fetchBitsLSB(); - uint32 ret = (_dwBits & ~((~0) << n)); + uint32 ret = (_dwBits & ~(~0UL << n)); _dwBits >>= n; _nBits -= n; return ret; diff --git a/common/dct.cpp b/common/dct.cpp index 27e0c0bf41..9d551b95ba 100644 --- a/common/dct.cpp +++ b/common/dct.cpp @@ -30,7 +30,7 @@ namespace Common { -DCT::DCT(int bits, TransformType trans) : _bits(bits), _cos(_bits + 2), _trans(trans), _rdft(0) { +DCT::DCT(int bits, TransformType trans) : _bits(bits), _cos(_bits + 2), _trans(trans), _rdft(nullptr) { int n = 1 << _bits; _tCos = _cos.getTable(); diff --git a/common/fft.cpp b/common/fft.cpp index 27a04abb6a..a750792047 100644 --- a/common/fft.cpp +++ b/common/fft.cpp @@ -51,7 +51,7 @@ FFT::FFT(int bits, int inverse) : _bits(bits), _inverse(inverse) { if (i+4 <= _bits) _cosTables[i] = new Common::CosineTable(i+4); else - _cosTables[i] = 0; + _cosTables[i] = nullptr; } } diff --git a/common/file.cpp b/common/file.cpp index 9797bcaa69..5fc4f9012b 100644 --- a/common/file.cpp +++ b/common/file.cpp @@ -31,7 +31,7 @@ namespace Common { File::File() - : _handle(0) { + : _handle(nullptr) { } File::~File() { @@ -46,7 +46,7 @@ bool File::open(const String &filename, Archive &archive) { assert(!filename.empty()); assert(!_handle); - SeekableReadStream *stream = 0; + SeekableReadStream *stream = nullptr; if ((stream = archive.createReadStreamForMember(filename))) { debug(8, "Opening hashed: %s", filename.c_str()); @@ -83,7 +83,7 @@ bool File::open(SeekableReadStream *stream, const String &name) { } else { debug(2, "File::open: opening '%s' failed", name.c_str()); } - return _handle != NULL; + return _handle != nullptr; } @@ -101,11 +101,11 @@ bool File::exists(const String &filename) { void File::close() { delete _handle; - _handle = NULL; + _handle = nullptr; } bool File::isOpen() const { - return _handle != NULL; + return _handle != nullptr; } bool File::err() const { @@ -144,7 +144,7 @@ uint32 File::read(void *ptr, uint32 len) { } -DumpFile::DumpFile() : _handle(0) { +DumpFile::DumpFile() : _handle(nullptr) { } DumpFile::~DumpFile() { @@ -182,19 +182,19 @@ bool DumpFile::open(const FSNode &node) { _handle = node.createWriteStream(); - if (_handle == NULL) + if (_handle == nullptr) debug(2, "File %s not found", node.getName().c_str()); - return _handle != NULL; + return _handle != nullptr; } void DumpFile::close() { delete _handle; - _handle = NULL; + _handle = nullptr; } bool DumpFile::isOpen() const { - return _handle != NULL; + return _handle != nullptr; } bool DumpFile::err() const { diff --git a/common/fs.cpp b/common/fs.cpp index 3a7026b1cc..d93270ff0d 100644 --- a/common/fs.cpp +++ b/common/fs.cpp @@ -37,7 +37,7 @@ FSNode::FSNode(AbstractFSNode *realNode) FSNode::FSNode(const String &p) { assert(g_system); FilesystemFactory *factory = g_system->getFilesystemFactory(); - AbstractFSNode *tmp = 0; + AbstractFSNode *tmp = nullptr; if (p.empty() || p == ".") tmp = factory->makeCurrentDirectoryFileNode(); @@ -62,7 +62,7 @@ bool FSNode::exists() const { FSNode FSNode::getChild(const String &n) const { // If this node is invalid or not a directory, return an invalid node - if (_realNode == 0 || !_realNode->isDirectory()) + if (_realNode == nullptr || !_realNode->isDirectory()) return FSNode(); AbstractFSNode *node = _realNode->getChild(n); @@ -97,11 +97,11 @@ String FSNode::getName() const { } FSNode FSNode::getParent() const { - if (_realNode == 0) + if (_realNode == nullptr) return *this; AbstractFSNode *node = _realNode->getParent(); - if (node == 0) { + if (node == nullptr) { return *this; } else { return FSNode(node); @@ -126,27 +126,27 @@ bool FSNode::isWritable() const { } SeekableReadStream *FSNode::createReadStream() const { - if (_realNode == 0) - return 0; + if (_realNode == nullptr) + return nullptr; if (!_realNode->exists()) { warning("FSNode::createReadStream: '%s' does not exist", getName().c_str()); - return 0; + return nullptr; } else if (_realNode->isDirectory()) { warning("FSNode::createReadStream: '%s' is a directory", getName().c_str()); - return 0; + return nullptr; } return _realNode->createReadStream(); } WriteStream *FSNode::createWriteStream() const { - if (_realNode == 0) - return 0; + if (_realNode == nullptr) + return nullptr; if (_realNode->isDirectory()) { warning("FSNode::createWriteStream: '%s' is a directory", getName().c_str()); - return 0; + return nullptr; } return _realNode->createWriteStream(); @@ -195,7 +195,7 @@ FSNode *FSDirectory::lookupCache(NodeCache &cache, const String &name) const { return &cache[name]; } - return 0; + return nullptr; } bool FSDirectory::hasFile(const String &name) const { @@ -225,11 +225,11 @@ const ArchiveMemberPtr FSDirectory::getMember(const String &name) const { SeekableReadStream *FSDirectory::createReadStreamForMember(const String &name) const { if (name.empty() || !_node.isDirectory()) - return 0; + return nullptr; FSNode *node = lookupCache(_fileCache, name); if (!node) - return 0; + return nullptr; SeekableReadStream *stream = node->createReadStream(); if (!stream) warning("FSDirectory::createReadStreamForMember: Can't create stream for file '%s'", name.c_str()); @@ -243,11 +243,11 @@ FSDirectory *FSDirectory::getSubDirectory(const String &name, int depth, bool fl FSDirectory *FSDirectory::getSubDirectory(const String &prefix, const String &name, int depth, bool flat) { if (name.empty() || !_node.isDirectory()) - return 0; + return nullptr; FSNode *node = lookupCache(_subDirCache, name); if (!node) - return 0; + return nullptr; return new FSDirectory(prefix, *node, depth, flat); } diff --git a/common/fs.h b/common/fs.h index f516bf7a9c..ed287cc17a 100644 --- a/common/fs.h +++ b/common/fs.h @@ -269,7 +269,7 @@ public: class FSDirectory : public Archive { FSNode _node; - String _prefix; // string that is prepended to each cache item key + String _prefix; // string that is prepended to each cache item key void setPrefix(const String &prefix); // Caches are case insensitive, clashes are dealt with when creating diff --git a/common/gui_options.cpp b/common/gui_options.cpp index 6f340bf88f..06b6c20a61 100644 --- a/common/gui_options.cpp +++ b/common/gui_options.cpp @@ -86,7 +86,7 @@ const struct GameOpt { { GUIO_GAMEOPTIONS11, "gameOptionB" }, { GUIO_GAMEOPTIONS12, "gameOptionC" }, - { GUIO_NONE, 0 } + { GUIO_NONE, nullptr } }; bool checkGameGUIOption(const String &option, const String &str) { diff --git a/common/hash-str.h b/common/hash-str.h index 82af6cca93..fcd41ab6a7 100644 --- a/common/hash-str.h +++ b/common/hash-str.h @@ -29,11 +29,10 @@ namespace Common { uint hashit(const char *str); -uint hashit_lower(const char *str); // Generate a hash based on the lowercase version of the string +uint hashit_lower(const char *str); // Generate a hash based on the lowercase version of the string inline uint hashit(const String &str) { return hashit(str.c_str()); } inline uint hashit_lower(const String &str) { return hashit_lower(str.c_str()); } - // FIXME: The following functors obviously are not consistently named struct CaseSensitiveString_EqualTo { @@ -53,8 +52,6 @@ struct IgnoreCase_Hash { uint operator()(const String& x) const { return hashit_lower(x.c_str()); } }; - - // Specalization of the Hash functor for String objects. // We do case sensitve hashing here, because that is what // the default EqualTo is compatible with. If one wants to use @@ -78,9 +75,6 @@ struct Hash<const char *> { // String map -- by default case insensitive typedef HashMap<String, String, IgnoreCase_Hash, IgnoreCase_EqualTo> StringMap; - - } // End of namespace Common - #endif diff --git a/common/hashmap.cpp b/common/hashmap.cpp index 99840993ce..e9eac9fc94 100644 --- a/common/hashmap.cpp +++ b/common/hashmap.cpp @@ -95,10 +95,10 @@ void updateHashCollisionStats(int collisions, int dummyHits, int lookups, int ar g_size / g_totalHashmaps, g_max_size, g_capacity / g_totalHashmaps, g_max_capacity); debug(" %d less than %d; %d less than %d; %d less than %d; %d less than %d", - g_stats[0], 2*8/3, - g_stats[1],2*16/3, - g_stats[2],2*32/3, - g_stats[3],2*64/3); + g_stats[0], 2 * 8 / 3, + g_stats[1], 2 * 16 / 3, + g_stats[2], 2 * 32 / 3, + g_stats[3], 2 * 64 / 3); // TODO: // * Should record the maximal size of the map during its lifetime, not that at its death diff --git a/common/hashmap.h b/common/hashmap.h index d7ba100571..1f93b68455 100644 --- a/common/hashmap.h +++ b/common/hashmap.h @@ -178,16 +178,16 @@ private: IteratorImpl(size_type idx, hashmap_t *hashmap) : _idx(idx), _hashmap(hashmap) {} NodeType *deref() const { - assert(_hashmap != 0); + assert(_hashmap != nullptr); assert(_idx <= _hashmap->_mask); Node *node = _hashmap->_storage[_idx]; - assert(node != 0); + assert(node != nullptr); assert(node != HASHMAP_DUMMY_NODE); return node; } public: - IteratorImpl() : _idx(0), _hashmap(0) {} + IteratorImpl() : _idx(0), _hashmap(nullptr) {} template<class T> IteratorImpl(const IteratorImpl<T> &c) : _idx(c._idx), _hashmap(c._hashmap) {} @@ -201,7 +201,7 @@ private: assert(_hashmap); do { _idx++; - } while (_idx <= _hashmap->_mask && (_hashmap->_storage[_idx] == 0 || _hashmap->_storage[_idx] == HASHMAP_DUMMY_NODE)); + } while (_idx <= _hashmap->_mask && (_hashmap->_storage[_idx] == nullptr || _hashmap->_storage[_idx] == HASHMAP_DUMMY_NODE)); if (_idx > _hashmap->_mask) _idx = (size_type)-1; @@ -315,7 +315,7 @@ HashMap<Key, Val, HashFunc, EqualFunc>::HashMap() #endif _mask = HASHMAP_MIN_CAPACITY - 1; _storage = new Node *[HASHMAP_MIN_CAPACITY]; - assert(_storage != NULL); + assert(_storage != nullptr); memset(_storage, 0, HASHMAP_MIN_CAPACITY * sizeof(Node *)); _size = 0; @@ -355,7 +355,7 @@ HashMap<Key, Val, HashFunc, EqualFunc>::~HashMap() { delete[] _storage; #ifdef DEBUG_HASH_COLLISIONS extern void updateHashCollisionStats(int, int, int, int, int); - updateHashCollisionStats(_collisions, _dummyHits, _lookups, _mask+1, _size); + updateHashCollisionStats(_collisions, _dummyHits, _lookups, _mask + 1, _size); #endif } @@ -369,9 +369,9 @@ HashMap<Key, Val, HashFunc, EqualFunc>::~HashMap() { template<class Key, class Val, class HashFunc, class EqualFunc> void HashMap<Key, Val, HashFunc, EqualFunc>::assign(const HM_t &map) { _mask = map._mask; - _storage = new Node *[_mask+1]; - assert(_storage != NULL); - memset(_storage, 0, (_mask+1) * sizeof(Node *)); + _storage = new Node *[_mask + 1]; + assert(_storage != nullptr); + memset(_storage, 0, (_mask + 1) * sizeof(Node *)); // Simply clone the map given to us, one by one. _size = 0; @@ -380,7 +380,7 @@ void HashMap<Key, Val, HashFunc, EqualFunc>::assign(const HM_t &map) { if (map._storage[ctr] == HASHMAP_DUMMY_NODE) { _storage[ctr] = HASHMAP_DUMMY_NODE; _deleted++; - } else if (map._storage[ctr] != NULL) { + } else if (map._storage[ctr] != nullptr) { _storage[ctr] = allocNode(map._storage[ctr]->_key); _storage[ctr]->_value = map._storage[ctr]->_value; _size++; @@ -396,7 +396,7 @@ template<class Key, class Val, class HashFunc, class EqualFunc> void HashMap<Key, Val, HashFunc, EqualFunc>::clear(bool shrinkArray) { for (size_type ctr = 0; ctr <= _mask; ++ctr) { freeNode(_storage[ctr]); - _storage[ctr] = NULL; + _storage[ctr] = nullptr; } #ifdef USE_HASHMAP_MEMORY_POOL @@ -406,9 +406,9 @@ void HashMap<Key, Val, HashFunc, EqualFunc>::clear(bool shrinkArray) { if (shrinkArray && _mask >= HASHMAP_MIN_CAPACITY) { delete[] _storage; - _mask = HASHMAP_MIN_CAPACITY; + _mask = HASHMAP_MIN_CAPACITY - 1; _storage = new Node *[HASHMAP_MIN_CAPACITY]; - assert(_storage != NULL); + assert(_storage != nullptr); memset(_storage, 0, HASHMAP_MIN_CAPACITY * sizeof(Node *)); } @@ -418,7 +418,7 @@ void HashMap<Key, Val, HashFunc, EqualFunc>::clear(bool shrinkArray) { template<class Key, class Val, class HashFunc, class EqualFunc> void HashMap<Key, Val, HashFunc, EqualFunc>::expandStorage(size_type newCapacity) { - assert(newCapacity > _mask+1); + assert(newCapacity > _mask + 1); #ifndef NDEBUG const size_type old_size = _size; @@ -431,12 +431,12 @@ void HashMap<Key, Val, HashFunc, EqualFunc>::expandStorage(size_type newCapacity _deleted = 0; _mask = newCapacity - 1; _storage = new Node *[newCapacity]; - assert(_storage != NULL); + assert(_storage != nullptr); memset(_storage, 0, newCapacity * sizeof(Node *)); // rehash all the old elements for (size_type ctr = 0; ctr <= old_mask; ++ctr) { - if (old_storage[ctr] == NULL || old_storage[ctr] == HASHMAP_DUMMY_NODE) + if (old_storage[ctr] == nullptr || old_storage[ctr] == HASHMAP_DUMMY_NODE) continue; // Insert the element from the old table into the new table. @@ -445,7 +445,7 @@ void HashMap<Key, Val, HashFunc, EqualFunc>::expandStorage(size_type newCapacity // don't have to call _equal(). const size_type hash = _hash(old_storage[ctr]->_key); size_type idx = hash & _mask; - for (size_type perturb = hash; _storage[idx] != NULL && _storage[idx] != HASHMAP_DUMMY_NODE; perturb >>= HASHMAP_PERTURB_SHIFT) { + for (size_type perturb = hash; _storage[idx] != nullptr && _storage[idx] != HASHMAP_DUMMY_NODE; perturb >>= HASHMAP_PERTURB_SHIFT) { idx = (5 * idx + perturb + 1) & _mask; } @@ -467,7 +467,7 @@ typename HashMap<Key, Val, HashFunc, EqualFunc>::size_type HashMap<Key, Val, Has const size_type hash = _hash(key); size_type ctr = hash & _mask; for (size_type perturb = hash; ; perturb >>= HASHMAP_PERTURB_SHIFT) { - if (_storage[ctr] == NULL) + if (_storage[ctr] == nullptr) break; if (_storage[ctr] == HASHMAP_DUMMY_NODE) { #ifdef DEBUG_HASH_COLLISIONS @@ -487,7 +487,7 @@ typename HashMap<Key, Val, HashFunc, EqualFunc>::size_type HashMap<Key, Val, Has _lookups++; debug("collisions %d, dummies hit %d, lookups %d, ratio %f in HashMap %p; size %d num elements %d", _collisions, _dummyHits, _lookups, ((double) _collisions / (double)_lookups), - (const void *)this, _mask+1, _size); + (const void *)this, _mask + 1, _size); #endif return ctr; @@ -501,7 +501,7 @@ typename HashMap<Key, Val, HashFunc, EqualFunc>::size_type HashMap<Key, Val, Has size_type first_free = NONE_FOUND; bool found = false; for (size_type perturb = hash; ; perturb >>= HASHMAP_PERTURB_SHIFT) { - if (_storage[ctr] == NULL) + if (_storage[ctr] == nullptr) break; if (_storage[ctr] == HASHMAP_DUMMY_NODE) { #ifdef DEBUG_HASH_COLLISIONS @@ -525,7 +525,7 @@ typename HashMap<Key, Val, HashFunc, EqualFunc>::size_type HashMap<Key, Val, Has _lookups++; debug("collisions %d, dummies hit %d, lookups %d, ratio %f in HashMap %p; size %d num elements %d", _collisions, _dummyHits, _lookups, ((double) _collisions / (double)_lookups), - (const void *)this, _mask+1, _size); + (const void *)this, _mask + 1, _size); #endif if (!found && first_free != _mask + 1) @@ -535,7 +535,7 @@ typename HashMap<Key, Val, HashFunc, EqualFunc>::size_type HashMap<Key, Val, Has if (_storage[ctr]) _deleted--; _storage[ctr] = allocNode(key); - assert(_storage[ctr] != NULL); + assert(_storage[ctr] != nullptr); _size++; // Keep the load factor below a certain threshold. @@ -546,7 +546,7 @@ typename HashMap<Key, Val, HashFunc, EqualFunc>::size_type HashMap<Key, Val, Has capacity = capacity < 500 ? (capacity * 4) : (capacity * 2); expandStorage(capacity); ctr = lookup(key); - assert(_storage[ctr] != NULL); + assert(_storage[ctr] != nullptr); } } @@ -557,7 +557,7 @@ typename HashMap<Key, Val, HashFunc, EqualFunc>::size_type HashMap<Key, Val, Has template<class Key, class Val, class HashFunc, class EqualFunc> bool HashMap<Key, Val, HashFunc, EqualFunc>::contains(const Key &key) const { size_type ctr = lookup(key); - return (_storage[ctr] != NULL); + return (_storage[ctr] != nullptr); } template<class Key, class Val, class HashFunc, class EqualFunc> @@ -573,7 +573,7 @@ const Val &HashMap<Key, Val, HashFunc, EqualFunc>::operator[](const Key &key) co template<class Key, class Val, class HashFunc, class EqualFunc> Val &HashMap<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key) { size_type ctr = lookupAndCreateIfMissing(key); - assert(_storage[ctr] != NULL); + assert(_storage[ctr] != nullptr); return _storage[ctr]->_value; } @@ -585,7 +585,7 @@ const Val &HashMap<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key) const template<class Key, class Val, class HashFunc, class EqualFunc> const Val &HashMap<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key, const Val &defaultVal) const { size_type ctr = lookup(key); - if (_storage[ctr] != NULL) + if (_storage[ctr] != nullptr) return _storage[ctr]->_value; else return defaultVal; @@ -594,7 +594,7 @@ const Val &HashMap<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key, const template<class Key, class Val, class HashFunc, class EqualFunc> void HashMap<Key, Val, HashFunc, EqualFunc>::setVal(const Key &key, const Val &val) { size_type ctr = lookupAndCreateIfMissing(key); - assert(_storage[ctr] != NULL); + assert(_storage[ctr] != nullptr); _storage[ctr]->_value = val; } @@ -619,7 +619,7 @@ template<class Key, class Val, class HashFunc, class EqualFunc> void HashMap<Key, Val, HashFunc, EqualFunc>::erase(const Key &key) { size_type ctr = lookup(key); - if (_storage[ctr] == NULL) + if (_storage[ctr] == nullptr) return; // If we remove a key, we replace it with a dummy node. diff --git a/common/huffman.h b/common/huffman.h index f703d078dc..b4de5ab483 100644 --- a/common/huffman.h +++ b/common/huffman.h @@ -47,11 +47,11 @@ public: * @param lengths Lengths of the individual codes. * @param symbols The symbols. If 0, assume they are identical to the code indices. */ - Huffman(uint8 maxLength, uint32 codeCount, const uint32 *codes, const uint8 *lengths, const uint32 *symbols = 0); + Huffman(uint8 maxLength, uint32 codeCount, const uint32 *codes, const uint8 *lengths, const uint32 *symbols = nullptr); ~Huffman(); /** Modify the codes' symbols. */ - void setSymbols(const uint32 *symbols = 0); + void setSymbols(const uint32 *symbols = nullptr); /** Return the next symbol in the bitstream. */ template<class BITSTREAM> diff --git a/common/iff_container.cpp b/common/iff_container.cpp index 1eee7ad71e..98d12dc417 100644 --- a/common/iff_container.cpp +++ b/common/iff_container.cpp @@ -34,7 +34,7 @@ IFFParser::~IFFParser() { if (_disposeStream) { delete _stream; } - _stream = 0; + _stream = nullptr; } void IFFParser::setInputStream(ReadStream *stream) { diff --git a/common/iff_container.h b/common/iff_container.h index e684f253b2..a88b159733 100644 --- a/common/iff_container.h +++ b/common/iff_container.h @@ -172,7 +172,7 @@ class IFFParser { IFF_ID id; uint32 size; - IFFChunkNav() : _input(0) { + IFFChunkNav() : _input(nullptr) { } void setInputStream(ReadStream *input) { _input = input; diff --git a/common/ini-file.cpp b/common/ini-file.cpp index 7fa17da76c..7e5a098b4e 100644 --- a/common/ini-file.cpp +++ b/common/ini-file.cpp @@ -249,7 +249,7 @@ void INIFile::removeSection(const String §ion) { bool INIFile::hasSection(const String §ion) const { assert(isValidName(section)); const Section *s = getSection(section); - return s != 0; + return s != nullptr; } void INIFile::renameSection(const String &oldName, const String &newName) { @@ -341,7 +341,7 @@ INIFile::Section *INIFile::getSection(const String §ion) { return &(*i); } } - return 0; + return nullptr; } const INIFile::Section *INIFile::getSection(const String §ion) const { @@ -350,11 +350,11 @@ const INIFile::Section *INIFile::getSection(const String §ion) const { return &(*i); } } - return 0; + return nullptr; } bool INIFile::Section::hasKey(const String &key) const { - return getKey(key) != 0; + return getKey(key) != nullptr; } const INIFile::KeyValue* INIFile::Section::getKey(const String &key) const { @@ -363,7 +363,7 @@ const INIFile::KeyValue* INIFile::Section::getKey(const String &key) const { return &(*i); } } - return 0; + return nullptr; } void INIFile::Section::setKey(const String &key, const String &value) { diff --git a/common/installshield_cab.cpp b/common/installshield_cab.cpp index e9e8586185..a7fcf81607 100644 --- a/common/installshield_cab.cpp +++ b/common/installshield_cab.cpp @@ -174,7 +174,7 @@ const ArchiveMemberPtr InstallShieldCabinet::getMember(const String &name) const SeekableReadStream *InstallShieldCabinet::createReadStreamForMember(const String &name) const { if (!_map.contains(name)) - return 0; + return nullptr; const FileEntry &entry = _map[name]; @@ -195,7 +195,7 @@ SeekableReadStream *InstallShieldCabinet::createReadStreamForMember(const String if (!result) { warning("failed to inflate CAB file '%s'", name.c_str()); free(dst); - return 0; + return nullptr; } return new MemoryReadStream(dst, entry.uncompressedSize, DisposeAfterUse::YES); diff --git a/common/json.cpp b/common/json.cpp index c8caf01519..89f780bfc8 100644 --- a/common/json.cpp +++ b/common/json.cpp @@ -76,17 +76,17 @@ JSON::JSON() {} JSONValue *JSON::parse(const char *data) { // Skip any preceding whitespace, end of data = no JSON = fail if (!skipWhitespace(&data)) - return NULL; + return nullptr; // We need the start of a value here now... JSONValue *value = JSONValue::parse(&data); - if (value == NULL) - return NULL; + if (value == nullptr) + return nullptr; // Can be white space now and should be at the end of the string then... if (skipWhitespace(&data)) { delete value; - return NULL; + return nullptr; } // We're now at the end of the string @@ -103,7 +103,7 @@ JSONValue *JSON::parse(const char *data) { * @return String Returns a JSON encoded string representation of the given value */ String JSON::stringify(const JSONValue *value) { - if (value != NULL) + if (value != nullptr) return value->stringify(); else return ""; @@ -276,7 +276,7 @@ JSONValue *JSONValue::parse(const char **data) { if (**data == '"') { String str; if (!JSON::extractString(&(++(*data)), str)) - return NULL; + return nullptr; else return new JSONValue(str); } @@ -310,7 +310,7 @@ JSONValue *JSONValue::parse(const char **data) { else if (**data >= '1' && **data <= '9') number = integer = JSON::parseInt(data); else - return NULL; + return nullptr; // Could be a decimal now... if (**data == '.') { @@ -318,7 +318,7 @@ JSONValue *JSONValue::parse(const char **data) { // Not get any digits? if (!(**data >= '0' && **data <= '9')) - return NULL; + return nullptr; // Find the decimal and sort the decimal place out // Use ParseDecimal as ParseInt won't work with decimals less than 0.1 @@ -343,7 +343,7 @@ JSONValue *JSONValue::parse(const char **data) { // Not get any digits? if (!(**data >= '0' && **data <= '9')) - return NULL; + return nullptr; // Sort the expo out double expo = JSON::parseInt(data); @@ -371,7 +371,7 @@ JSONValue *JSONValue::parse(const char **data) { // Whitespace at the start? if (!JSON::skipWhitespace(data)) { FREE_OBJECT(object); - return NULL; + return nullptr; } // Special case - empty object @@ -384,32 +384,32 @@ JSONValue *JSONValue::parse(const char **data) { String name; if (!JSON::extractString(&(++(*data)), name)) { FREE_OBJECT(object); - return NULL; + return nullptr; } // More whitespace? if (!JSON::skipWhitespace(data)) { FREE_OBJECT(object); - return NULL; + return nullptr; } // Need a : now if (*((*data)++) != ':') { FREE_OBJECT(object); - return NULL; + return nullptr; } // More whitespace? if (!JSON::skipWhitespace(data)) { FREE_OBJECT(object); - return NULL; + return nullptr; } // The value is here JSONValue *value = parse(data); - if (value == NULL) { + if (value == nullptr) { FREE_OBJECT(object); - return NULL; + return nullptr; } // Add the name:value @@ -420,7 +420,7 @@ JSONValue *JSONValue::parse(const char **data) { // More whitespace? if (!JSON::skipWhitespace(data)) { FREE_OBJECT(object); - return NULL; + return nullptr; } // End of object? @@ -432,7 +432,7 @@ JSONValue *JSONValue::parse(const char **data) { // Want a , now if (**data != ',') { FREE_OBJECT(object); - return NULL; + return nullptr; } (*data)++; @@ -440,7 +440,7 @@ JSONValue *JSONValue::parse(const char **data) { // Only here if we ran out of data FREE_OBJECT(object); - return NULL; + return nullptr; } // An array? @@ -453,7 +453,7 @@ JSONValue *JSONValue::parse(const char **data) { // Whitespace at the start? if (!JSON::skipWhitespace(data)) { FREE_ARRAY(array); - return NULL; + return nullptr; } // Special case - empty array @@ -464,9 +464,9 @@ JSONValue *JSONValue::parse(const char **data) { // Get the value JSONValue *value = parse(data); - if (value == NULL) { + if (value == nullptr) { FREE_ARRAY(array); - return NULL; + return nullptr; } // Add the value @@ -475,7 +475,7 @@ JSONValue *JSONValue::parse(const char **data) { // More whitespace? if (!JSON::skipWhitespace(data)) { FREE_ARRAY(array); - return NULL; + return nullptr; } // End of array? @@ -487,7 +487,7 @@ JSONValue *JSONValue::parse(const char **data) { // Want a , now if (**data != ',') { FREE_ARRAY(array); - return NULL; + return nullptr; } (*data)++; @@ -495,12 +495,12 @@ JSONValue *JSONValue::parse(const char **data) { // Only here if we ran out of data FREE_ARRAY(array); - return NULL; + return nullptr; } // Ran out of possibilites, it's bad! else { - return NULL; + return nullptr; } } @@ -871,7 +871,7 @@ JSONValue *JSONValue::child(std::size_t index) { if (index < _arrayValue->size()) { return (*_arrayValue)[index]; } else { - return NULL; + return nullptr; } } @@ -905,7 +905,7 @@ JSONValue *JSONValue::child(const char *name) { if (it != _objectValue->end()) { return it->_value; } else { - return NULL; + return nullptr; } } diff --git a/common/json.h b/common/json.h index 3b219993e7..a911196d18 100644 --- a/common/json.h +++ b/common/json.h @@ -65,7 +65,7 @@ static inline bool isinf(double x) { // Simple function to check a string 's' has at least 'n' characters static inline bool simplejson_wcsnlen(const char *s, size_t n) { - if (s == 0) + if (s == nullptr) return false; const char *save = s; diff --git a/common/language.cpp b/common/language.cpp index b7397bec6d..4d40744d2f 100644 --- a/common/language.cpp +++ b/common/language.cpp @@ -46,13 +46,13 @@ const LanguageDescription g_languages[] = { { "jp", "ja_JP", "Japanese", JA_JPN }, { "kr", "ko_KR", "Korean", KO_KOR }, { "lv", "lv_LV", "Latvian", LV_LAT }, - { "nb", "nb_NO", "Norwegian Bokm\xE5l", NB_NOR }, // TODO Someone should verify the unix locale + { "nb", "nb_NO", "Norwegian Bokm\xE5l", NB_NOR }, { "pl", "pl_PL", "Polish", PL_POL }, { "br", "pt_BR", "Portuguese", PT_BRA }, { "ru", "ru_RU", "Russian", RU_RUS }, { "es", "es_ES", "Spanish", ES_ESP }, { "se", "sv_SE", "Swedish", SE_SWE }, - { 0, 0, 0, UNK_LANG } + { nullptr, nullptr, nullptr, UNK_LANG } }; Language parseLanguage(const String &str) { @@ -87,7 +87,7 @@ const char *getLanguageCode(Language id) { if (l->id == id) return l->code; } - return 0; + return nullptr; } const char *getLanguageLocale(Language id) { @@ -96,7 +96,7 @@ const char *getLanguageLocale(Language id) { if (l->id == id) return l->unixLocale; } - return 0; + return nullptr; } const char *getLanguageDescription(Language id) { @@ -105,7 +105,7 @@ const char *getLanguageDescription(Language id) { if (l->id == id) return l->description; } - return 0; + return nullptr; } bool checkGameGUIOptionLanguage(Language lang, const String &str) { diff --git a/common/list.h b/common/list.h index 1bb4a2a5df..31cf161d22 100644 --- a/common/list.h +++ b/common/list.h @@ -170,7 +170,7 @@ public: const_iterator i2; const_iterator e2 = list.end(); - for (i = begin(), i2 = list.begin(); (i != e) && (i2 != e2) ; ++i, ++i2) { + for (i = begin(), i2 = list.begin(); (i != e) && (i2 != e2); ++i, ++i2) { static_cast<Node *>(i._node)->_data = static_cast<const Node *>(i2._node)->_data; } diff --git a/common/list_intern.h b/common/list_intern.h index b4f347561b..37f9259e54 100644 --- a/common/list_intern.h +++ b/common/list_intern.h @@ -55,7 +55,7 @@ namespace ListInternal { NodeBase *_node; - Iterator() : _node(0) {} + Iterator() : _node(nullptr) {} explicit Iterator(NodeBase *node) : _node(node) {} // Prefix inc @@ -108,7 +108,7 @@ namespace ListInternal { const NodeBase *_node; - ConstIterator() : _node(0) {} + ConstIterator() : _node(nullptr) {} explicit ConstIterator(const NodeBase *node) : _node(node) {} ConstIterator(const Iterator<T> &x) : _node(x._node) {} diff --git a/common/macresman.cpp b/common/macresman.cpp index adca1ea10b..553b138717 100644 --- a/common/macresman.cpp +++ b/common/macresman.cpp @@ -67,9 +67,9 @@ void MacResManager::close() { delete[] _resLists[i]; } - delete[] _resLists; _resLists = 0; - delete[] _resTypes; _resTypes = 0; - delete _stream; _stream = 0; + delete[] _resLists; _resLists = nullptr; + delete[] _resTypes; _resTypes = nullptr; + delete _stream; _stream = nullptr; _resMap.numTypes = 0; } @@ -463,7 +463,7 @@ bool MacResManager::load(SeekableReadStream &stream) { SeekableReadStream *MacResManager::getDataFork() { if (!_stream) - return NULL; + return nullptr; if (_mode == kResForkMacBinary) { _stream->seek(MBI_DFLEN); @@ -476,7 +476,7 @@ SeekableReadStream *MacResManager::getDataFork() { return file; delete file; - return NULL; + return nullptr; } MacResIDArray MacResManager::getResIDArray(uint32 typeID) { @@ -544,7 +544,7 @@ SeekableReadStream *MacResManager::getResource(uint32 typeID, uint16 resID) { } if (typeNum == -1) - return NULL; + return nullptr; for (int i = 0; i < _resTypes[typeNum].items; i++) if (_resLists[typeNum][i].id == resID) { @@ -553,14 +553,14 @@ SeekableReadStream *MacResManager::getResource(uint32 typeID, uint16 resID) { } if (resNum == -1) - return NULL; + return nullptr; _stream->seek(_dataOffset + _resLists[typeNum][resNum].dataOffset); uint32 len = _stream->readUint32BE(); // Ignore resources with 0 length if (!len) - return 0; + return nullptr; return _stream->readStream(len); } @@ -574,14 +574,14 @@ SeekableReadStream *MacResManager::getResource(const String &fileName) { // Ignore resources with 0 length if (!len) - return 0; + return nullptr; return _stream->readStream(len); } } } - return 0; + return nullptr; } SeekableReadStream *MacResManager::getResource(uint32 typeID, const String &fileName) { @@ -596,14 +596,14 @@ SeekableReadStream *MacResManager::getResource(uint32 typeID, const String &file // Ignore resources with 0 length if (!len) - return 0; + return nullptr; return _stream->readStream(len); } } } - return 0; + return nullptr; } void MacResManager::readMap() { @@ -640,7 +640,7 @@ void MacResManager::readMap() { resPtr->nameOffset = _stream->readUint16BE(); resPtr->dataOffset = _stream->readUint32BE(); _stream->readUint32BE(); - resPtr->name = 0; + resPtr->name = nullptr; resPtr->attr = resPtr->dataOffset >> 24; resPtr->dataOffset &= 0xFFFFFF; diff --git a/common/math.h b/common/math.h index ddb5c67dfe..7b2ec6060e 100644 --- a/common/math.h +++ b/common/math.h @@ -107,12 +107,46 @@ inline int intLog2(uint32 v) { } #endif -inline float rad2deg(float rad) { - return rad * 180.0f / (float)M_PI; +// Convert radians to degrees +// Input and Output type can be different +// Upconvert everything to floats +template<class InputT, class OutputT> +inline OutputT rad2deg(InputT rad) { + return (OutputT)( (float)rad * (float)57.2957795130823); // 180.0/M_PI = 57.2957795130823 } -inline float deg2rad(float deg) { - return deg * (float)M_PI / 180.0f; +// Handle the case differently when the input type is double +template<class OutputT> +inline OutputT rad2deg(double rad) { + return (OutputT)( rad * 57.2957795130823); +} + +// Convert radians to degrees +// Input and Output type are the same +template<class T> +inline T rad2deg(T rad) { + return rad2deg<T,T>(rad); +} + +// Convert degrees to radians +// Input and Output type can be different +// Upconvert everything to floats +template<class InputT, class OutputT> +inline OutputT deg2rad(InputT deg) { + return (OutputT)( (float)deg * (float)0.0174532925199433); // M_PI/180.0 = 0.0174532925199433 +} + +// Handle the case differently when the input type is double +template<class OutputT> +inline OutputT deg2rad(double deg) { + return (OutputT)( deg * 0.0174532925199433); +} + +// Convert degrees to radians +// Input and Output type are the same +template<class T> +inline T deg2rad(T deg) { + return deg2rad<T,T>(deg); } } // End of namespace Common diff --git a/common/memorypool.cpp b/common/memorypool.cpp index 1a9bfe2e29..f0134a430d 100644 --- a/common/memorypool.cpp +++ b/common/memorypool.cpp @@ -43,7 +43,7 @@ static size_t adjustChunkSize(size_t chunkSize) { MemoryPool::MemoryPool(size_t chunkSize) : _chunkSize(adjustChunkSize(chunkSize)) { - _next = NULL; + _next = nullptr; _chunksPerPage = INITIAL_CHUNKS_PER_PAGE; } @@ -64,7 +64,7 @@ void MemoryPool::allocPage() { // Allocate a new page page.numChunks = _chunksPerPage; - assert(page.numChunks * _chunkSize < 16*1024*1024); // Refuse to allocate pages bigger than 16 MB + assert(page.numChunks * _chunkSize < 16*1024*1024); // Refuse to allocate pages bigger than 16 MB page.start = ::malloc(page.numChunks * _chunkSize); assert(page.start); @@ -154,7 +154,7 @@ void MemoryPool::freeUnusedPages() { ::free(_pages[i].start); ++freedPagesCount; - _pages[i].start = NULL; + _pages[i].start = nullptr; } } @@ -163,7 +163,7 @@ void MemoryPool::freeUnusedPages() { // Remove all now unused pages size_t newSize = 0; for (size_t i = 0; i < _pages.size(); ++i) { - if (_pages[i].start != NULL) { + if (_pages[i].start != nullptr) { if (newSize != i) _pages[newSize] = _pages[i]; ++newSize; diff --git a/common/memstream.h b/common/memstream.h index f6bf990208..8a8326e4a6 100644 --- a/common/memstream.h +++ b/common/memstream.h @@ -184,7 +184,7 @@ protected: _size = new_len; } public: - explicit MemoryWriteStreamDynamic(DisposeAfterUse::Flag disposeMemory) : _capacity(0), _size(0), _ptr(0), _data(0), _pos(0), _disposeMemory(disposeMemory) {} + explicit MemoryWriteStreamDynamic(DisposeAfterUse::Flag disposeMemory) : _capacity(0), _size(0), _ptr(nullptr), _data(nullptr), _pos(0), _disposeMemory(disposeMemory) {} ~MemoryWriteStreamDynamic() { if (_disposeMemory) @@ -247,7 +247,7 @@ private: } } public: - explicit MemoryReadWriteStream(DisposeAfterUse::Flag disposeMemory) : _capacity(0), _size(0), _data(0), _writePos(0), _readPos(0), _pos(0), _length(0), _disposeMemory(disposeMemory), _eos(false) {} + explicit MemoryReadWriteStream(DisposeAfterUse::Flag disposeMemory) : _capacity(0), _size(0), _data(nullptr), _writePos(0), _readPos(0), _pos(0), _length(0), _disposeMemory(disposeMemory), _eos(false) {} ~MemoryReadWriteStream() { if (_disposeMemory) @@ -289,8 +289,8 @@ public: return dataSize; } - int32 pos() const { return _pos - _length; } //'read' position in the stream - int32 size() const { return _size; } //that's also 'write' position in the stream, as it's append-only + int32 pos() const { return _pos - _length; } // 'read' position in the stream + int32 size() const { return _size; } // that's also 'write' position in the stream, as it's append-only bool seek(int32, int) { return false; } bool eos() const { return _eos; } void clearErr() { _eos = false; } diff --git a/common/mutex.cpp b/common/mutex.cpp index a7b34eb334..e7a0bbfe76 100644 --- a/common/mutex.cpp +++ b/common/mutex.cpp @@ -62,14 +62,14 @@ StackLock::~StackLock() { } void StackLock::lock() { - if (_mutexName != NULL) + if (_mutexName != nullptr) debug(6, "Locking mutex %s", _mutexName); g_system->lockMutex(_mutex); } void StackLock::unlock() { - if (_mutexName != NULL) + if (_mutexName != nullptr) debug(6, "Unlocking mutex %s", _mutexName); g_system->unlockMutex(_mutex); diff --git a/common/mutex.h b/common/mutex.h index 6e467cfddf..f965a63e0d 100644 --- a/common/mutex.h +++ b/common/mutex.h @@ -46,8 +46,8 @@ class StackLock { void lock(); void unlock(); public: - explicit StackLock(MutexRef mutex, const char *mutexName = NULL); - explicit StackLock(const Mutex &mutex, const char *mutexName = NULL); + explicit StackLock(MutexRef mutex, const char *mutexName = nullptr); + explicit StackLock(const Mutex &mutex, const char *mutexName = nullptr); ~StackLock(); }; diff --git a/common/osd_message_queue.cpp b/common/osd_message_queue.cpp index b8abf18bb5..d150737165 100644 --- a/common/osd_message_queue.cpp +++ b/common/osd_message_queue.cpp @@ -26,18 +26,18 @@ namespace Common { DECLARE_SINGLETON(OSDMessageQueue); - + OSDMessageQueue::OSDMessageQueue() : _lastUpdate(0) { } OSDMessageQueue::~OSDMessageQueue() { g_system->getEventManager()->getEventDispatcher()->unregisterSource(this); } - + void OSDMessageQueue::registerEventSource() { g_system->getEventManager()->getEventDispatcher()->registerSource(this, false); } - + void OSDMessageQueue::addMessage(const char *msg) { _mutex.lock(); _messages.push(msg); diff --git a/common/osd_message_queue.h b/common/osd_message_queue.h index 7aa7cf4792..10fe96bc6a 100644 --- a/common/osd_message_queue.h +++ b/common/osd_message_queue.h @@ -38,9 +38,9 @@ class OSDMessageQueue : public Singleton<OSDMessageQueue>, public EventSource { public: OSDMessageQueue(); ~OSDMessageQueue(); - + void registerEventSource(); - + enum { kMinimumDelay = 1000 /** < Minimum delay between two OSD messages (in milliseconds) */ }; @@ -49,7 +49,7 @@ public: * Add a message to the OSD message queue. */ void addMessage(const char *msg); - + /** * Common::EventSource interface * diff --git a/common/platform.cpp b/common/platform.cpp index 6898993b33..0049666912 100644 --- a/common/platform.cpp +++ b/common/platform.cpp @@ -56,7 +56,7 @@ const PlatformDescription g_platforms[] = { { "os2", "os2", "os2", "OS/2", kPlatformOS2 }, { "beos", "beos", "beos", "BeOS", kPlatformBeOS }, - { 0, 0, 0, "Default", kPlatformUnknown } + { nullptr, nullptr, nullptr, "Default", kPlatformUnknown } }; Platform parsePlatform(const String &str) { @@ -88,7 +88,7 @@ const char *getPlatformCode(Platform id) { if (l->id == id) return l->code; } - return 0; + return nullptr; } const char *getPlatformAbbrev(Platform id) { @@ -97,7 +97,7 @@ const char *getPlatformAbbrev(Platform id) { if (l->id == id) return l->abbrev; } - return 0; + return nullptr; } const char *getPlatformDescription(Platform id) { diff --git a/common/ptr.h b/common/ptr.h index f3b2f3cbfa..49a38e48bd 100644 --- a/common/ptr.h +++ b/common/ptr.h @@ -109,7 +109,7 @@ public: typedef T *PointerType; typedef T &ReferenceType; - SharedPtr() : _refCount(0), _deletion(0), _pointer(0) {} + SharedPtr() : _refCount(nullptr), _deletion(nullptr), _pointer(nullptr) {} template<class T2> explicit SharedPtr(T2 *p) : _refCount(new RefValue(1)), _deletion(new SharedPtrDeletionImpl<T2>(p)), _pointer(p) {} @@ -206,9 +206,9 @@ private: if (!*_refCount) { delete _refCount; delete _deletion; - _deletion = 0; - _refCount = 0; - _pointer = 0; + _deletion = nullptr; + _refCount = nullptr; + _pointer = nullptr; } } } diff --git a/common/quicktime.cpp b/common/quicktime.cpp index ecbf021e45..1c1690bc13 100644 --- a/common/quicktime.cpp +++ b/common/quicktime.cpp @@ -45,7 +45,7 @@ namespace Common { QuickTimeParser::QuickTimeParser() { _beginOffset = 0; - _fd = 0; + _fd = nullptr; _scaleFactorX = 1; _scaleFactorY = 1; _resFork = new MacResManager(); @@ -166,7 +166,7 @@ void QuickTimeParser::initParseTable() { { &QuickTimeParser::readSMI, MKTAG('S', 'M', 'I', ' ') }, { &QuickTimeParser::readDefault, MKTAG('g', 'm', 'h', 'd') }, { &QuickTimeParser::readLeaf, MKTAG('g', 'm', 'i', 'n') }, - { 0, 0 } + { nullptr, 0 } }; _parseTable = p; @@ -805,13 +805,13 @@ void QuickTimeParser::close() { if (_disposeFileHandle == DisposeAfterUse::YES) delete _fd; - _fd = 0; + _fd = nullptr; } QuickTimeParser::SampleDesc::SampleDesc(Track *parentTrack, uint32 codecTag) { _parentTrack = parentTrack; _codecTag = codecTag; - _extraData = 0; + _extraData = nullptr; _objectTypeMP4 = 0; } @@ -821,16 +821,16 @@ QuickTimeParser::SampleDesc::~SampleDesc() { QuickTimeParser::Track::Track() { chunkCount = 0; - chunkOffsets = 0; + chunkOffsets = nullptr; timeToSampleCount = 0; - timeToSample = 0; + timeToSample = nullptr; sampleToChunkCount = 0; - sampleToChunk = 0; + sampleToChunk = nullptr; sampleSize = 0; sampleCount = 0; - sampleSizes = 0; + sampleSizes = nullptr; keyframeCount = 0; - keyframes = 0; + keyframes = nullptr; timeScale = 0; width = 0; height = 0; diff --git a/common/quicktime.h b/common/quicktime.h index 3f82fc0431..26fc44ac71 100644 --- a/common/quicktime.h +++ b/common/quicktime.h @@ -79,7 +79,7 @@ public: void setChunkBeginOffset(uint32 offset) { _beginOffset = offset; } /** Find out if this parser has an open file handle */ - bool isOpen() const { return _fd != 0; } + bool isOpen() const { return _fd != nullptr; } protected: // This is the file handle from which data is read from. It can be the actual file handle or a decompressed stream. diff --git a/common/rdft.cpp b/common/rdft.cpp index 89d39112e6..b6af6cb4cd 100644 --- a/common/rdft.cpp +++ b/common/rdft.cpp @@ -28,7 +28,7 @@ namespace Common { -RDFT::RDFT(int bits, TransformType trans) : _bits(bits), _sin(bits), _cos(bits), _fft(0) { +RDFT::RDFT(int bits, TransformType trans) : _bits(bits), _sin(bits), _cos(bits), _fft(nullptr) { assert((_bits >= 4) && (_bits <= 16)); _inverse = trans == IDFT_C2R || trans == DFT_C2R; diff --git a/common/recorderfile.cpp b/common/recorderfile.cpp index 1f283715d0..3db017ea8b 100644 --- a/common/recorderfile.cpp +++ b/common/recorderfile.cpp @@ -335,7 +335,7 @@ RecorderEvent PlaybackFile::getNextEvent() { case kScreenShotTag: _readStream->seek(-4, SEEK_CUR); header.len = _readStream->readUint32BE(); - _readStream->skip(header.len-8); + _readStream->skip(header.len - 8); break; case kMD5Tag: checkRecordedMD5(); @@ -575,7 +575,7 @@ int PlaybackFile::getScreensCount() { int result = 0; while (skipToNextScreenshot()) { uint32 size = _readStream->readUint32BE(); - _readStream->skip(size-8); + _readStream->skip(size - 8); ++result; } return result; @@ -608,10 +608,11 @@ Graphics::Surface *PlaybackFile::getScreenShot(int number) { if (screenCount == number) { screenCount++; _readStream->seek(-4, SEEK_CUR); - return Graphics::loadThumbnail(*_readStream); + Graphics::Surface *thumbnail; + return Graphics::loadThumbnail(*_readStream, thumbnail) ? thumbnail : NULL; } else { uint32 size = _readStream->readUint32BE(); - _readStream->skip(size-8); + _readStream->skip(size - 8); screenCount++; } } diff --git a/common/rect.h b/common/rect.h index 6c4292c7af..135076bf1e 100644 --- a/common/rect.h +++ b/common/rect.h @@ -40,10 +40,10 @@ struct Point { Point() : x(0), y(0) {} Point(int16 x1, int16 y1) : x(x1), y(y1) {} - bool operator==(const Point &p) const { return x == p.x && y == p.y; } - bool operator!=(const Point &p) const { return x != p.x || y != p.y; } - Point operator+(const Point &delta) const { return Point(x + delta.x, y + delta.y); } - Point operator-(const Point &delta) const { return Point(x - delta.x, y - delta.y); } + bool operator==(const Point &p) const { return x == p.x && y == p.y; } + bool operator!=(const Point &p) const { return x != p.x || y != p.y; } + Point operator+(const Point &delta) const { return Point(x + delta.x, y + delta.y); } + Point operator-(const Point &delta) const { return Point(x - delta.x, y - delta.y); } void operator+=(const Point &delta) { x += delta.x; diff --git a/common/rendermode.cpp b/common/rendermode.cpp index e07cac4b4e..ab345a7b36 100644 --- a/common/rendermode.cpp +++ b/common/rendermode.cpp @@ -44,7 +44,7 @@ const RenderModeDescription g_renderModes[] = { { "2gs", "Apple IIgs", kRenderApple2GS }, { "atari", "Atari ST", kRenderAtariST }, { "macintosh", "Macintosh", kRenderMacintosh }, - {0, 0, kRenderDefault} + {nullptr, nullptr, kRenderDefault} }; struct RenderGUIOMapping { @@ -92,7 +92,7 @@ const char *getRenderModeCode(RenderMode id) { if (l->id == id) return l->code; } - return 0; + return nullptr; } const char *getRenderModeDescription(RenderMode id) { @@ -101,7 +101,7 @@ const char *getRenderModeDescription(RenderMode id) { if (l->id == id) return l->description; } - return 0; + return nullptr; } String renderMode2GUIO(RenderMode id) { diff --git a/common/safe-bool.h b/common/safe-bool.h index 7cbe29931c..92c8af51aa 100644 --- a/common/safe-bool.h +++ b/common/safe-bool.h @@ -52,7 +52,7 @@ namespace Common { public: operator bool_type() const { return static_cast<const DerivedT *>(this)->operator_bool() ? - &impl_t::stub : 0; + &impl_t::stub : nullptr; } operator bool_type() { diff --git a/common/scummsys.h b/common/scummsys.h index 5486ba27c6..ce54f3b50e 100644 --- a/common/scummsys.h +++ b/common/scummsys.h @@ -398,6 +398,18 @@ #endif #endif +#ifndef WARN_UNUSED_RESULT + #if __cplusplus >= 201703L + #define WARN_UNUSED_RESULT [[nodiscard]] + #elif GCC_ATLEAST(3, 4) + #define WARN_UNUSED_RESULT __attribute__((__warn_unused_result__)) + #elif defined(_Check_return_) + #define WARN_UNUSED_RESULT _Check_return_ + #else + #define WARN_UNUSED_RESULT + #endif +#endif + #ifndef STRINGBUFLEN #if defined(__N64__) || defined(__DS__) || defined(__3DS__) #define STRINGBUFLEN 256 diff --git a/common/serializer.h b/common/serializer.h index e8db40923a..18fb38563b 100644 --- a/common/serializer.h +++ b/common/serializer.h @@ -34,7 +34,7 @@ namespace Common { template<typename T> \ void syncAs ## SUFFIX(T &val, Version minVersion = 0, Version maxVersion = kLastVersion) { \ if (_version < minVersion || _version > maxVersion) \ - return; \ + return; \ if (_loadStream) \ val = static_cast<T>(_loadStream->read ## SUFFIX()); \ else { \ @@ -178,7 +178,7 @@ public: */ void skip(uint32 size, Version minVersion = 0, Version maxVersion = kLastVersion) { if (_version < minVersion || _version > maxVersion) - return; // Ignore anything which is not supposed to be present in this save game version + return; // Ignore anything which is not supposed to be present in this save game version _bytesSynced += size; if (isLoading()) @@ -194,7 +194,7 @@ public: */ void syncBytes(byte *buf, uint32 size, Version minVersion = 0, Version maxVersion = kLastVersion) { if (_version < minVersion || _version > maxVersion) - return; // Ignore anything which is not supposed to be present in this save game version + return; // Ignore anything which is not supposed to be present in this save game version if (isLoading()) _loadStream->read(buf, size); @@ -217,7 +217,7 @@ public: */ bool matchBytes(const char *magic, byte size, Version minVersion = 0, Version maxVersion = kLastVersion) { if (_version < minVersion || _version > maxVersion) - return true; // Ignore anything which is not supposed to be present in this save game version + return true; // Ignore anything which is not supposed to be present in this save game version bool match; if (isSaving()) { @@ -238,7 +238,7 @@ public: */ void syncString(String &str, Version minVersion = 0, Version maxVersion = kLastVersion) { if (_version < minVersion || _version > maxVersion) - return; // Ignore anything which is not supposed to be present in this save game version + return; // Ignore anything which is not supposed to be present in this save game version if (isLoading()) { char c; diff --git a/common/singleton.h b/common/singleton.h index 9bcd590183..7deb1dd7dc 100644 --- a/common/singleton.h +++ b/common/singleton.h @@ -59,6 +59,10 @@ public: public: + static bool hasInstance() { + return _singleton != 0; + } + static T& instance() { // TODO: We aren't thread safe. For now we ignore it since the // only thing using this singleton template is the config manager, diff --git a/common/str.cpp b/common/str.cpp index 2ef67175cd..468d1a6f53 100644 --- a/common/str.cpp +++ b/common/str.cpp @@ -28,7 +28,7 @@ namespace Common { -MemoryPool *g_refCountPool = 0; // FIXME: This is never freed right now +MemoryPool *g_refCountPool = nullptr; // FIXME: This is never freed right now static uint32 computeCapacity(uint32 len) { // By default, for the capacity we use the next multiple of 32 @@ -36,7 +36,7 @@ static uint32 computeCapacity(uint32 len) { } String::String(const char *str) : _size(0), _str(_storage) { - if (str == 0) { + if (str == nullptr) { _storage[0] = 0; _size = 0; } else @@ -63,10 +63,10 @@ void String::initWithCStr(const char *str, uint32 len) { if (len >= _builtinCapacity) { // Not enough internal storage, so allocate more - _extern._capacity = computeCapacity(len+1); - _extern._refCount = 0; + _extern._capacity = computeCapacity(len + 1); + _extern._refCount = nullptr; _str = new char[_extern._capacity]; - assert(_str != 0); + assert(_str != nullptr); } // Copy the string into the storage area @@ -87,7 +87,7 @@ String::String(const String &str) _extern._capacity = str._extern._capacity; _str = str._str; } - assert(_str != 0); + assert(_str != nullptr); } String::String(char c) @@ -165,15 +165,15 @@ void String::ensureCapacity(uint32 new_size, bool keep_old) { // Set the ref count & capacity if we use an external storage. // It is important to do this *after* copying any old content, // else we would override data that has not yet been copied! - _extern._refCount = 0; + _extern._refCount = nullptr; _extern._capacity = newCapacity; } } void String::incRefCount() const { assert(!isStorageIntern()); - if (_extern._refCount == 0) { - if (g_refCountPool == 0) { + if (_extern._refCount == nullptr) { + if (g_refCountPool == nullptr) { g_refCountPool = new MemoryPool(sizeof(int)); assert(g_refCountPool); } @@ -290,7 +290,7 @@ bool String::hasPrefix(const String &x) const { } bool String::hasPrefix(const char *x) const { - assert(x != 0); + assert(x != nullptr); // Compare x with the start of _str. const char *y = c_str(); while (*x && *x == *y) { @@ -302,12 +302,29 @@ bool String::hasPrefix(const char *x) const { return *x == 0; } +bool String::hasPrefixIgnoreCase(const String &x) const { + return hasPrefixIgnoreCase(x.c_str()); +} + +bool String::hasPrefixIgnoreCase(const char *x) const { + assert(x != nullptr); + // Compare x with the start of _str. + const char *y = c_str(); + while (*x && tolower(*x) == tolower(*y)) { + ++x; + ++y; + } + // It's a prefix, if and only if all letters in x are 'used up' before + // _str ends. + return *x == 0; +} + bool String::hasSuffix(const String &x) const { return hasSuffix(x.c_str()); } bool String::hasSuffix(const char *x) const { - assert(x != 0); + assert(x != nullptr); // Compare x with the end of _str. const uint32 x_size = strlen(x); if (x_size > _size) @@ -322,17 +339,37 @@ bool String::hasSuffix(const char *x) const { return *x == 0; } +bool String::hasSuffixIgnoreCase(const String &x) const { + return hasSuffixIgnoreCase(x.c_str()); +} + +bool String::hasSuffixIgnoreCase(const char *x) const { + assert(x != nullptr); + // Compare x with the end of _str. + const uint32 x_size = strlen(x); + if (x_size > _size) + return false; + const char *y = c_str() + _size - x_size; + while (*x && tolower(*x) == tolower(*y)) { + ++x; + ++y; + } + // It's a suffix, if and only if all letters in x are 'used up' before + // _str ends. + return *x == 0; +} + bool String::contains(const String &x) const { - return strstr(c_str(), x.c_str()) != NULL; + return strstr(c_str(), x.c_str()) != nullptr; } bool String::contains(const char *x) const { - assert(x != 0); - return strstr(c_str(), x) != NULL; + assert(x != nullptr); + return strstr(c_str(), x) != nullptr; } bool String::contains(char x) const { - return strchr(c_str(), x) != NULL; + return strchr(c_str(), x) != nullptr; } uint64 String::asUint64() const { @@ -593,7 +630,7 @@ String String::vformat(const char *fmt, va_list args) { // vsnprintf didn't have enough space, so grow buffer output.ensureCapacity(len, false); scumm_va_copy(va, args); - int len2 = vsnprintf(output._str, len+1, fmt, va); + int len2 = vsnprintf(output._str, len + 1, fmt, va); va_end(va); assert(len == len2); output._size = len2; @@ -610,7 +647,7 @@ bool String::operator==(const String &x) const { } bool String::operator==(const char *x) const { - assert(x != 0); + assert(x != nullptr); return equals(x); } @@ -619,7 +656,7 @@ bool String::operator!=(const String &x) const { } bool String::operator !=(const char *x) const { - assert(x != 0); + assert(x != nullptr); return !equals(x); } @@ -656,7 +693,7 @@ bool String::equals(const String &x) const { } bool String::equals(const char *x) const { - assert(x != 0); + assert(x != nullptr); return (0 == compareTo(x)); } @@ -665,7 +702,7 @@ bool String::equalsIgnoreCase(const String &x) const { } bool String::equalsIgnoreCase(const char *x) const { - assert(x != 0); + assert(x != nullptr); return (0 == compareToIgnoreCase(x)); } @@ -674,7 +711,7 @@ int String::compareTo(const String &x) const { } int String::compareTo(const char *x) const { - assert(x != 0); + assert(x != nullptr); return strcmp(c_str(), x); } @@ -683,7 +720,7 @@ int String::compareToIgnoreCase(const String &x) const { } int String::compareToIgnoreCase(const char *x) const { - assert(x != 0); + assert(x != nullptr); return scumm_stricmp(c_str(), x); } @@ -741,7 +778,7 @@ String lastPathComponent(const String &path, const char sep) { const char *last = str + path.size(); // Skip over trailing slashes - while (last > str && *(last-1) == sep) + while (last > str && *(last - 1) == sep) --last; // Path consisted of only slashes -> return empty string @@ -815,13 +852,13 @@ bool matchString(const char *str, const char *pat, bool ignoreCase, bool pathMod assert(str); assert(pat); - const char *p = 0; - const char *q = 0; + const char *p = nullptr; + const char *q = nullptr; for (;;) { if (pathMode && *str == '/') { - p = 0; - q = 0; + p = nullptr; + q = nullptr; if (*pat == '?') return false; } @@ -837,8 +874,8 @@ bool matchString(const char *str, const char *pat, bool ignoreCase, bool pathMod // NB: We can't simply check if pat also ended here, because // the pattern might end with any number of *s. ++pat; - p = 0; - q = 0; + p = nullptr; + q = nullptr; } // If pattern ended with * -> match if (!*pat) @@ -1010,7 +1047,7 @@ int scumm_strnicmp(const char *s1, const char *s2, uint n) { byte l1, l2; do { if (n-- == 0) - return 0; // no difference found so far -> signal equality + return 0; // no difference found so far -> signal equality // Don't use ++ inside tolower, in case the macro uses its // arguments more than once. diff --git a/common/str.h b/common/str.h index fd77fa90c8..7a1706b7e1 100644 --- a/common/str.h +++ b/common/str.h @@ -154,9 +154,13 @@ public: bool hasSuffix(const String &x) const; bool hasSuffix(const char *x) const; + bool hasSuffixIgnoreCase(const String &x) const; + bool hasSuffixIgnoreCase(const char *x) const; bool hasPrefix(const String &x) const; bool hasPrefix(const char *x) const; + bool hasPrefixIgnoreCase(const String &x) const; + bool hasPrefixIgnoreCase(const char *x) const; bool contains(const String &x) const; bool contains(const char *x) const; @@ -285,7 +289,7 @@ public: * except that it stores the result in (variably sized) String * instead of a fixed size buffer. */ - static String format(const char *fmt, ...) GCC_PRINTF(1,2); + static String format(const char *fmt, ...) GCC_PRINTF(1, 2); /** * Print formatted data into a String object. Similar to vsprintf, diff --git a/common/stream.cpp b/common/stream.cpp index 8d93888020..5c9b571af4 100644 --- a/common/stream.cpp +++ b/common/stream.cpp @@ -99,7 +99,7 @@ bool MemoryReadStream::seek(int32 offs, int whence) { // Reset end-of-stream flag on a successful seek _eos = false; - return true; // FIXME: STREAM REWRITE + return true; // FIXME: STREAM REWRITE } bool MemoryWriteStreamDynamic::seek(int32 offs, int whence) { @@ -124,7 +124,7 @@ bool MemoryWriteStreamDynamic::seek(int32 offs, int whence) { // Post-Condition assert(_pos <= _size); - return true; // FIXME: STREAM REWRITE + return true; // FIXME: STREAM REWRITE } #pragma mark - @@ -135,7 +135,7 @@ enum { }; char *SeekableReadStream::readLine(char *buf, size_t bufSize) { - assert(buf != 0 && bufSize > 1); + assert(buf != nullptr && bufSize > 1); char *p = buf; size_t len = 0; char c = 0; @@ -143,7 +143,7 @@ char *SeekableReadStream::readLine(char *buf, size_t bufSize) { // If end-of-file occurs before any characters are read, return NULL // and the buffer contents remain unchanged. if (eos() || err()) { - return 0; + return nullptr; } // Loop as long as there is still free space in the buffer, @@ -155,7 +155,7 @@ char *SeekableReadStream::readLine(char *buf, size_t bufSize) { // If end-of-file occurs before any characters are read, return // NULL and the buffer contents remain unchanged. if (len == 0) - return 0; + return nullptr; break; } @@ -163,7 +163,7 @@ char *SeekableReadStream::readLine(char *buf, size_t bufSize) { // If an error occurs, return NULL and the buffer contents // are indeterminate. if (err()) - return 0; + return nullptr; // Check for CR or CR/LF // * DOS and Windows use CRLF line breaks @@ -174,7 +174,7 @@ char *SeekableReadStream::readLine(char *buf, size_t bufSize) { c = readByte(); if (err()) { - return 0; // error: the buffer contents are indeterminate + return nullptr; // error: the buffer contents are indeterminate } if (eos()) { // The CR was the last character in the file. @@ -382,7 +382,7 @@ uint32 BufferedReadStream::read(void *dataPtr, uint32 dataSize) { ReadStream *wrapBufferedReadStream(ReadStream *parentStream, uint32 bufSize, DisposeAfterUse::Flag disposeParentStream) { if (parentStream) return new BufferedReadStream(parentStream, bufSize, disposeParentStream); - return 0; + return nullptr; } #pragma mark - @@ -413,7 +413,7 @@ BufferedSeekableReadStream::BufferedSeekableReadStream(SeekableReadStream *paren bool BufferedSeekableReadStream::seek(int32 offset, int whence) { // If it is a "local" seek, we may get away with "seeking" around // in the buffer only. - _eos = false; // seeking always cancels EOS + _eos = false; // seeking always cancels EOS int relOffset = 0; switch (whence) { @@ -459,7 +459,7 @@ bool BufferedSeekableReadStream::seek(int32 offset, int whence) { SeekableReadStream *wrapBufferedSeekableReadStream(SeekableReadStream *parentStream, uint32 bufSize, DisposeAfterUse::Flag disposeParentStream) { if (parentStream) return new BufferedSeekableReadStream(parentStream, bufSize, disposeParentStream); - return 0; + return nullptr; } #pragma mark - @@ -543,7 +543,7 @@ public: WriteStream *wrapBufferedWriteStream(WriteStream *parentStream, uint32 bufSize) { if (parentStream) return new BufferedWriteStream(parentStream, bufSize); - return 0; + return nullptr; } } // End of namespace Common diff --git a/common/system.cpp b/common/system.cpp index 131a7d2580..f4568c2240 100644 --- a/common/system.cpp +++ b/common/system.cpp @@ -35,47 +35,47 @@ #include "backends/fs/fs-factory.h" #include "backends/timer/default/default-timer.h" -OSystem *g_system = 0; +OSystem *g_system = nullptr; OSystem::OSystem() { - _audiocdManager = 0; - _eventManager = 0; - _timerManager = 0; - _savefileManager = 0; + _audiocdManager = nullptr; + _eventManager = nullptr; + _timerManager = nullptr; + _savefileManager = nullptr; #if defined(USE_TASKBAR) - _taskbarManager = 0; + _taskbarManager = nullptr; #endif #if defined(USE_UPDATES) - _updateManager = 0; + _updateManager = nullptr; #endif - _fsFactory = 0; + _fsFactory = nullptr; } OSystem::~OSystem() { delete _audiocdManager; - _audiocdManager = 0; + _audiocdManager = nullptr; delete _eventManager; - _eventManager = 0; + _eventManager = nullptr; delete _timerManager; - _timerManager = 0; + _timerManager = nullptr; #if defined(USE_TASKBAR) delete _taskbarManager; - _taskbarManager = 0; + _taskbarManager = nullptr; #endif #if defined(USE_UPDATES) delete _updateManager; - _updateManager = 0; + _updateManager = nullptr; #endif delete _savefileManager; - _savefileManager = 0; + _savefileManager = nullptr; delete _fsFactory; - _fsFactory = 0; + _fsFactory = nullptr; } void OSystem::initBackend() { @@ -138,7 +138,7 @@ Common::SeekableReadStream *OSystem::createConfigReadStream() { Common::WriteStream *OSystem::createConfigWriteStream() { #ifdef __DC__ - return 0; + return nullptr; #else Common::FSNode file(getDefaultConfigFileName()); return file.createWriteStream(); diff --git a/common/system.h b/common/system.h index 206c3134c4..8866a4dcd2 100644 --- a/common/system.h +++ b/common/system.h @@ -324,8 +324,8 @@ public: kFeatureDisplayLogFile, /** - * The presence of this feature indicates whether the hasTextInClipboard() - * and getTextFromClipboard() calls are supported. + * The presence of this feature indicates whether the hasTextInClipboard(), + * getTextFromClipboard() and setTextInClipboard() calls are supported. * * This feature has no associated state. */ @@ -587,7 +587,7 @@ public: * @return a list of supported shaders */ virtual const GraphicsMode *getSupportedShaders() const { - static const OSystem::GraphicsMode no_shader[2] = {{"NONE", "Normal (no shader)", 0}, {0, 0, 0}}; + static const OSystem::GraphicsMode no_shader[2] = {{"NONE", "Normal (no shader)", 0}, {nullptr, nullptr, 0}}; return no_shader; } @@ -632,7 +632,7 @@ public: * @param height the new virtual screen height * @param format the new virtual screen pixel format */ - virtual void initSize(uint width, uint height, const Graphics::PixelFormat *format = NULL) = 0; + virtual void initSize(uint width, uint height, const Graphics::PixelFormat *format = nullptr) = 0; /** * Send a list of graphics modes to the backend so it can make a decision @@ -964,7 +964,7 @@ public: * would be too small to notice otherwise, these are allowed to scale the cursor anyway. * @param format pointer to the pixel format which cursor graphic uses (0 means CLUT8) */ - virtual void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale = false, const Graphics::PixelFormat *format = NULL) = 0; + virtual void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale = false, const Graphics::PixelFormat *format = nullptr) = 0; /** * Replace the specified range of cursor the palette with new colors. @@ -1028,7 +1028,7 @@ public: * * See keymapper documentation for further reference. */ - virtual Common::HardwareInputSet *getHardwareInputSet() { return 0; } + virtual Common::HardwareInputSet *getHardwareInputSet() { return nullptr; } /** * Return a platform-specific global keymap @@ -1041,7 +1041,7 @@ public: * * See keymapper documentation for further reference. */ - virtual Common::Keymap *getGlobalKeymap() { return 0; } + virtual Common::Keymap *getGlobalKeymap() { return nullptr; } /** * Return platform-specific default keybindings @@ -1052,7 +1052,7 @@ public: * * See keymapper documentation for further reference. */ - virtual Common::KeymapperDefaultBindings *getKeymapperDefaultBindings() { return 0; } + virtual Common::KeymapperDefaultBindings *getKeymapperDefaultBindings() { return nullptr; } #endif //@} @@ -1336,6 +1336,17 @@ public: virtual Common::String getTextFromClipboard() { return ""; } /** + * Set the content of the clipboard to the given string. + * + * The kFeatureClipboardSupport feature flag can be used to + * test whether this call has been implemented by the active + * backend. + * + * @return true if the text was properly set in the clipboard, false otherwise + */ + virtual bool setTextInClipboard(const Common::String &text) { return false; } + + /** * Open the given Url in the default browser (if available on the target * system). * diff --git a/common/textconsole.cpp b/common/textconsole.cpp index 5c69e42379..d533c4b7e4 100644 --- a/common/textconsole.cpp +++ b/common/textconsole.cpp @@ -28,13 +28,13 @@ namespace Common { -static OutputFormatter s_errorOutputFormatter = 0; +static OutputFormatter s_errorOutputFormatter = nullptr; void setErrorOutputFormatter(OutputFormatter f) { s_errorOutputFormatter = f; } -static ErrorHandler s_errorHandler = 0; +static ErrorHandler s_errorHandler = nullptr; void setErrorHandler(ErrorHandler handler) { s_errorHandler = handler; diff --git a/common/translation.cpp b/common/translation.cpp index 01665bf876..35e5b6e4c3 100644 --- a/common/translation.cpp +++ b/common/translation.cpp @@ -46,7 +46,7 @@ bool operator<(const TLanguage &l, const TLanguage &r) { return strcmp(l.name, r.name) < 0; } -TranslationManager::TranslationManager() : _currentLang(-1), _charmap(0) { +TranslationManager::TranslationManager() : _currentLang(-1), _charmap(nullptr) { loadTranslationsInfoDat(); // Set the default language @@ -110,7 +110,7 @@ void TranslationManager::setLanguage(const String &lang) { } const char *TranslationManager::getTranslation(const char *message) const { - return getTranslation(message, NULL); + return getTranslation(message, nullptr); } const char *TranslationManager::getTranslation(const char *message, const char *context) const { @@ -144,7 +144,7 @@ const char *TranslationManager::getTranslation(const char *message, const char * ++rightIndex; } // Find the context we want - if (context == NULL || *context == '\0' || leftIndex == rightIndex) + if (context == nullptr || *context == '\0' || leftIndex == rightIndex) return _currentTranslationMessages[leftIndex].msgstr.c_str(); // We could use again binary search, but there should be only a small number of contexts. while (rightIndex > leftIndex) { @@ -416,7 +416,7 @@ void TranslationManager::loadLanguageDat(int index) { // Setup the new charset mapping if (charmapNum == -1) { delete[] _charmap; - _charmap = 0; + _charmap = nullptr; } else { if (!_charmap) _charmap = new uint32[256]; diff --git a/common/translation.h b/common/translation.h index e316507fdb..3dd7039cf3 100644 --- a/common/translation.h +++ b/common/translation.h @@ -44,7 +44,7 @@ struct TLanguage { const char *name; int id; - TLanguage() : name(0), id(0) {} + TLanguage() : name(nullptr), id(0) {} TLanguage(const char *n, int i) : name(n), id(i) {} }; diff --git a/common/unarj.cpp b/common/unarj.cpp index e8aed7cbd1..9737521245 100644 --- a/common/unarj.cpp +++ b/common/unarj.cpp @@ -95,8 +95,8 @@ class ArjDecoder { public: ArjDecoder(const ArjHeader *hdr) { _compsize = hdr->compSize; - _compressed = 0; - _outstream = 0; + _compressed = nullptr; + _outstream = nullptr; _bitbuf = 0; _bytebuf = 0; _bitcount = 0; @@ -251,16 +251,16 @@ ArjHeader *readHeader(SeekableReadStream &stream) { if (header.id != HEADER_ID) { warning("ArjFile::readHeader(): Bad header ID (%x)", header.id); - return NULL; + return nullptr; } header.headerSize = stream.readUint16LE(); if (header.headerSize == 0) - return NULL; // end of archive + return nullptr; // end of archive if (header.headerSize > HEADERSIZE_MAX) { warning("ArjFile::readHeader(): Bad header"); - return NULL; + return nullptr; } int rSize = stream.read(headData, header.headerSize); @@ -270,7 +270,7 @@ ArjHeader *readHeader(SeekableReadStream &stream) { header.headerCrc = stream.readUint32LE(); if (CRC32::checksum(headData, header.headerSize) != header.headerCrc) { warning("ArjFile::readHeader(): Bad header CRC"); - return NULL; + return nullptr; } header.firstHdrSize = readS.readByte(); @@ -292,7 +292,7 @@ ArjHeader *readHeader(SeekableReadStream &stream) { // static int check_file_size() if (header.origSize < 0 || header.compSize < 0) { warning("ArjFile::readHeader(): Wrong file size"); - return NULL; + return nullptr; } strlcpy(header.filename, (const char *)&headData[header.firstHdrSize], ARJ_FILENAME_MAX); @@ -723,14 +723,14 @@ ArjArchive::ArjArchive(const String &filename) : _arjFilename(filename) { return; } - ArjHeader *header = NULL; + ArjHeader *header = nullptr; arjFile.seek(firstHeaderOffset, SEEK_SET); - if ((header = readHeader(arjFile)) == NULL) + if ((header = readHeader(arjFile)) == nullptr) return; delete header; - while ((header = readHeader(arjFile)) != NULL) { + while ((header = readHeader(arjFile)) != nullptr) { _headers[header->filename] = header; arjFile.seek(header->compSize, SEEK_CUR); } @@ -771,7 +771,7 @@ const ArchiveMemberPtr ArjArchive::getMember(const String &name) const { SeekableReadStream *ArjArchive::createReadStreamForMember(const String &name) const { if (!_headers.contains(name)) { - return 0; + return nullptr; } ArjHeader *hdr = _headers[name]; diff --git a/common/unzip.cpp b/common/unzip.cpp index 1f4e601989..2e7a3f8b81 100644 --- a/common/unzip.cpp +++ b/common/unzip.cpp @@ -480,18 +480,18 @@ static uLong unzlocal_SearchCentralDir(Common::SeekableReadStream &fin) { uMaxBack = uSizeFile; buf = (unsigned char*)malloc(BUFREADCOMMENT+4); - if (buf==NULL) + if (buf==nullptr) return 0; uBackRead = 4; while (uBackRead<uMaxBack) { - uLong uReadSize,uReadPos ; + uLong uReadSize,uReadPos; int i; if (uBackRead+BUFREADCOMMENT>uMaxBack) uBackRead = uMaxBack; else uBackRead+=BUFREADCOMMENT; - uReadPos = uSizeFile-uBackRead ; + uReadPos = uSizeFile-uBackRead; uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? (BUFREADCOMMENT+4) : (uSizeFile-uReadPos); @@ -528,7 +528,7 @@ static uLong unzlocal_SearchCentralDir(Common::SeekableReadStream &fin) { */ unzFile unzOpen(Common::SeekableReadStream *stream) { if (!stream) - return NULL; + return nullptr; unz_s *us = new unz_s; uLong central_pos,uL; @@ -597,21 +597,21 @@ unzFile unzOpen(Common::SeekableReadStream *stream) { if (err != UNZ_OK) { delete us->_stream; delete us; - return NULL; + return nullptr; } us->byte_before_the_zipfile = central_pos - (us->offset_central_dir+us->size_central_dir); us->central_pos = central_pos; - us->pfile_in_zip_read = NULL; + us->pfile_in_zip_read = nullptr; err = unzGoToFirstFile((unzFile)us); while (err == UNZ_OK) { // Get the file details char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; - unzGetCurrentFileInfo(us, NULL, szCurrentFileName, sizeof(szCurrentFileName) - 1, - NULL, 0, NULL, 0); + unzGetCurrentFileInfo(us, nullptr, szCurrentFileName, sizeof(szCurrentFileName) - 1, + nullptr, 0, nullptr, 0); // Save details into the hash cached_file_in_zip fe; @@ -637,11 +637,11 @@ unzFile unzOpen(Common::SeekableReadStream *stream) { return UNZ_OK if there is no problem. */ int unzClose(unzFile file) { unz_s *s; - if (file == NULL) + if (file == nullptr) return UNZ_PARAMERROR; s = (unz_s *)file; - if (s->pfile_in_zip_read != NULL) + if (s->pfile_in_zip_read != nullptr) unzCloseCurrentFile(file); delete s->_stream; @@ -656,7 +656,7 @@ int unzClose(unzFile file) { return UNZ_OK if there is no problem. */ int unzGetGlobalInfo(unzFile file, unz_global_info *pglobal_info) { unz_s *s; - if (file == NULL) + if (file == nullptr) return UNZ_PARAMERROR; s = (unz_s *)file; *pglobal_info = s->gi; @@ -670,13 +670,13 @@ int unzGetGlobalInfo(unzFile file, unz_global_info *pglobal_info) { static void unzlocal_DosDateToTmuDate(uLong ulDosDate, tm_unz* ptm) { uLong uDate; uDate = (uLong)(ulDosDate>>16); - ptm->tm_mday = (uInt)(uDate&0x1f) ; - ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ; - ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ; + ptm->tm_mday = (uInt)(uDate&0x1f); + ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1); + ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980); ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800); - ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20) ; - ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)) ; + ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20); + ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)); } /* @@ -707,7 +707,7 @@ static int unzlocal_GetCurrentFileInfoInternal(unzFile file, uLong uMagic; long lSeek=0; - if (file==NULL) + if (file==nullptr) return UNZ_PARAMERROR; s=(unz_s*)file; s->_stream->seek(s->pos_in_central_dir+s->byte_before_the_zipfile, SEEK_SET); @@ -771,8 +771,8 @@ static int unzlocal_GetCurrentFileInfoInternal(unzFile file, err=UNZ_ERRNO; lSeek+=file_info.size_filename; - if ((err==UNZ_OK) && (szFileName!=NULL)) { - uLong uSizeRead ; + if ((err==UNZ_OK) && (szFileName!=nullptr)) { + uLong uSizeRead; if (file_info.size_filename<fileNameBufferSize) { *(szFileName+file_info.size_filename)='\0'; uSizeRead = file_info.size_filename; @@ -786,8 +786,8 @@ static int unzlocal_GetCurrentFileInfoInternal(unzFile file, } - if ((err==UNZ_OK) && (extraField!=NULL)) { - uLong uSizeRead ; + if ((err==UNZ_OK) && (extraField!=nullptr)) { + uLong uSizeRead; if (file_info.size_file_extra<extraFieldBufferSize) uSizeRead = file_info.size_file_extra; else @@ -809,8 +809,8 @@ static int unzlocal_GetCurrentFileInfoInternal(unzFile file, lSeek+=file_info.size_file_extra; - if ((err==UNZ_OK) && (szComment!=NULL)) { - uLong uSizeRead ; + if ((err==UNZ_OK) && (szComment!=nullptr)) { + uLong uSizeRead; if (file_info.size_file_comment<commentBufferSize) { *(szComment+file_info.size_file_comment)='\0'; uSizeRead = file_info.size_file_comment; @@ -831,10 +831,10 @@ static int unzlocal_GetCurrentFileInfoInternal(unzFile file, } else lSeek+=file_info.size_file_comment; - if ((err==UNZ_OK) && (pfile_info!=NULL)) + if ((err==UNZ_OK) && (pfile_info!=nullptr)) *pfile_info=file_info; - if ((err==UNZ_OK) && (pfile_info_internal!=NULL)) + if ((err==UNZ_OK) && (pfile_info_internal!=nullptr)) *pfile_info_internal=file_info_internal; return err; @@ -853,7 +853,7 @@ int unzGetCurrentFileInfo(unzFile file, void *extraField, uLong extraFieldBufferSize, char *szComment, uLong commentBufferSize) { - return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL, + return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,nullptr, szFileName,fileNameBufferSize, extraField,extraFieldBufferSize, szComment,commentBufferSize); @@ -866,14 +866,14 @@ int unzGetCurrentFileInfo(unzFile file, int unzGoToFirstFile(unzFile file) { int err=UNZ_OK; unz_s* s; - if (file==NULL) + if (file==nullptr) return UNZ_PARAMERROR; s=(unz_s*)file; s->pos_in_central_dir=s->offset_central_dir; s->num_file=0; err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, &s->cur_file_info_internal, - NULL,0,NULL,0,NULL,0); + nullptr,0,nullptr,0,nullptr,0); s->current_file_ok = (err == UNZ_OK); return err; } @@ -888,7 +888,7 @@ int unzGoToNextFile(unzFile file) { unz_s* s; int err; - if (file==NULL) + if (file==nullptr) return UNZ_PARAMERROR; s=(unz_s*)file; if (!s->current_file_ok) @@ -897,11 +897,11 @@ int unzGoToNextFile(unzFile file) { return UNZ_END_OF_LIST_OF_FILE; s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename + - s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ; + s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment; s->num_file++; err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, &s->cur_file_info_internal, - NULL,0,NULL,0,NULL,0); + nullptr,0,nullptr,0,nullptr,0); s->current_file_ok = (err == UNZ_OK); return err; } @@ -917,7 +917,7 @@ int unzGoToNextFile(unzFile file) { int unzLocateFile(unzFile file, const char *szFileName, int iCaseSensitivity) { unz_s* s; - if (file==NULL) + if (file==nullptr) return UNZ_PARAMERROR; if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP) @@ -1047,13 +1047,13 @@ int unzOpenCurrentFile (unzFile file) { uLong offset_local_extrafield; /* offset of the local extra field */ uInt size_local_extrafield; /* size of the local extra field */ - if (file==NULL) + if (file==nullptr) return UNZ_PARAMERROR; s=(unz_s*)file; if (!s->current_file_ok) return UNZ_PARAMERROR; - if (s->pfile_in_zip_read != NULL) + if (s->pfile_in_zip_read != nullptr) unzCloseCurrentFile(file); if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar, @@ -1062,7 +1062,7 @@ int unzOpenCurrentFile (unzFile file) { pfile_in_zip_read_info = (file_in_zip_read_info_s*) malloc(sizeof(file_in_zip_read_info_s)); - if (pfile_in_zip_read_info==NULL) + if (pfile_in_zip_read_info==nullptr) return UNZ_INTERNALERROR; pfile_in_zip_read_info->read_buffer=(char *)malloc(UNZ_BUFSIZE); @@ -1070,7 +1070,7 @@ int unzOpenCurrentFile (unzFile file) { pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield; pfile_in_zip_read_info->pos_local_extrafield=0; - if (pfile_in_zip_read_info->read_buffer==NULL) + if (pfile_in_zip_read_info->read_buffer==nullptr) { free(pfile_in_zip_read_info); return UNZ_INTERNALERROR; @@ -1093,9 +1093,9 @@ int unzOpenCurrentFile (unzFile file) { if (!Store) { #ifdef USE_ZLIB - pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; - pfile_in_zip_read_info->stream.zfree = (free_func)0; - pfile_in_zip_read_info->stream.opaque = (voidpf)0; + pfile_in_zip_read_info->stream.zalloc = (alloc_func)nullptr; + pfile_in_zip_read_info->stream.zfree = (free_func)nullptr; + pfile_in_zip_read_info->stream.opaque = (voidpf)nullptr; err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS); if (err == Z_OK) @@ -1140,16 +1140,16 @@ int unzReadCurrentFile(unzFile file, voidp buf, unsigned len) { uInt iRead = 0; unz_s* s; file_in_zip_read_info_s* pfile_in_zip_read_info; - if (file==NULL) + if (file==nullptr) return UNZ_PARAMERROR; s=(unz_s*)file; pfile_in_zip_read_info=s->pfile_in_zip_read; - if (pfile_in_zip_read_info==NULL) + if (pfile_in_zip_read_info==nullptr) return UNZ_PARAMERROR; - if (pfile_in_zip_read_info->read_buffer == NULL) + if (pfile_in_zip_read_info->read_buffer == nullptr) return UNZ_END_OF_LIST_OF_FILE; if (len==0) return 0; @@ -1185,11 +1185,11 @@ int unzReadCurrentFile(unzFile file, voidp buf, unsigned len) { } if (pfile_in_zip_read_info->compression_method==0) { - uInt uDoCopy,i ; + uInt uDoCopy,i; if (pfile_in_zip_read_info->stream.avail_out < pfile_in_zip_read_info->stream.avail_in) - uDoCopy = pfile_in_zip_read_info->stream.avail_out ; + uDoCopy = pfile_in_zip_read_info->stream.avail_out; else - uDoCopy = pfile_in_zip_read_info->stream.avail_in ; + uDoCopy = pfile_in_zip_read_info->stream.avail_in; for (i=0;i<uDoCopy;i++) *(pfile_in_zip_read_info->stream.next_out+i) = *(pfile_in_zip_read_info->stream.next_in+i); @@ -1258,12 +1258,12 @@ int unzReadCurrentFile(unzFile file, voidp buf, unsigned len) { z_off_t unztell(unzFile file) { unz_s* s; file_in_zip_read_info_s* pfile_in_zip_read_info; - if (file==NULL) + if (file==nullptr) return UNZ_PARAMERROR; s=(unz_s*)file; pfile_in_zip_read_info=s->pfile_in_zip_read; - if (pfile_in_zip_read_info==NULL) + if (pfile_in_zip_read_info==nullptr) return UNZ_PARAMERROR; return (z_off_t)pfile_in_zip_read_info->stream.total_out; @@ -1276,12 +1276,12 @@ z_off_t unztell(unzFile file) { int unzeof(unzFile file) { unz_s* s; file_in_zip_read_info_s* pfile_in_zip_read_info; - if (file==NULL) + if (file==nullptr) return UNZ_PARAMERROR; s=(unz_s*)file; pfile_in_zip_read_info=s->pfile_in_zip_read; - if (pfile_in_zip_read_info==NULL) + if (pfile_in_zip_read_info==nullptr) return UNZ_PARAMERROR; if (pfile_in_zip_read_info->rest_read_uncompressed == 0) @@ -1310,24 +1310,24 @@ int unzGetLocalExtrafield(unzFile file, voidp buf, unsigned len) { uInt read_now; uLong size_to_read; - if (file==NULL) + if (file==nullptr) return UNZ_PARAMERROR; s=(unz_s*)file; pfile_in_zip_read_info=s->pfile_in_zip_read; - if (pfile_in_zip_read_info==NULL) + if (pfile_in_zip_read_info==nullptr) return UNZ_PARAMERROR; size_to_read = (pfile_in_zip_read_info->size_local_extrafield - pfile_in_zip_read_info->pos_local_extrafield); - if (buf==NULL) + if (buf==nullptr) return (int)size_to_read; if (len>size_to_read) read_now = (uInt)size_to_read; else - read_now = (uInt)len ; + read_now = (uInt)len; if (read_now==0) return 0; @@ -1352,12 +1352,12 @@ int unzCloseCurrentFile(unzFile file) { unz_s* s; file_in_zip_read_info_s* pfile_in_zip_read_info; - if (file == NULL) + if (file == nullptr) return UNZ_PARAMERROR; s = (unz_s*)file; pfile_in_zip_read_info = s->pfile_in_zip_read; - if (pfile_in_zip_read_info == NULL) + if (pfile_in_zip_read_info == nullptr) return UNZ_PARAMERROR; @@ -1374,12 +1374,12 @@ int unzCloseCurrentFile(unzFile file) { free(pfile_in_zip_read_info->read_buffer); - pfile_in_zip_read_info->read_buffer = NULL; + pfile_in_zip_read_info->read_buffer = nullptr; pfile_in_zip_read_info->stream_initialized = 0; free(pfile_in_zip_read_info); - s->pfile_in_zip_read=NULL; + s->pfile_in_zip_read=nullptr; return err; } @@ -1392,8 +1392,8 @@ int unzCloseCurrentFile(unzFile file) { */ int unzGetGlobalComment(unzFile file, char *szComment, uLong uSizeBuf) { unz_s* s; - uLong uReadThis ; - if (file==NULL) + uLong uReadThis; + if (file==nullptr) return UNZ_PARAMERROR; s=(unz_s*)file; @@ -1411,7 +1411,7 @@ int unzGetGlobalComment(unzFile file, char *szComment, uLong uSizeBuf) { return UNZ_ERRNO; } - if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment)) + if ((szComment != nullptr) && (uSizeBuf > s->gi.size_comment)) *(szComment+s->gi.size_comment)='\0'; return (int)uReadThis; } @@ -1487,26 +1487,26 @@ const ArchiveMemberPtr ZipArchive::getMember(const String &name) const { SeekableReadStream *ZipArchive::createReadStreamForMember(const String &name) const { if (unzLocateFile(_zipFile, name.c_str(), 2) != UNZ_OK) - return 0; + return nullptr; unz_file_info fileInfo; if (unzOpenCurrentFile(_zipFile) != UNZ_OK) - return 0; + return nullptr; - if (unzGetCurrentFileInfo(_zipFile, &fileInfo, NULL, 0, NULL, 0, NULL, 0) != UNZ_OK) - return 0; + if (unzGetCurrentFileInfo(_zipFile, &fileInfo, nullptr, 0, nullptr, 0, nullptr, 0) != UNZ_OK) + return nullptr; byte *buffer = (byte *)malloc(fileInfo.uncompressed_size); assert(buffer); if (unzReadCurrentFile(_zipFile, buffer, fileInfo.uncompressed_size) != (int)fileInfo.uncompressed_size) { free(buffer); - return 0; + return nullptr; } if (unzCloseCurrentFile(_zipFile) != UNZ_OK) { free(buffer); - return 0; + return nullptr; } return new MemoryReadStream(buffer, fileInfo.uncompressed_size, DisposeAfterUse::YES); @@ -1527,12 +1527,12 @@ Archive *makeZipArchive(const FSNode &node) { Archive *makeZipArchive(SeekableReadStream *stream) { if (!stream) - return 0; + return nullptr; unzFile zipFile = unzOpen(stream); if (!zipFile) { // stream gets deleted by unzOpen() call if something // goes wrong. - return 0; + return nullptr; } return new ZipArchive(zipFile); } diff --git a/common/updates.cpp b/common/updates.cpp index 087002a7d3..4e4ed53b8f 100644 --- a/common/updates.cpp +++ b/common/updates.cpp @@ -47,7 +47,7 @@ int UpdateManager::normalizeInterval(int interval) { val++; } - return val[-1]; // Return maximal acceptable value + return val[-1]; // Return maximal acceptable value } const char *UpdateManager::updateIntervalToString(int interval) { diff --git a/common/updates.h b/common/updates.h index 3a3049d4df..812aac718e 100644 --- a/common/updates.h +++ b/common/updates.h @@ -50,7 +50,7 @@ public: kUpdateIntervalNotSupported = 0, kUpdateIntervalOneDay = 86400, kUpdateIntervalOneWeek = 604800, - kUpdateIntervalOneMonth = 2628000 // average seconds per month (60*60*24*365)/12 + kUpdateIntervalOneMonth = 2628000 // average seconds per month (60*60*24*365)/12 }; UpdateManager() {} diff --git a/common/ustr.cpp b/common/ustr.cpp index 35b5502a6d..85946cda46 100644 --- a/common/ustr.cpp +++ b/common/ustr.cpp @@ -34,7 +34,7 @@ static uint32 computeCapacity(uint32 len) { } U32String::U32String(const value_type *str) : _size(0), _str(_storage) { - if (str == 0) { + if (str == nullptr) { _storage[0] = 0; _size = 0; } else { @@ -69,7 +69,7 @@ U32String::U32String(const U32String &str) _extern._capacity = str._extern._capacity; _str = str._str; } - assert(_str != 0); + assert(_str != nullptr); } U32String::~U32String() { @@ -239,7 +239,7 @@ void U32String::ensureCapacity(uint32 new_size, bool keep_old) { if (new_size < curCapacity) newCapacity = curCapacity; else - newCapacity = MAX(curCapacity * 2, computeCapacity(new_size+1)); + newCapacity = MAX(curCapacity * 2, computeCapacity(new_size + 1)); // Allocate new storage newStorage = new value_type[newCapacity]; @@ -265,15 +265,15 @@ void U32String::ensureCapacity(uint32 new_size, bool keep_old) { // Set the ref count & capacity if we use an external storage. // It is important to do this *after* copying any old content, // else we would override data that has not yet been copied! - _extern._refCount = 0; + _extern._refCount = nullptr; _extern._capacity = newCapacity; } } void U32String::incRefCount() const { assert(!isStorageIntern()); - if (_extern._refCount == 0) { - if (g_refCountPool == 0) { + if (_extern._refCount == nullptr) { + if (g_refCountPool == nullptr) { g_refCountPool = new MemoryPool(sizeof(int)); assert(g_refCountPool); } @@ -316,10 +316,10 @@ void U32String::initWithCStr(const value_type *str, uint32 len) { if (len >= _builtinCapacity) { // Not enough internal storage, so allocate more - _extern._capacity = computeCapacity(len+1); - _extern._refCount = 0; + _extern._capacity = computeCapacity(len + 1); + _extern._refCount = nullptr; _str = new value_type[_extern._capacity]; - assert(_str != 0); + assert(_str != nullptr); } // Copy the string into the storage area diff --git a/common/util.h b/common/util.h index a098a6a437..2d6a36d086 100644 --- a/common/util.h +++ b/common/util.h @@ -123,7 +123,7 @@ bool isAlnum(int c); * false is returned. * * @param c the character to test - * @return true if the character is TODO, false otherwise. + * @return true if the character is alphabetic, false otherwise. */ bool isAlpha(int c); diff --git a/common/winexe_ne.cpp b/common/winexe_ne.cpp index ccf1fd17e5..2d46cb2554 100644 --- a/common/winexe_ne.cpp +++ b/common/winexe_ne.cpp @@ -30,7 +30,7 @@ namespace Common { NEResources::NEResources() { - _exe = 0; + _exe = nullptr; } NEResources::~NEResources() { @@ -40,7 +40,7 @@ NEResources::~NEResources() { void NEResources::clear() { if (_exe) { delete _exe; - _exe = 0; + _exe = nullptr; } _resources.clear(); @@ -270,14 +270,14 @@ const NEResources::Resource *NEResources::findResource(const WinResourceID &type if (it->type == type && it->id == id) return &*it; - return 0; + return nullptr; } SeekableReadStream *NEResources::getResource(const WinResourceID &type, const WinResourceID &id) { const Resource *res = findResource(type, id); if (!res) - return 0; + return nullptr; _exe->seek(res->offset); return _exe->readStream(res->size); diff --git a/common/winexe_pe.cpp b/common/winexe_pe.cpp index 969ea5d923..042c347c47 100644 --- a/common/winexe_pe.cpp +++ b/common/winexe_pe.cpp @@ -31,7 +31,7 @@ namespace Common { PEResources::PEResources() { - _exe = 0; + _exe = nullptr; } PEResources::~PEResources() { @@ -41,7 +41,7 @@ PEResources::~PEResources() { void PEResources::clear() { _sections.clear(); _resources.clear(); - delete _exe; _exe = 0; + delete _exe; _exe = nullptr; } bool PEResources::loadFromEXE(const String &fileName) { @@ -224,7 +224,7 @@ SeekableReadStream *PEResources::getResource(const WinResourceID &type, const Wi Array<WinResourceID> langList = getLangList(type, name); if (langList.empty()) - return 0; + return nullptr; const Resource &resource = _resources[type][name][langList[0]]; _exe->seek(resource.offset); @@ -233,17 +233,17 @@ SeekableReadStream *PEResources::getResource(const WinResourceID &type, const Wi SeekableReadStream *PEResources::getResource(const WinResourceID &type, const WinResourceID &name, const WinResourceID &lang) { if (!_exe || !_resources.contains(type)) - return 0; + return nullptr; const NameMap &nameMap = _resources[type]; if (!nameMap.contains(name)) - return 0; + return nullptr; const LangMap &langMap = nameMap[name]; if (!langMap.contains(lang)) - return 0; + return nullptr; const Resource &resource = langMap[lang]; _exe->seek(resource.offset); diff --git a/common/xmlparser.cpp b/common/xmlparser.cpp index 4470180710..48203e8fe5 100644 --- a/common/xmlparser.cpp +++ b/common/xmlparser.cpp @@ -74,7 +74,7 @@ bool XMLParser::loadStream(SeekableReadStream *stream) { void XMLParser::close() { delete _stream; - _stream = 0; + _stream = nullptr; } bool XMLParser::parserError(const String &errStr) { @@ -299,13 +299,13 @@ bool XMLParser::closeKey() { } bool XMLParser::parse() { - if (_stream == 0) + if (_stream == nullptr) return false; // Make sure we are at the start of the stream. _stream->seek(0, SEEK_SET); - if (_XMLkeys == 0) + if (_XMLkeys == nullptr) buildLayout(); while (!_activeKey.empty()) @@ -373,12 +373,12 @@ bool XMLParser::parse() { break; } } else { - ParserNode *node = allocNode(); //new ParserNode; + ParserNode *node = allocNode(); // new ParserNode; node->name = _token; node->ignore = false; node->header = activeHeader; node->depth = _activeKey.size(); - node->layout = 0; + node->layout = nullptr; _activeKey.push(node); } diff --git a/common/xmlparser.h b/common/xmlparser.h index 1e474b596c..2e4596ac0f 100644 --- a/common/xmlparser.h +++ b/common/xmlparser.h @@ -92,7 +92,7 @@ public: /** * Parser constructor. */ - XMLParser() : _XMLkeys(0), _stream(0) {} + XMLParser() : _XMLkeys(nullptr), _stream(nullptr) {} virtual ~XMLParser(); @@ -195,7 +195,7 @@ public: if (!_activeKey.empty()) return _activeKey.top(); - return 0; + return nullptr; } /** diff --git a/common/zlib.cpp b/common/zlib.cpp index 39130beb4e..6afffb14d2 100644 --- a/common/zlib.cpp +++ b/common/zlib.cpp @@ -71,7 +71,7 @@ bool inflateZlibHeaderless(byte *dst, uint dstLen, const byte *src, uint srcLen, return false; // Set the dictionary, if provided - if (dict != 0) { + if (dict != nullptr) { err = inflateSetDictionary(&stream, const_cast<byte *>(dict), dictLen); if (err != Z_OK) return false; @@ -168,7 +168,7 @@ protected: public: GZipReadStream(SeekableReadStream *w, uint32 knownSize = 0) : _wrapped(w), _stream() { - assert(w != 0); + assert(w != nullptr); // Verify file header is correct w->seek(0, SEEK_SET); @@ -281,7 +281,7 @@ public: _wrapped->seek(0, SEEK_SET); _zlibErr = inflateReset(&_stream); if (_zlibErr != Z_OK) - return false; // FIXME: STREAM REWRITE + return false; // FIXME: STREAM REWRITE _stream.next_in = _buf; _stream.avail_in = 0; } @@ -297,7 +297,7 @@ public: } _eos = false; - return true; // FIXME: STREAM REWRITE + return true; // FIXME: STREAM REWRITE } }; @@ -335,7 +335,7 @@ protected: public: GZipWriteStream(WriteStream *w) : _wrapped(w), _stream(), _pos(0) { - assert(w != 0); + assert(w != nullptr); // Adding 16 to windowBits indicates to zlib that it is supposed to // write gzip headers. This feature was added in zlib 1.2.0.4, @@ -352,7 +352,7 @@ public: _stream.next_out = _buf; _stream.avail_out = BUFSIZE; _stream.avail_in = 0; - _stream.next_in = 0; + _stream.next_in = nullptr; } ~GZipWriteStream() { diff --git a/common/zlib.h b/common/zlib.h index c8877e98a1..eb0548344d 100644 --- a/common/zlib.h +++ b/common/zlib.h @@ -75,7 +75,7 @@ bool uncompress(byte *dst, unsigned long *dstLen, const byte *src, unsigned long * * @return true on success (Z_OK or Z_STREAM_END), false otherwise. */ -bool inflateZlibHeaderless(byte *dst, uint dstLen, const byte *src, uint srcLen, const byte *dict = 0, uint dictLen = 0); +bool inflateZlibHeaderless(byte *dst, uint dstLen, const byte *src, uint srcLen, const byte *dict = nullptr, uint dictLen = 0); /** * Wrapper around zlib's inflate functions. This function will call the |