[Scummvm-git-logs] scummvm master -> a3386d53e1542ac6f6917e1e46f0d0e30adabba1

Strangerke noreply at scummvm.org
Thu May 16 07:04:29 UTC 2024


This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
53225d4ae0 BAGEL: In CBofMovie, remove some useless null checks before delete and reduce if depth of onMainLoop()
fad644c1fa BAGEL: Some renaming in CBofDataFile, intialize pTmpHeader (CID 1544825)
a3386d53e1 BAGEL: Fix a potential allocation of negative size (CID 1544843)


Commit: 53225d4ae04d317b929ac703285354c9206e8b1f
    https://github.com/scummvm/scummvm/commit/53225d4ae04d317b929ac703285354c9206e8b1f
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2024-05-16T08:03:31+01:00

Commit Message:
BAGEL: In CBofMovie, remove some useless null checks before delete and reduce if depth of onMainLoop()

Changed paths:
    engines/bagel/boflib/gui/movie.cpp


diff --git a/engines/bagel/boflib/gui/movie.cpp b/engines/bagel/boflib/gui/movie.cpp
index 2ab9e8d0d8a..d51a7b9ee76 100644
--- a/engines/bagel/boflib/gui/movie.cpp
+++ b/engines/bagel/boflib/gui/movie.cpp
@@ -146,41 +146,40 @@ void  CBofMovie::onKeyHit(uint32 lKey, uint32 /*lRepCount*/) {
 }
 
 void  CBofMovie::onMainLoop() {
-	if (_pSmk->needsUpdate()) {
-		if (_eMovStatus != STOPPED) {
-			// Smack the current frame into the buffer
-			const Graphics::Surface *frame = _pSmk->decodeNextFrame();
-			if (_pSmk->hasDirtyPalette()) {
-				_pSbuf->setPalette(_pSmk->getPalette(), 0, 256);
+	if (!_pSmk->needsUpdate() || _eMovStatus == STOPPED)
+		return;
+
+	// Smack the current frame into the buffer
+	const Graphics::Surface *frame = _pSmk->decodeNextFrame();
+	if (_pSmk->hasDirtyPalette()) {
+		_pSbuf->setPalette(_pSmk->getPalette(), 0, 256);
+	}
+	if (frame) {
+		_pSbuf->blitFrom(*frame, _srcRect, _dstRect);
+		updateWindow();
+	}
+
+	if (_eMovStatus == FOREWARD) {
+		if (_pSmk->getCurFrame() == (int)_pSmk->getFrameCount() - 1) {
+			if (_bLoop == false) {
+				onMovieDone();
+			} else {
+				seekToStart();
+				_pSmk->start();
 			}
-			if (frame) {
-				_pSbuf->blitFrom(*frame, _srcRect, _dstRect);
-				updateWindow();
+		}
+	} else if (_eMovStatus == REVERSE) {
+		if ((_pSmk->getCurFrame() == 0) || (_pSmk->getCurFrame() == 1)) {
+			if (_bLoop == false) {
+				onMovieDone();
+			} else {
+				seekToEnd();
+				//_pSmk->start();
 			}
-
-			if (_eMovStatus == FOREWARD) {
-				if (_pSmk->getCurFrame() == (int)_pSmk->getFrameCount() - 1) {
-					if (_bLoop == false) {
-						onMovieDone();
-					} else {
-						seekToStart();
-						_pSmk->start();
-					}
-				}
-			} else if (_eMovStatus == REVERSE) {
-				if ((_pSmk->getCurFrame() == 0) || (_pSmk->getCurFrame() == 1)) {
-					if (_bLoop == false) {
-						onMovieDone();
-					} else {
-						seekToEnd();
-						//_smk->start();
-					}
-				} else {
-					setFrame(_pSmk->getCurFrame() - 2); // HACK: Reverse playback
-				}
-			}// MOVIE_REVERSE
-		}// !MOVIE_STOPPED
-	}// !SMACKWAIT
+		} else {
+			setFrame(_pSmk->getCurFrame() - 2); // HACK: Reverse playback
+		}
+	}// MOVIE_REVERSE
 }
 
 void  CBofMovie::onPaint(CBofRect *) {
@@ -190,15 +189,11 @@ void  CBofMovie::onPaint(CBofRect *) {
 }
 
 void  CBofMovie::closeMovie() {
-	if (_pSbuf) {
-		delete _pSbuf;
-		_pSbuf = nullptr;
-	}
+	delete _pSbuf;
+	_pSbuf = nullptr;
 
-	if (_pSmk) {
-		delete _pSmk;
-		_pSmk = nullptr;
-	}
+	delete _pSmk;
+	_pSmk = nullptr;
 }
 
 void  CBofMovie::onClose() {
@@ -239,7 +234,7 @@ bool CBofMovie::play(bool bLoop, bool bEscCanStop) {
 bool CBofMovie::play() {
 	if (_pSmk) {
 		_pSmk->pauseVideo(false);
-		//_smk->setReverse(false); // TODO: Not supported by SMK
+		//_pSmk->setReverse(false); // TODO: Not supported by SMK
 		_pSmk->start();
 		_eMovStatus = FOREWARD;
 		return true;


Commit: fad644c1fab5de09dbb1f664a99660f6520311f9
    https://github.com/scummvm/scummvm/commit/fad644c1fab5de09dbb1f664a99660f6520311f9
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2024-05-16T08:03:31+01:00

Commit Message:
BAGEL: Some renaming in CBofDataFile, intialize pTmpHeader (CID 1544825)

Changed paths:
    engines/bagel/boflib/dat_file.cpp
    engines/bagel/boflib/dat_file.h


diff --git a/engines/bagel/boflib/dat_file.cpp b/engines/bagel/boflib/dat_file.cpp
index ebd4e8f6e2f..c6a2ab4bb48 100644
--- a/engines/bagel/boflib/dat_file.cpp
+++ b/engines/bagel/boflib/dat_file.cpp
@@ -32,14 +32,14 @@ namespace Bagel {
 // Local prototypes
 static uint32 CreateHashCode(const byte *);
 
-void HEADER_REC::synchronize(Common::Serializer &s) {
+void HeaderRec::synchronize(Common::Serializer &s) {
 	s.syncAsSint32LE(_lOffset);
 	s.syncAsSint32LE(_lLength);
 	s.syncAsUint32LE(_lCrc);
 	s.syncAsUint32LE(_lKey);
 }
 
-void HEAD_INFO::synchronize(Common::Serializer &s) {
+void HeadInfo::synchronize(Common::Serializer &s) {
 	s.syncAsSint32LE(_lNumRecs);
 	s.syncAsSint32LE(_lAddress);
 	s.syncAsUint32LE(_lFlags);
@@ -132,7 +132,7 @@ ErrorCode CBofDataFile::releaseFile() {
 ErrorCode CBofDataFile::create() {
 	assert(isValidObject(this));
 
-	HEAD_INFO stHeaderInfo;
+	HeadInfo stHeaderInfo;
 
 	// Only continue if there is no current error
 	if (_errCode == ERR_NONE) {
@@ -151,7 +151,7 @@ ErrorCode CBofDataFile::create() {
 		_bHeaderDirty = false;
 
 		stHeaderInfo._lNumRecs = _lNumRecs = 0;
-		stHeaderInfo._lAddress = HEAD_INFO::size();
+		stHeaderInfo._lAddress = HeadInfo::size();
 
 		// Create the file
 		if (CBofFile::create(_szFileName, _lFlags) == ERR_NONE) {
@@ -219,20 +219,20 @@ ErrorCode CBofDataFile::readHeader() {
 
 		if (!errorOccurred()) {
 			// Determine number of records in file
-			HEAD_INFO stHeaderInfo;
+			HeadInfo stHeaderInfo;
 			if (read(stHeaderInfo) == ERR_NONE) {
 				_lNumRecs = stHeaderInfo._lNumRecs;
 				_lHeaderStart = stHeaderInfo._lAddress;
 
 				// Length of header is number of records * header-record size
-				_lHeaderLength = _lNumRecs * HEADER_REC::size();
+				_lHeaderLength = _lNumRecs * HeaderRec::size();
 
 				Common::SeekableReadStream *rs = dynamic_cast<Common::SeekableReadStream *>(_stream);
 				assert(rs);
 				int32 lfileLength = rs->size();
 
 				// Make sure header contains valid info
-				if ((_lHeaderStart >= HEAD_INFO::size()) &&
+				if ((_lHeaderStart >= HeadInfo::size()) &&
 				        (_lHeaderStart <= lfileLength) && (_lHeaderLength >= 0) &&
 				        (_lHeaderLength < lfileLength)) {
 
@@ -242,7 +242,7 @@ ErrorCode CBofDataFile::readHeader() {
 
 					if (_lHeaderLength != 0) {
 						// Allocate buffer to hold header
-						_pHeader = new HEADER_REC[(int)_lNumRecs];
+						_pHeader = new HeaderRec[(int)_lNumRecs];
 						if (_pHeader == nullptr)
 							fatalError(ERR_MEMORY, buildString("Could not allocate footer for file '%s'", _szFileName));
 
@@ -296,10 +296,10 @@ ErrorCode CBofDataFile::writeHeader() {
 
 		if (_errCode == ERR_NONE) {
 			// Header starts at the end of the last record
-			HEADER_REC *pRec = &_pHeader[_lNumRecs - 1];
+			HeaderRec *pRec = &_pHeader[_lNumRecs - 1];
 			_lHeaderStart = pRec->_lOffset + pRec->_lLength;
 
-			HEAD_INFO stHeaderInfo;
+			HeadInfo stHeaderInfo;
 			stHeaderInfo._lNumRecs = _lNumRecs;
 			stHeaderInfo._lAddress = _lHeaderStart;
 			stHeaderInfo._lFlags = _lFlags;
@@ -352,7 +352,7 @@ ErrorCode CBofDataFile::readRecord(int32 lRecNum, void *pBuf) {
 		assert(_pHeader != nullptr);
 		// Get info about address of where record starts
 		// and how large the record is.
-		HEADER_REC *pRecInfo = &_pHeader[(int)lRecNum];
+		HeaderRec *pRecInfo = &_pHeader[(int)lRecNum];
 
 		// Open the data file if it's not already open
 		if (_stream == nullptr) {
@@ -403,7 +403,7 @@ ErrorCode CBofDataFile::readFromFile(int32 lRecNum, void *pBuf, int32 lBytes) {
 
 		// Get info about address of where record starts
 		// and how large the record is.
-		HEADER_REC *pRecInfo = &_pHeader[(int)lRecNum];
+		HeaderRec *pRecInfo = &_pHeader[(int)lRecNum];
 
 		// Open the data file if it's not already open
 		if (_stream == nullptr) {
@@ -450,7 +450,7 @@ ErrorCode CBofDataFile::writeRecord(int32 lRecNum, void *pBuf, int32 lSize, bool
 		if (lSize == -1)
 			lSize = _pHeader[(int)lRecNum]._lLength;
 
-		int32 lPrevOffset = HEAD_INFO::size();
+		int32 lPrevOffset = HeadInfo::size();
 		int32 lPrevLength = 0;
 
 		if (lRecNum != 0) {
@@ -458,7 +458,7 @@ ErrorCode CBofDataFile::writeRecord(int32 lRecNum, void *pBuf, int32 lSize, bool
 			lPrevLength = _pHeader[(int)lRecNum - 1]._lLength;
 		}
 
-		HEADER_REC *pRecInfo = &_pHeader[(int)lRecNum];
+		HeaderRec *pRecInfo = &_pHeader[(int)lRecNum];
 
 		// Header needs to updated
 		_bHeaderDirty = true;
@@ -647,20 +647,25 @@ ErrorCode CBofDataFile::addRecord(void *pBuf, int32 lLength, bool bUpdateHeader,
 			if (_errCode == ERR_NONE) {
 				_lNumRecs++;
 
-				HEADER_REC *pTmpHeader = new HEADER_REC[(int)_lNumRecs];
+				HeaderRec *pTmpHeader = new HeaderRec[(int)_lNumRecs];
 				if (pTmpHeader == nullptr)
 					fatalError(ERR_MEMORY, "Could not allocate a data file header");
 
+				for (int i = 0; i < _lNumRecs; ++i) {
+					pTmpHeader[i]._lOffset = pTmpHeader[i]._lLength = 0;
+					pTmpHeader[i]._lCrc = pTmpHeader[i]._lKey = 0;
+				}
+
 				if (_pHeader != nullptr) {
-					memcpy(pTmpHeader, _pHeader, (size_t)(HEADER_REC::size() * (_lNumRecs - 1)));
+					memcpy(pTmpHeader, _pHeader, (size_t)(HeaderRec::size() * (_lNumRecs - 1)));
 					delete[] _pHeader;
 				}
 
 				_pHeader = pTmpHeader;
 
 				int32 lRecNum = _lNumRecs - 1;
-				HEADER_REC *pCurRec = &_pHeader[lRecNum];
-				int32 lPrevLength = HEAD_INFO::size();
+				HeaderRec *pCurRec = &_pHeader[lRecNum];
+				int32 lPrevLength = HeadInfo::size();
 				int32 lPrevOffset = 0;
 
 				if (lRecNum != 0) {
@@ -753,7 +758,7 @@ ErrorCode CBofDataFile::read(void *pDestBuf, int32 lBytes) {
 	return CBofFile::read(pDestBuf, lBytes);
 }
 
-ErrorCode CBofDataFile::read(HEAD_INFO &rec) {
+ErrorCode CBofDataFile::read(HeadInfo &rec) {
 	byte buf[16];
 	ErrorCode errorCode = read(&buf[0], 16);
 
@@ -764,7 +769,7 @@ ErrorCode CBofDataFile::read(HEAD_INFO &rec) {
 	return errorCode;
 }
 
-ErrorCode CBofDataFile::read(HEADER_REC &rec) {
+ErrorCode CBofDataFile::read(HeaderRec &rec) {
 	byte buf[16];
 	ErrorCode errorCode = read(&buf[0], 16);
 
@@ -779,7 +784,7 @@ ErrorCode CBofDataFile::write(const void *pSrcBuf, int32 lBytes) {
 	return CBofFile::write(pSrcBuf, lBytes);
 }
 
-ErrorCode CBofDataFile::write(HEAD_INFO &rec) {
+ErrorCode CBofDataFile::write(HeadInfo &rec) {
 	byte buf[16];
 
 	Common::MemoryWriteStream mem(buf, 16);
@@ -789,7 +794,7 @@ ErrorCode CBofDataFile::write(HEAD_INFO &rec) {
 	return write(&buf[0], 16);
 }
 
-ErrorCode CBofDataFile::write(HEADER_REC &rec) {
+ErrorCode CBofDataFile::write(HeaderRec &rec) {
 	byte buf[16];
 
 	Common::MemoryWriteStream mem(buf, 16);
@@ -813,7 +818,7 @@ uint32 CreateHashCode(const byte *pKey) {
 	return lCode;
 }
 
-void SwapHeadInfo(HEAD_INFO *stHI) {
+void SwapHeadInfo(HeadInfo *stHI) {
 	// Macintosh is big endian, so we must swap our bytes
 	stHI->_lNumRecs = SWAPLONG(stHI->_lNumRecs);
 	stHI->_lAddress = SWAPLONG(stHI->_lAddress);
@@ -821,8 +826,8 @@ void SwapHeadInfo(HEAD_INFO *stHI) {
 	stHI->_lFootCrc = SWAPLONG(stHI->_lFootCrc);
 }
 
-void SwapHeaderRec(HEADER_REC *stHR, int nRecords) {
-	HEADER_REC *p = stHR;
+void SwapHeaderRec(HeaderRec *stHR, int nRecords) {
+	HeaderRec *p = stHR;
 	for (int i = 0; i < nRecords; i++) {
 		p->_lOffset = SWAPLONG(p->_lOffset);
 		p->_lLength = SWAPLONG(p->_lLength);
diff --git a/engines/bagel/boflib/dat_file.h b/engines/bagel/boflib/dat_file.h
index b6a1933afa5..0492494c350 100644
--- a/engines/bagel/boflib/dat_file.h
+++ b/engines/bagel/boflib/dat_file.h
@@ -46,7 +46,7 @@ namespace Bagel {
 
 #define MAX_PW_LEN 32 // Max Password length
 
-struct HEADER_REC {
+struct HeaderRec {
 public:
 	int32 _lOffset;
 	int32 _lLength;
@@ -57,7 +57,7 @@ public:
 	static int size() { return 16; }
 };
 
-struct HEAD_INFO {
+struct HeadInfo {
 	int32 _lNumRecs;  // Number of records in this file
 	int32 _lAddress;  // starting address of footer
 	uint32 _lFlags;   // contains flags for this file
@@ -73,7 +73,7 @@ private:
 	int32 _lHeaderLength = 0;
 	int32 _lHeaderStart = 0;
 	int32 _lNumRecs = 0;
-	HEADER_REC *_pHeader = nullptr;
+	HeaderRec *_pHeader = nullptr;
 
 	bool _bHeaderDirty;
 
@@ -221,8 +221,8 @@ public:
 	 * @return              Error code
 	 */
 	ErrorCode read(void *pDestBuf, int32 lBytes);
-	ErrorCode read(HEADER_REC &rec);
-	ErrorCode read(HEAD_INFO &rec);
+	ErrorCode read(HeaderRec &rec);
+	ErrorCode read(HeadInfo &rec);
 
 	/**
 	 * Write to a currently open file
@@ -231,8 +231,8 @@ public:
 	 * @return              Error code
 	 */
 	ErrorCode write(const void *pSrcBuf, int32 lBytes);
-	ErrorCode write(HEADER_REC &rec);
-	ErrorCode write(HEAD_INFO &rec);
+	ErrorCode write(HeaderRec &rec);
+	ErrorCode write(HeadInfo &rec);
 };
 
 } // namespace Bagel


Commit: a3386d53e1542ac6f6917e1e46f0d0e30adabba1
    https://github.com/scummvm/scummvm/commit/a3386d53e1542ac6f6917e1e46f0d0e30adabba1
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2024-05-16T08:03:32+01:00

Commit Message:
BAGEL: Fix a potential allocation of negative size (CID 1544843)

Changed paths:
    engines/bagel/boflib/dat_file.cpp


diff --git a/engines/bagel/boflib/dat_file.cpp b/engines/bagel/boflib/dat_file.cpp
index c6a2ab4bb48..e6db4b7f022 100644
--- a/engines/bagel/boflib/dat_file.cpp
+++ b/engines/bagel/boflib/dat_file.cpp
@@ -557,10 +557,14 @@ ErrorCode CBofDataFile::writeRecord(int32 lRecNum, void *pBuf, int32 lSize, bool
 					// Remember it's length
 					pRecInfo->_lLength = lSize;
 
+					int bufferSize = getMaxRecSize();
+					if (bufferSize <= 0)
+						fatalError(ERR_FREAD, "Invalid size read in header data");
+
 					// Allocate a buffer that could hold the largest record
-					byte *pTmpBuf = (byte *)bofAlloc((int)getMaxRecSize());
+					byte *pTmpBuf = (byte *)bofAlloc(bufferSize);
 					if (pTmpBuf == nullptr)
-						fatalError(ERR_MEMORY, "unable to allocate a buffer of %ld bytes", getMaxRecSize());
+						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);




More information about the Scummvm-git-logs mailing list