Skip to content

Commit 46dbf3a

Browse files
committed
fix: replace printf/fprintf with serial_printf, fix SpeechManager NULL checks
Bare metal safety: - TrapDispatcher BadTrap: replace printf with serial_printf (printf routes to serial anyway but extern is cleaner for bare metal) - TrapDispatcher SysError: replace fprintf(stderr,...) with serial_printf - MenuBarManager InitMenuBar: replace printf with serial_puts SpeechManager hardening: - GetAudioOutputDeviceCapabilities: NULL-check all 3 output params before dereferencing (formats, formatCount, supportedFlags) - GetAudioStreamProperty: NULL-check valueSize before writing - GetSpeechRate/GetSpeechPitch: remove redundant NULL checks after already-validated parameter (dead code)
1 parent aebf166 commit 46dbf3a

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

src/MenuManager/MenuBarManager.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020
/* Menu bar management */
2121
void InitMenuBar(void) {
22-
printf("Initializing menu bar\n");
22+
extern void serial_puts(const char* str);
23+
serial_puts("Initializing menu bar\n");
2324
InitMenus();
2425
}
2526

src/SpeechManager/SpeechManagerCore.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,8 @@ OSErr GetSpeechRate(SpeechChannel chan, Fixed *rate) {
240240
}
241241
}
242242

243-
if (rate) {
244-
*rate = 0x00010000;
245-
}
246-
return noErr; // Stub
243+
*rate = 0x00010000; /* Fixed 1.0 = normal rate */
244+
return noErr;
247245
}
248246

249247
/*
@@ -281,10 +279,8 @@ OSErr GetSpeechPitch(SpeechChannel chan, Fixed *pitch) {
281279
}
282280
}
283281

284-
if (pitch) {
285-
*pitch = 0x00010000;
286-
}
287-
return noErr; // Stub
282+
*pitch = 0x00010000; /* Fixed 1.0 = normal pitch */
283+
return noErr;
288284
}
289285

290286
/*

src/SpeechManager/SpeechOutput_Stub.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,10 @@ OSErr GetAudioOutputVolume(Fixed *volume) {
335335

336336
OSErr GetAudioOutputDeviceCapabilities(const char *deviceID, AudioOutputFormat **formats,
337337
short *formatCount, AudioOutputFlags *supportedFlags) {
338+
(void)deviceID;
339+
if (formats) *formats = NULL;
338340
if (formatCount) *formatCount = 0;
341+
if (supportedFlags) *supportedFlags = 0;
339342
return noErr;
340343
}
341344

@@ -413,6 +416,8 @@ OSErr SetAudioStreamProperty(AudioOutputStream *stream, OSType property, const v
413416

414417
OSErr GetAudioStreamProperty(AudioOutputStream *stream, OSType property, void *value,
415418
long *valueSize) {
419+
(void)stream; (void)property; (void)value;
420+
if (valueSize) *valueSize = 0;
416421
return noErr;
417422
}
418423

src/TrapDispatcher.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,11 @@ FLineTrapHandler TrapDispatcher_SetFLineHandler(FLineTrapHandler handler) {
348348
*/
349349
SInt32 TrapDispatcher_BadTrap(TrapContext *context) {
350350
/* Save all registers in debugger space - this would be system-specific */
351-
printf("BadTrap: Unimplemented trap at PC=0x%08X, trap_word=0x%04X\n",
352-
context->pc - 2, *(UInt16*)(uintptr_t)(context->pc - 2));
351+
{
352+
extern void serial_printf(const char* fmt, ...);
353+
serial_printf("BadTrap: Unimplemented trap at PC=0x%08X, trap_word=0x%04X\n",
354+
context->pc - 2, *(UInt16*)(uintptr_t)(context->pc - 2));
355+
}
353356

354357
/* In original Mac OS, this would call SysError with DS_CORE_ERR */
355358
SysError(DS_CORE_ERR);
@@ -466,7 +469,8 @@ static SInt32 unimplemented_trap_handler(TrapContext *context) {
466469

467470
/* Weak symbol definitions for system functions that should be provided externally */
468471
__attribute__((weak)) void SysError(int error_code) {
469-
fprintf(stderr, "SYSTEM ERROR %d: Unimplemented trap or critical failure\n", error_code);
472+
extern void serial_printf(const char* fmt, ...);
473+
serial_printf("SYSTEM ERROR %d: Unimplemented trap or critical failure\n", error_code);
470474
abort();
471475
}
472476

0 commit comments

Comments
 (0)