Skip to content

MADS: Fix some unaligned accesses in quote handling code - #7977

Merged
dreammaster merged 1 commit into
scummvm:masterfrom
dwatteau:fix/mads-nebular-strict-alignment-fixes
Oct 10, 2026
Merged

dreammaster merged 1 commit into
scummvm:masterfrom
dwatteau:fix/mads-nebular-strict-alignment-fixes

Conversation

@dwatteau

@dwatteau dwatteau commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

I have an old MIPS device, where unaligned accesses cause a plain crash with a SIGBUS.

Some of them happen with Rex Nebular, when trying to play the first scene, or when using the quotes command in the debugger.

(Playing a build with --enable-ubsan also triggers the issue on a regular x86/aarch64 desktop).

The following diff fixes this.

OK?

(also: it's not part of the PR, but the following change could provide a guarantee that no similar unaligned access is done in font_write(). But I'm not experiencing any crash there yet, maybe it's always at an aligned place, in practice.)

diff --git a/engines/mads/core/font.cpp b/engines/mads/core/font.cpp
index 549e2179e43..8d00115bc2f 100644
--- a/engines/mads/core/font.cpp
+++ b/engines/mads/core/font.cpp
@@ -130,7 +130,7 @@ int font_write(FontPtr font, Buffer *target, const char *out_string,
 	if (strlen(out_string) == 0)
 		return x;
 
-	*(uint32 *)&colors[0] = *(uint32 *)&font_colors[0];
+	memcpy(colors, font_colors, sizeof(colors));
 
 	Common::strcpy_s(temp_buf, out_string);
 

)

SIGBUSes would happen on mips64el when starting Rex Nebular, or when
using the 'quotes' command in the debugger.

Also reported by UBSan in standard builds.
@dreammaster
dreammaster merged commit 4b6c65c into scummvm:master Oct 10, 2026
@dreammaster

Copy link
Copy Markdown
Member

Looks good. I'm merging this in now. And I'll apply the suggested font fix.

@dwatteau
dwatteau deleted the fix/mads-nebular-strict-alignment-fixes branch October 10, 2026 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants