[Scummvm-git-logs] scummvm master -> 23ef244d3d6da9073cf3dbc9d1d4688881acbdcf
Strangerke
noreply at scummvm.org
Fri May 24 07:19:40 UTC 2024
This automated email contains information about 5 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
f357df8bb4 BAGEL: Remove unused parameters in bofMemFree(), fix function doc for encrypt()
976410c4a4 BAGEL: Fix comments in list.h, reduce a couple of variable scopes
d73724c1b2 BAGEL: As bof(Mem)Alloc now trigger a fatal error on failure, remove all the null checks related to their uses
a913965e8b BAGEL: Remove useless null check on bofCAlloc return value
23ef244d3d BAGEL: rename bofCAlloc to bofCleanAlloc, remove second useless parameter (always 1 element)
Commit: f357df8bb4502462760bd9e5ff9e61643b7c333d
https://github.com/scummvm/scummvm/commit/f357df8bb4502462760bd9e5ff9e61643b7c333d
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2024-05-24T08:08:20+01:00
Commit Message:
BAGEL: Remove unused parameters in bofMemFree(), fix function doc for encrypt()
Changed paths:
engines/bagel/boflib/misc.cpp
engines/bagel/boflib/misc.h
diff --git a/engines/bagel/boflib/misc.cpp b/engines/bagel/boflib/misc.cpp
index 9e71e22b613..55d6de75cbf 100644
--- a/engines/bagel/boflib/misc.cpp
+++ b/engines/bagel/boflib/misc.cpp
@@ -81,9 +81,7 @@ void *bofMemAlloc(uint32 nSize, const char *pFile, int nLine, bool bClear) {
return pNewBlock;
}
-void bofMemFree(void *pBuf, const char *pFile, int nLine) {
- assert(pFile != nullptr);
-
+void bofMemFree(void *pBuf) {
free(pBuf);
}
diff --git a/engines/bagel/boflib/misc.h b/engines/bagel/boflib/misc.h
index af3ac4081cf..c52135a9320 100644
--- a/engines/bagel/boflib/misc.h
+++ b/engines/bagel/boflib/misc.h
@@ -77,14 +77,12 @@ extern void *bofMemAlloc(uint32 nSize, const char *pFile, int nLine, bool bClear
/**
* Frees specified memory block
* @param pBuf Buffer to de-allocate
- * @param pFile Source file name
- * @param nLine Source file line number
**/
-extern void bofMemFree(void *pBuf, const char *pFile, int nLine);
+extern void bofMemFree(void *pBuf);
#define bofAlloc(n) bofMemAlloc((n), __FILE__, __LINE__, false)
#define bofCAlloc(n, m) bofMemAlloc((uint32)(n) * (m), __FILE__, __LINE__, true)
-#define bofFree(p) bofMemFree((p), __FILE__, __LINE__)
+#define bofFree(p) bofMemFree((p))
inline uint32 getFreePhysMem() {
return 999999;
@@ -96,7 +94,7 @@ inline uint32 getFreePhysMem() {
* @param lSize Number of bytes in buffer
* @param pszPassword Optional password to encrypt with
*/
-void encrypt(void *, int32, const char *pPassword = nullptr);
+void encrypt(void *pBuf, int32 lSize, const char *pszPassword = nullptr);
#define decrypt encrypt
extern void encryptPartial(void *, int32, int32, const char *pPassword = nullptr);
Commit: 976410c4a45cd58c4b8e7c978cdb2073befce863
https://github.com/scummvm/scummvm/commit/976410c4a45cd58c4b8e7c978cdb2073befce863
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2024-05-24T08:08:20+01:00
Commit Message:
BAGEL: Fix comments in list.h, reduce a couple of variable scopes
Changed paths:
engines/bagel/boflib/list.h
diff --git a/engines/bagel/boflib/list.h b/engines/bagel/boflib/list.h
index a87600c9256..8358b550e8b 100644
--- a/engines/bagel/boflib/list.h
+++ b/engines/bagel/boflib/list.h
@@ -78,9 +78,6 @@ private:
}
void recalcItemList() {
- CBofListNode<T> *pNode;
- int i;
-
// We only want to recalc if we're about to overflow what we have
if (_nNumItems >= _nItemsAllocated) {
if (_pItemList != nullptr) {
@@ -101,8 +98,8 @@ private:
if (_nNumItems != 0) {
assert(_pItemList != nullptr);
- i = 0;
- pNode = _pHead;
+ int i = 0;
+ CBofListNode<T> *pNode = _pHead;
while (pNode != nullptr) {
*(_pItemList + i++) = pNode;
@@ -243,7 +240,7 @@ public:
/**
* Retrieves the node at the specified location
* @returns Returns the node located at the given index.
- * @param nIndex Index of node to retrieve
+ * @param nNodeIndex Index of node to retrieve
*/
CBofListNode<T> *getNode(int nNodeIndex) {
assert(nNodeIndex >= 0 && nNodeIndex < getCount());
@@ -348,15 +345,13 @@ public:
}
/**
- * Removes specfied node from the list
+ * Removes specified node from the list
* @param pNode Node to remove
* @returns Item stored at specified location
*/
T remove(CBofListNode<T> *pNode) {
assert(pNode != nullptr);
- T retVal;
-
// One less item in list
_nNumItems--;
@@ -364,7 +359,7 @@ public:
if (pNode != nullptr) {
- retVal = pNode->getNodeItem();
+ T retVal = pNode->getNodeItem();
if (_pHead == pNode)
_pHead = _pHead->_pNext;
@@ -388,7 +383,7 @@ public:
}
/**
- * Removes specfied node (by index) from the list
+ * Removes specified node (by index) from the list
* @param nNodeIndex Index of node to remove
* @returns Item stored at specified location
*/
@@ -408,7 +403,7 @@ public:
}
/**
- * Removes specfied node (by index) from the list
+ * Removes specified node (by index) from the list
* @returns Item stored at specified location
*/
inline T removeHead() {
@@ -418,7 +413,7 @@ public:
}
/**
- * Removes specfied node (by index) from the list
+ * Removes specified node (by index) from the list
* @returns Item stored at specified location
*/
inline T removeTail() {
@@ -428,7 +423,7 @@ public:
/**
* Adds specified node as the new head of this list
- * @param pNode Pointer to node to add to the list
+ * @param pNewNode Pointer to node to add to the list
*/
inline void addToHead(CBofListNode<T> *pNewNode) {
assert(pNewNode != nullptr);
@@ -459,7 +454,7 @@ public:
/**
* Adds specified node as the new tail of this list
- * @param pNode Pointer to node to add to the list
+ * @param pNewNode Pointer to node to add to the list
*/
void addToTail(CBofListNode<T> *pNewNode) {
assert(pNewNode != nullptr);
Commit: d73724c1b2da49cee3c2e4ce6f2f0de99f9784ee
https://github.com/scummvm/scummvm/commit/d73724c1b2da49cee3c2e4ce6f2f0de99f9784ee
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2024-05-24T08:08:20+01:00
Commit Message:
BAGEL: As bof(Mem)Alloc now trigger a fatal error on failure, remove all the null checks related to their uses
Changed paths:
engines/bagel/baglib/character_object.cpp
engines/bagel/baglib/master_win.cpp
engines/bagel/baglib/save_game_file.cpp
engines/bagel/baglib/storage_dev_win.cpp
engines/bagel/boflib/dat_file.cpp
engines/bagel/boflib/gfx/bitmap.cpp
engines/bagel/boflib/res.cpp
engines/bagel/boflib/string.cpp
engines/bagel/spacebar/computer.cpp
engines/bagel/spacebar/sraf_computer.cpp
diff --git a/engines/bagel/baglib/character_object.cpp b/engines/bagel/baglib/character_object.cpp
index 0187522d21b..da80070bdb4 100644
--- a/engines/bagel/baglib/character_object.cpp
+++ b/engines/bagel/baglib/character_object.cpp
@@ -104,11 +104,7 @@ ErrorCode CBagCharacterObject::attach() {
_binBufLen = cInputFile.getLength();
_binBuf = (char *)bofAlloc(_binBufLen + 1);
- if (_binBuf != nullptr) {
- cInputFile.read(_binBuf, _binBufLen);
- } else {
- reportError(ERR_MEMORY, "Unable to allocate a buffer of %d bytes", _binBufLen + 1);
- }
+ cInputFile.read(_binBuf, _binBufLen);
}
// Set the start and stop frames if still default.
diff --git a/engines/bagel/baglib/master_win.cpp b/engines/bagel/baglib/master_win.cpp
index b3d95365b54..ca612cb9bf4 100644
--- a/engines/bagel/baglib/master_win.cpp
+++ b/engines/bagel/baglib/master_win.cpp
@@ -373,8 +373,6 @@ ErrorCode CBagMasterWin::loadFile(const CBofString &wldName, const CBofString &s
// Only allocate the object list when we really need it...
if (_objList == nullptr) {
_objList = (StObj *)bofAlloc(MAX_OBJS * sizeof(StObj));
- if (_objList == nullptr)
- fatalError(ERR_MEMORY, "Could not allocate Object list");
// Init to zero (we might not use all slots)
memset(_objList, 0, MAX_OBJS * sizeof(StObj));
@@ -426,18 +424,16 @@ ErrorCode CBagMasterWin::loadFile(const CBofString &wldName, const CBofString &s
// is pre-loaded
int length = fileLength(wldFileName);
char *fileBuf = (char *)bofAlloc(length);
- if (fileBuf != nullptr) {
- CBagIfstream fpInput(fileBuf, length);
+ CBagIfstream fpInput(fileBuf, length);
- CBofFile file;
- file.open(wldFileName);
- file.read(fileBuf, length);
- file.close();
+ CBofFile file;
+ file.open(wldFileName);
+ file.read(fileBuf, length);
+ file.close();
- loadFileFromStream(fpInput, startWldName);
+ loadFileFromStream(fpInput, startWldName);
- bofFree(fileBuf);
- }
+ bofFree(fileBuf);
// Possibly need to switch CDs
CBagel *bagApp = CBagel::getBagApp();
@@ -570,55 +566,53 @@ ErrorCode CBagMasterWin::loadGlobalVars(const CBofString &wldName) {
// is pre-loaded
int length = fileLength(wldFileName);
char *buffer = (char *)bofAlloc(length);
- if (buffer != nullptr) {
- CBagIfstream fpInput(buffer, length);
+ CBagIfstream fpInput(buffer, length);
- CBofFile file;
- file.open(wldFileName);
- file.read(buffer, length);
- file.close();
+ CBofFile file;
+ file.open(wldFileName);
+ file.read(buffer, length);
+ file.close();
- while (!fpInput.eof()) {
- fpInput.eatWhite();
+ while (!fpInput.eof()) {
+ fpInput.eatWhite();
- if (!fpInput.eatWhite()) {
- break;
- }
-
- KEYWORDS keyword;
- getKeywordFromStream(fpInput, keyword);
+ if (!fpInput.eatWhite()) {
+ break;
+ }
- switch (keyword) {
- case VARIABLE: {
- CBagVar *var = new CBagVar;
- fpInput.eatWhite();
- var->setInfo(fpInput);
- var->setGlobal();
- break;
- }
+ KEYWORDS keyword;
+ getKeywordFromStream(fpInput, keyword);
- case REMARK: {
- char dummyStr[256];
- fpInput.getCh(dummyStr, 255);
- break;
- }
+ switch (keyword) {
+ case VARIABLE: {
+ CBagVar *var = new CBagVar;
+ fpInput.eatWhite();
+ var->setInfo(fpInput);
+ var->setGlobal();
+ break;
+ }
- case STORAGEDEV:
- case START_WLD:
- case SYSSCREEN:
- case DISKID:
- case DISKAUDIO:
- case SHAREDPAL:
- case PDASTATE:
- default: {
- parseAlertBox(fpInput, "Syntax Error: Unexpected Type in Global Var Wld:", __FILE__, __LINE__);
- break;
- }
- }
+ case REMARK: {
+ char dummyStr[256];
+ fpInput.getCh(dummyStr, 255);
+ break;
}
- bofFree(buffer);
+ case STORAGEDEV:
+ case START_WLD:
+ case SYSSCREEN:
+ case DISKID:
+ case DISKAUDIO:
+ case SHAREDPAL:
+ case PDASTATE:
+ default: {
+ parseAlertBox(fpInput, "Syntax Error: Unexpected Type in Global Var Wld:", __FILE__, __LINE__);
+ break;
+ }
+ }
}
+
+ bofFree(buffer);
}
return _errCode;
@@ -1517,9 +1511,6 @@ bool CBagMasterWin::showSaveDialog(CBofWindow *win, bool bSaveBkg) {
CBofSound::pauseSounds();
StBagelSave *saveBuf = (StBagelSave *)bofAlloc(sizeof(StBagelSave));
- if (saveBuf == nullptr)
- fatalError(ERR_MEMORY, "Unable to allocate the Save Game Buffer");
-
fillSaveBuffer(saveBuf);
CBagSaveDialog saveDialog;
saveDialog.setSaveGameBuffer((byte *)saveBuf, sizeof(StBagelSave));
@@ -1634,8 +1625,6 @@ void CBagMasterWin::doRestore(StBagelSave *saveBuf) {
// Restore any extra obj list info (for .WLD swapping)
if (_objList == nullptr) {
_objList = (StObj *)bofAlloc(MAX_OBJS * sizeof(StObj));
- if (_objList == nullptr)
- fatalError(ERR_MEMORY, "Unable to allocate a array of %d StObj", MAX_OBJS);
// Init to nullptr (might not use all slots)
memset(_objList, 0, MAX_OBJS * sizeof(StObj));
diff --git a/engines/bagel/baglib/save_game_file.cpp b/engines/bagel/baglib/save_game_file.cpp
index 4353f506ee1..2185b91dab7 100644
--- a/engines/bagel/baglib/save_game_file.cpp
+++ b/engines/bagel/baglib/save_game_file.cpp
@@ -190,7 +190,6 @@ ErrorCode CBagSaveGameFile::readSavedGame(int32 slotNum) {
_errCode = ERR_FREAD;
} else {
byte *pBuf = (byte *)bofAlloc(lSize);
- assert(pBuf);
readRecord(lRecNum, pBuf);
// Load in the savegame
@@ -233,8 +232,6 @@ ErrorCode CBagSaveGameFile::readTitle(int32 lSlot, StSavegameHeader *pSavedGame)
int32 lSize = getRecSize(lRecNum);
byte *pBuf = (byte *)bofAlloc(lSize);
- if (pBuf == nullptr)
- fatalError(ERR_MEMORY, "Could not allocate %ld bytes to read a saved game title", lSize);
readRecord(lRecNum, pBuf);
diff --git a/engines/bagel/baglib/storage_dev_win.cpp b/engines/bagel/baglib/storage_dev_win.cpp
index 7f2b65cc49e..9dc007241c0 100644
--- a/engines/bagel/baglib/storage_dev_win.cpp
+++ b/engines/bagel/baglib/storage_dev_win.cpp
@@ -573,18 +573,17 @@ ErrorCode CBagStorageDev::loadFile(const CBofString &sWldName) {
error("Unable to open or read %s", sWldFileName.getBuffer());
char *pBuf = (char *)bofAlloc(nLength);
- if (pBuf != nullptr) {
- CBagIfstream fpInput(pBuf, nLength);
+ CBagIfstream fpInput(pBuf, nLength);
- CBofFile cFile;
- cFile.open(sWldFileName);
- cFile.read(pBuf, nLength);
- cFile.close();
+ CBofFile cFile;
+ cFile.open(sWldFileName);
+ cFile.read(pBuf, nLength);
+ cFile.close();
- CBagStorageDev::loadFileFromStream(fpInput, sWldFileName);
+ CBagStorageDev::loadFileFromStream(fpInput, sWldFileName);
+
+ bofFree(pBuf);
- bofFree(pBuf);
- }
// Add everything to the window
return ERR_NONE;
}
@@ -1435,9 +1434,6 @@ ErrorCode CBagStorageDevWnd::loadFile(const CBofString &sFile) {
reportError(ERR_FOPEN, "Unable to open file %s", sWldFile.getBuffer());
else {
char *pBuf = (char *)bofAlloc(nLength);
- if (pBuf == nullptr)
- fatalError(ERR_MEMORY, "Unable to allocate a buffer of %d bytes", nLength);
-
CBagIfstream fpInput(pBuf, nLength);
CBofFile cFile;
@@ -1714,21 +1710,19 @@ ErrorCode CBagStorageDevDlg::loadFile(const CBofString &sFile) {
reportError(ERR_FOPEN, "Unable to open file %s", sWldFile.getBuffer());
else {
char *pBuf = (char *)bofAlloc(nLength);
- if (pBuf != nullptr) {
- CBagIfstream fpInput(pBuf, nLength);
+ CBagIfstream fpInput(pBuf, nLength);
- CBofFile cFile;
- cFile.open(sWldFile);
- cFile.read(pBuf, nLength);
- cFile.close();
+ CBofFile cFile;
+ cFile.open(sWldFile);
+ cFile.read(pBuf, nLength);
+ cFile.close();
- CBagStorageDev::loadFileFromStream(fpInput, sWldFile);
+ CBagStorageDev::loadFileFromStream(fpInput, sWldFile);
- bofFree(pBuf);
+ bofFree(pBuf);
- if (isCreated())
- invalidateRect(nullptr);
- }
+ if (isCreated())
+ invalidateRect(nullptr);
}
// Add everything to the window
return _errCode;
diff --git a/engines/bagel/boflib/dat_file.cpp b/engines/bagel/boflib/dat_file.cpp
index 98ee61c6c95..291292d7b90 100644
--- a/engines/bagel/boflib/dat_file.cpp
+++ b/engines/bagel/boflib/dat_file.cpp
@@ -490,8 +490,6 @@ ErrorCode CBofDataFile::writeRecord(int32 lRecNum, void *pBuf, int32 lSize, bool
// Allocate a buffer big enough for one chunk
byte *pTmpBuf = (byte *)bofAlloc(lChunkSize);
- if (pTmpBuf == nullptr)
- fatalError(ERR_MEMORY, "Unable to allocate %ld bytes to expand record size in writeRecord()", lBufLength);
// While there is data to move
while (lBufLength > 0) {
@@ -550,8 +548,6 @@ ErrorCode CBofDataFile::writeRecord(int32 lRecNum, void *pBuf, int32 lSize, bool
// Allocate a buffer that could hold the largest record
byte *pTmpBuf = (byte *)bofAlloc(bufferSize);
- if (pTmpBuf == nullptr)
- fatalError(ERR_MEMORY, "unable to allocate a buffer of %d bytes", bufferSize);
for (int i = (int)lRecNum + 1; i < (int)_lNumRecs - 1; i++) {
_errCode = readRecord(i, pTmpBuf);
@@ -594,8 +590,6 @@ ErrorCode CBofDataFile::verifyRecord(int32 lRecNum) {
// Allocate space to hold this record
void *pBuf = bofAlloc((int)getRecSize(lRecNum));
- if (pBuf == nullptr)
- fatalError(ERR_MEMORY, "Unable to allocate a buffer of %ld bytes", getRecSize(lRecNum));
_errCode = readRecord(lRecNum, pBuf);
bofFree(pBuf);
diff --git a/engines/bagel/boflib/gfx/bitmap.cpp b/engines/bagel/boflib/gfx/bitmap.cpp
index 55e88d74ffa..345ba554faf 100644
--- a/engines/bagel/boflib/gfx/bitmap.cpp
+++ b/engines/bagel/boflib/gfx/bitmap.cpp
@@ -796,38 +796,36 @@ ErrorCode CBofBitmap::scrollRight(int nPixels, CBofRect * /*pRect*/) {
assert(_pBits != nullptr);
byte *pTemp = (byte *)bofAlloc(abs(nPixels));
- if (pTemp != nullptr) {
- int nBytes = _nDX - nPixels;
- if (nPixels < 0) {
- nBytes = _nDX + nPixels;
- }
+ int nBytes = _nDX - nPixels;
+ if (nPixels < 0) {
+ nBytes = _nDX + nPixels;
+ }
- byte *p = _pBits;
+ byte *p = _pBits;
- lock();
+ lock();
- if (nPixels > 0) {
- for (int i = 0; i < _nDY; i++) {
- memcpy(pTemp, p + nBytes, nPixels);
- memmove(p + nPixels, p, nBytes);
- memcpy(p, pTemp, nPixels);
- p += _nScanDX;
- }
- } else {
- nPixels = -nPixels;
-
- for (int i = 0; i < _nDY; i++) {
- memcpy(pTemp, p, nPixels);
- memmove(p, p + nPixels, nBytes);
- memcpy(p + nBytes, pTemp, nPixels);
- p += _nScanDX;
- }
+ if (nPixels > 0) {
+ for (int i = 0; i < _nDY; i++) {
+ memcpy(pTemp, p + nBytes, nPixels);
+ memmove(p + nPixels, p, nBytes);
+ memcpy(p, pTemp, nPixels);
+ p += _nScanDX;
}
+ } else {
+ nPixels = -nPixels;
- unlock();
-
- bofFree(pTemp);
+ for (int i = 0; i < _nDY; i++) {
+ memcpy(pTemp, p, nPixels);
+ memmove(p, p + nPixels, nBytes);
+ memcpy(p + nBytes, pTemp, nPixels);
+ p += _nScanDX;
+ }
}
+
+ unlock();
+
+ bofFree(pTemp);
}
}
@@ -871,11 +869,8 @@ ErrorCode CBofBitmap::scrollUp(int nPixels) {
// Only scroll if we need to
if (nPixels != 0) {
- byte *pRowBuf = (byte *)bofAlloc(dx);
-
// Allocate a buffer to hold one horizontal line
- if (pRowBuf == nullptr)
- fatalError(ERR_MEMORY, "Error: scrollUp - Could not allocate %ld bytes for row", dx);
+ byte *pRowBuf = (byte *)bofAlloc(dx);
byte *pStart = _pBits;
byte *pEnd = _pBits;
diff --git a/engines/bagel/boflib/res.cpp b/engines/bagel/boflib/res.cpp
index aba885800dd..b9681a9f827 100644
--- a/engines/bagel/boflib/res.cpp
+++ b/engines/bagel/boflib/res.cpp
@@ -54,8 +54,6 @@ ErrorCode CBofStringTable::load(const char *pszFileName) {
// Allocate a buffer to hold entire file
_pBuf = (byte *)bofAlloc(_lBufSize + 1);
- if (_pBuf == nullptr)
- fatalError(ERR_MEMORY, "Unable to allocate %u bytes for String Table", _lBufSize + 1);
memset(_pBuf, 0, _lBufSize + 1);
diff --git a/engines/bagel/boflib/string.cpp b/engines/bagel/boflib/string.cpp
index 9817dc29cce..c89b5b0954a 100644
--- a/engines/bagel/boflib/string.cpp
+++ b/engines/bagel/boflib/string.cpp
@@ -104,10 +104,8 @@ void CBofString::allocBuffer(int nLen) {
// Don't do anything about zero length allocations
if (nLen > 0) {
_pszData = (char *)bofAlloc(nLen + 1);
- if (_pszData != nullptr) {
- // Set the entire buffer to nullptr
- memset(_pszData, '\0', nLen + 1);
- }
+ // Set the entire buffer to nullptr
+ memset(_pszData, '\0', nLen + 1);
}
_nLength = 0;
@@ -575,22 +573,21 @@ void CBofString::growTo(int nNewSize) {
// Otherwise, we must keep track of whats in the buffer
// Create a temp buffer to save string
char *p = (char *)bofAlloc(_nLength + 2);
- if (p != nullptr) {
- // Save copy of string
- Common::strcpy_s(p, MAX_STRING, _pszData);
- // Make the new buffer
- allocBuffer(nNewSize);
+ // Save copy of string
+ Common::strcpy_s(p, MAX_STRING, _pszData);
- // Copy saved string back
- strncpy(_pszData, p, nNewSize - 1);
+ // Make the new buffer
+ allocBuffer(nNewSize);
- // Get it's new length
- _nLength = (uint16)strlen(_pszData);
+ // Copy saved string back
+ strncpy(_pszData, p, nNewSize - 1);
- // Don't need temp buffer anymore
- bofFree(p);
- }
+ // Get it's new length
+ _nLength = (uint16)strlen(_pszData);
+
+ // Don't need temp buffer anymore
+ bofFree(p);
}
}
diff --git a/engines/bagel/spacebar/computer.cpp b/engines/bagel/spacebar/computer.cpp
index b4df6d71fc4..471b3f9b0fc 100644
--- a/engines/bagel/spacebar/computer.cpp
+++ b/engines/bagel/spacebar/computer.cpp
@@ -241,8 +241,6 @@ ErrorCode SBarComputer::readDrnkFile() {
// Allocate the buffers
_pDrinkBuff = (char *)bofAlloc(fpDrinkFile.getLength() + 1);
- if (_pDrinkBuff == nullptr)
- return ERR_MEMORY;
// Read the text file into buffers
fpDrinkFile.read(_pDrinkBuff, fpDrinkFile.getLength());
@@ -310,8 +308,6 @@ ErrorCode SBarComputer::readIngFile() {
// Allocate the buffers
_pIngBuff = (char *)bofAlloc(fpIngFile.getLength() + 1);
- if (_pIngBuff == nullptr)
- fatalError(ERR_MEMORY, "Unable to allocate buffer of %u bytes", fpIngFile.getLength() + 1);
// Read the text file into buffers
fpIngFile.read(_pIngBuff, fpIngFile.getLength());
diff --git a/engines/bagel/spacebar/sraf_computer.cpp b/engines/bagel/spacebar/sraf_computer.cpp
index fc692410e81..8f759804e9d 100644
--- a/engines/bagel/spacebar/sraf_computer.cpp
+++ b/engines/bagel/spacebar/sraf_computer.cpp
@@ -4133,8 +4133,6 @@ void SrafComputer::notifyBoss(CBofString &sSoundFile, int nStafferID) {
reportError(ERR_FREAD, "Unexpected empty file %s", sSoundFile.getBuffer());
} else {
char *pszBuf = (char *)bofAlloc(nLength + 1);
- if (pszBuf == nullptr)
- fatalError(ERR_MEMORY, "Could not allocate a buffer of %u bytes", nLength + 1);
memset(pszBuf, 0, nLength + 1);
fTxtFile.read(pszBuf, nLength);
Commit: a913965e8b8880b7c149ba86434963abea5ccfb2
https://github.com/scummvm/scummvm/commit/a913965e8b8880b7c149ba86434963abea5ccfb2
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2024-05-24T08:17:10+01:00
Commit Message:
BAGEL: Remove useless null check on bofCAlloc return value
Changed paths:
engines/bagel/baglib/help.cpp
engines/bagel/baglib/save_game_file.cpp
engines/bagel/baglib/text_object.cpp
engines/bagel/dialogs/credits_dialog.cpp
diff --git a/engines/bagel/baglib/help.cpp b/engines/bagel/baglib/help.cpp
index 2c15644dd6c..8ecc2264ce7 100644
--- a/engines/bagel/baglib/help.cpp
+++ b/engines/bagel/baglib/help.cpp
@@ -122,8 +122,6 @@ ErrorCode CBagHelp::attach() {
uint32 size = file.getLength();
char *buffer = (char *)bofCAlloc(size + 1, 1);
- if (buffer == nullptr)
- fatalError(ERR_MEMORY, "Unable to allocate %d bytes to read %s.", size, _textFile.getBuffer());
file.read(buffer, size);
diff --git a/engines/bagel/baglib/save_game_file.cpp b/engines/bagel/baglib/save_game_file.cpp
index 2185b91dab7..0f46503001b 100644
--- a/engines/bagel/baglib/save_game_file.cpp
+++ b/engines/bagel/baglib/save_game_file.cpp
@@ -232,7 +232,6 @@ ErrorCode CBagSaveGameFile::readTitle(int32 lSlot, StSavegameHeader *pSavedGame)
int32 lSize = getRecSize(lRecNum);
byte *pBuf = (byte *)bofAlloc(lSize);
-
readRecord(lRecNum, pBuf);
// Fill StSavegameHeader structure with this game's saved info
diff --git a/engines/bagel/baglib/text_object.cpp b/engines/bagel/baglib/text_object.cpp
index afe777f49f8..d416e52bca5 100644
--- a/engines/bagel/baglib/text_object.cpp
+++ b/engines/bagel/baglib/text_object.cpp
@@ -142,8 +142,6 @@ ErrorCode CBagTextObject::attach() {
// Allocate the buffers
uint32 nFileLen = fpTextFile.getLength();
char *pTextBuff = (char *)bofCAlloc(nFileLen + 1, 1);
- if (pTextBuff == nullptr)
- fatalError(ERR_MEMORY, "Unable to allocate a Text buffer of %u bytes", nFileLen + 1);
// Read the text file into buffers
fpTextFile.read(pTextBuff, nFileLen);
diff --git a/engines/bagel/dialogs/credits_dialog.cpp b/engines/bagel/dialogs/credits_dialog.cpp
index c7361da8c16..ecf34a966fa 100644
--- a/engines/bagel/dialogs/credits_dialog.cpp
+++ b/engines/bagel/dialogs/credits_dialog.cpp
@@ -142,8 +142,6 @@ ErrorCode CBagCreditsDialog::loadNextTextFile() {
// Read in text file
uint32 lSize = cFile.getLength();
_pszText = (char *)bofCAlloc(lSize + 1, 1);
- if (_pszText == nullptr)
- fatalError(ERR_MEMORY, "Unable to allocate %d bytes for Credits.", lSize);
cFile.read(_pszText, lSize);
Commit: 23ef244d3d6da9073cf3dbc9d1d4688881acbdcf
https://github.com/scummvm/scummvm/commit/23ef244d3d6da9073cf3dbc9d1d4688881acbdcf
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2024-05-24T08:19:16+01:00
Commit Message:
BAGEL: rename bofCAlloc to bofCleanAlloc, remove second useless parameter (always 1 element)
Changed paths:
engines/bagel/baglib/help.cpp
engines/bagel/baglib/text_object.cpp
engines/bagel/boflib/misc.h
engines/bagel/dialogs/credits_dialog.cpp
diff --git a/engines/bagel/baglib/help.cpp b/engines/bagel/baglib/help.cpp
index 8ecc2264ce7..0ebc58f7e88 100644
--- a/engines/bagel/baglib/help.cpp
+++ b/engines/bagel/baglib/help.cpp
@@ -121,7 +121,7 @@ ErrorCode CBagHelp::attach() {
CBofFile file(_textFile, CBF_BINARY | CBF_READONLY);
uint32 size = file.getLength();
- char *buffer = (char *)bofCAlloc(size + 1, 1);
+ char *buffer = (char *)bofCleanAlloc(size + 1);
file.read(buffer, size);
diff --git a/engines/bagel/baglib/text_object.cpp b/engines/bagel/baglib/text_object.cpp
index d416e52bca5..53e1d107715 100644
--- a/engines/bagel/baglib/text_object.cpp
+++ b/engines/bagel/baglib/text_object.cpp
@@ -141,7 +141,7 @@ ErrorCode CBagTextObject::attach() {
if (!fpTextFile.errorOccurred()) {
// Allocate the buffers
uint32 nFileLen = fpTextFile.getLength();
- char *pTextBuff = (char *)bofCAlloc(nFileLen + 1, 1);
+ char *pTextBuff = (char *)bofCleanAlloc(nFileLen + 1);
// Read the text file into buffers
fpTextFile.read(pTextBuff, nFileLen);
diff --git a/engines/bagel/boflib/misc.h b/engines/bagel/boflib/misc.h
index c52135a9320..c751e4cdd59 100644
--- a/engines/bagel/boflib/misc.h
+++ b/engines/bagel/boflib/misc.h
@@ -81,7 +81,7 @@ extern void *bofMemAlloc(uint32 nSize, const char *pFile, int nLine, bool bClear
extern void bofMemFree(void *pBuf);
#define bofAlloc(n) bofMemAlloc((n), __FILE__, __LINE__, false)
-#define bofCAlloc(n, m) bofMemAlloc((uint32)(n) * (m), __FILE__, __LINE__, true)
+#define bofCleanAlloc(n) bofMemAlloc((n), __FILE__, __LINE__, true)
#define bofFree(p) bofMemFree((p))
inline uint32 getFreePhysMem() {
diff --git a/engines/bagel/dialogs/credits_dialog.cpp b/engines/bagel/dialogs/credits_dialog.cpp
index ecf34a966fa..7318113b4a4 100644
--- a/engines/bagel/dialogs/credits_dialog.cpp
+++ b/engines/bagel/dialogs/credits_dialog.cpp
@@ -141,7 +141,7 @@ ErrorCode CBagCreditsDialog::loadNextTextFile() {
if (!cFile.errorOccurred()) {
// Read in text file
uint32 lSize = cFile.getLength();
- _pszText = (char *)bofCAlloc(lSize + 1, 1);
+ _pszText = (char *)bofCleanAlloc(lSize + 1);
cFile.read(_pszText, lSize);
More information about the Scummvm-git-logs
mailing list