From 156be3ad53461aaf556c8f62543ff36b877509e7 Mon Sep 17 00:00:00 2001 From: rfm Date: Tue, 29 Oct 2024 14:59:43 +0000 Subject: [PATCH] safety fix in case code incorrectly tries to use the reuslt of forwarding a method to the undo manager. --- ChangeLog | 6 ++++++ Source/NSUndoManager.m | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/ChangeLog b/ChangeLog index 2e58f2885..7ec6b9fac 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,10 @@ +2024-10-29 Richard Frith-Macdonald + + * Source/NSUndoManager.m: set zero/nil return value when forwarding + invocation ... in case calling code tries to use the result. + 2024-10-28 Hugo Melder + * Source/NSString.m: -commonPrefixWithString:options: returns nil when string supplied as first argument is nil. On macOS, the empty string is returned instead. diff --git a/Source/NSUndoManager.m b/Source/NSUndoManager.m index e22de8c11..f0f5f14e0 100644 --- a/Source/NSUndoManager.m +++ b/Source/NSUndoManager.m @@ -429,6 +429,11 @@ - (void) endUndoGrouping */ - (void) forwardInvocation: (NSInvocation*)anInvocation { + NSUInteger size = [[anInvocation methodSignature] methodReturnLength]; + unsigned char v[size]; + + memset(v, '\0', size); + if (_disableCount == 0) { if (_nextTarget == nil) @@ -466,6 +471,8 @@ - (void) forwardInvocation: (NSInvocation*)anInvocation _runLoopGroupingPending = YES; } } + + [anInvocation setReturnValue: (void*)v]; } /**