[Scummvm-git-logs] scummvm master -> d06bcf29c5a8b7853db1c40e912e6637fba3c5f3
bluegr
noreply at scummvm.org
Wed Oct 30 12:01:36 UTC 2024
This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
39f0c165c3 M4: Avoid unaligned memory access in the memory stash code
d06bcf29c5 M4: Avoid unaligned memory access in the font loader
Commit: 39f0c165c30118919ba082372acdd18ea72f2b3d
https://github.com/scummvm/scummvm/commit/39f0c165c30118919ba082372acdd18ea72f2b3d
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2024-10-30T14:01:32+02:00
Commit Message:
M4: Avoid unaligned memory access in the memory stash code
Changed paths:
engines/m4/mem/mem.cpp
diff --git a/engines/m4/mem/mem.cpp b/engines/m4/mem/mem.cpp
index ea68f89c00d..cca1fa6c14a 100644
--- a/engines/m4/mem/mem.cpp
+++ b/engines/m4/mem/mem.cpp
@@ -67,8 +67,8 @@ bool mem_register_stash_type(int32 *memType, int32 blockSize, int32 maxNumReques
_G(requests)[i] = maxNumRequests;
- _G(memBlock)[i] = mem_alloc((blockSize + 1) * maxNumRequests, name.c_str());
- memset(_G(memBlock)[i], 0, (blockSize + 1) * maxNumRequests);
+ _G(memBlock)[i] = mem_alloc((blockSize + sizeof(uintptr)) * maxNumRequests, name.c_str());
+ memset(_G(memBlock)[i], 0, (blockSize + sizeof(uintptr)) * maxNumRequests);
return true;
}
@@ -80,12 +80,12 @@ bool mem_register_stash_type(int32 *memType, int32 blockSize, int32 maxNumReques
void mem_free_to_stash(void *mem, int32 memType) {
// _G(memBlock)[memType] is block associated with memType
int8 *b_ptr = (int8 *)_G(memBlock)[memType];
- int32 index = ((intptr)mem - (intptr)_G(memBlock)[memType]) / (_G(sizeMem)[memType] + 1);
+ int32 index = ((intptr)mem - (intptr)_G(memBlock)[memType]) / (_G(sizeMem)[memType] + sizeof(uintptr));
if (index < 0 || index > _G(requests)[memType])
error_show(FL, 'MSGF');
- b_ptr += index * (_G(sizeMem)[memType] + 1);
+ b_ptr += index * (_G(sizeMem)[memType] + sizeof(uintptr));
*b_ptr = 0;
}
@@ -95,13 +95,13 @@ void *mem_get_from_stash(int32 memType, const Common::String &name) {
for (i = 0; i < _G(requests)[memType]; i++) {
if (!*b_ptr) {
- *b_ptr = 1;
- void *result = (void *)(b_ptr + 1);
+ *(uintptr *)b_ptr = 1;
+ void *result = (void *)(b_ptr + sizeof(uintptr));
Common::fill((byte *)result, (byte *)result + _G(sizeMem)[memType], 0);
return result;
} else {
- b_ptr += _G(sizeMem)[memType] + 1;
+ b_ptr += _G(sizeMem)[memType] + sizeof(uintptr);
}
}
Commit: d06bcf29c5a8b7853db1c40e912e6637fba3c5f3
https://github.com/scummvm/scummvm/commit/d06bcf29c5a8b7853db1c40e912e6637fba3c5f3
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2024-10-30T14:01:32+02:00
Commit Message:
M4: Avoid unaligned memory access in the font loader
Changed paths:
engines/m4/fileio/sys_file.cpp
engines/m4/fileio/sys_file.h
engines/m4/graphics/gr_font.cpp
diff --git a/engines/m4/fileio/sys_file.cpp b/engines/m4/fileio/sys_file.cpp
index 3b86df021f7..3cf0d7fbb9b 100644
--- a/engines/m4/fileio/sys_file.cpp
+++ b/engines/m4/fileio/sys_file.cpp
@@ -631,6 +631,14 @@ int32 SysFile::read(MemHandle bufferHandle, int32 n) {
}
}
+byte SysFile::readByte() {
+ byte buf[1];
+ void *ptr = (void *)buf;
+ read(&ptr, 1);
+
+ return buf[0];
+}
+
uint32 SysFile::readUint32LE() {
byte buf[4];
void *ptr = (void *)buf;
diff --git a/engines/m4/fileio/sys_file.h b/engines/m4/fileio/sys_file.h
index 4b843b5e8d8..9366c8ba2bc 100644
--- a/engines/m4/fileio/sys_file.h
+++ b/engines/m4/fileio/sys_file.h
@@ -123,6 +123,14 @@ public:
uint32 read(MemHandle bufferHandle);
int32 read(MemHandle bufferHandle, int32 n);
+ /**
+ * Read in a 8-bit value
+ */
+ byte readByte();
+ int8 readSByte() {
+ return (int8)readByte();
+ }
+
/**
* Read in a 32-bit value
*/
diff --git a/engines/m4/graphics/gr_font.cpp b/engines/m4/graphics/gr_font.cpp
index 069dbb37984..614fbae4e69 100644
--- a/engines/m4/graphics/gr_font.cpp
+++ b/engines/m4/graphics/gr_font.cpp
@@ -356,21 +356,15 @@ int32 gr_font_write(Buffer *target, const char *out_string, int32 x, int32 y, in
}
Font *gr_font_load(const char *fontName) {
- uint8 buffer[10];
uint32 tag;
- uint32 *bumpf;
Font *newFont;
- void *bufferHandle = &buffer[0];
+ void *bufferHandle;
SysFile fontFile(fontName, BINARY);
if (!fontFile.exists())
return nullptr;
- bufferHandle = &buffer[0];
- fontFile.read(&bufferHandle, 10);
-
- bumpf = (uint32 *)&buffer[0];
- tag = convert_intel32(*bumpf);
+ tag = fontFile.readUint32LE();
if (tag != 'FONT')
error_show(FL, 'FNTL', "font: %s chkpnt: %d", (const char *)fontName, 0);
@@ -378,16 +372,12 @@ Font *gr_font_load(const char *fontName) {
if (!newFont)
error_show(FL, 'OOM!', "_G(font) struct");
- newFont->max_y_size = buffer[4];
- newFont->max_x_size = buffer[5];
- newFont->dataSize = *((uint32 *)&buffer[6]);
- newFont->dataSize = convert_intel32(newFont->dataSize);
+ newFont->max_y_size = fontFile.readByte();
+ newFont->max_x_size = fontFile.readByte();
+ newFont->dataSize = fontFile.readUint32LE();
// read 'WIDT' into tag
- bufferHandle = &buffer[0];
- fontFile.read(&bufferHandle, 4);
- bumpf = (uint32 *)&buffer[0];
- tag = convert_intel32(*bumpf);
+ tag = fontFile.readUint32LE();
if (tag != 'WIDT')
error_show(FL, 'FNTL', "font: %s chkpnt: %d", fontName, 1);
@@ -400,10 +390,7 @@ Font *gr_font_load(const char *fontName) {
fontFile.read(&bufferHandle, 256);
// read 'OFFS' into tag
- bufferHandle = &buffer[0];
- fontFile.read(&bufferHandle, 4);
- bumpf = (uint32 *)&buffer[0];
- tag = convert_intel32(*bumpf);
+ tag = fontFile.readUint32LE();
if (tag != 'OFFS')
error_show(FL, 'FNTL', "font: %s chkpnt: %d", fontName, 2);
@@ -419,10 +406,7 @@ Font *gr_font_load(const char *fontName) {
newFont->offset[i] = convert_intel16(newFont->offset[i]);
// read 'PIXS' into tag
- bufferHandle = &buffer[0];
- fontFile.read(&bufferHandle, 4);
- bumpf = (uint32 *)&buffer[0];
- tag = convert_intel32(*bumpf);
+ tag = fontFile.readUint32LE();
if (tag != 'PIXS')
error_show(FL, 'FNTL', "font: %s chkpnt: %d", fontName, 3);
More information about the Scummvm-git-logs
mailing list