donato-fiore/calculatorhistory

NSInvalidArgumentException when dividing

Opened this issue · 1 comments

Thanks for this very useful tweak! I'd like to report a crash on iOS 15.8. Phone locale set to use "," as decimal separator.

Steps to reproduce: 25 ÷ 4 =

Stack trace

Application Specific Information:
abort() called
dyld4 config: DYLD_INSERT_LIBRARIES=/usr/lib/systemhook.dylib
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString replaceCharactersInRange:withString:]: nil argument'
terminating with uncaught exception of type NSException

Last Exception Backtrace:
0 CoreFoundation 0x18190fc60 __exceptionPreprocess + 216
1 libobjc.A.dylib 0x19913fee4 objc_exception_throw + 55
2 CoreFoundation 0x181a0a694 CFThrowFormattedException + 111
3 CoreFoundation 0x1819ac304 mutateError + 199
4 CoreFoundation 0x1818b6ae4 -[__NSCFString replaceCharactersInRange:withString:] + 67
5 CalculatorHistory.dylib 0x10300430c hooked_CalculatePerformExpression + 696
6 Calculator 0x102b942e0 calculatorEvaluateExpression + 184
7 Calculator 0x102bcf28c specialized calculatorEvaluateOperator(
:leftOperand:rightOperand:) + 780
8 Calculator 0x102baf564 CalculatorModel.equalsButtonPressed() + 1136
9 Calculator 0x102bab5e4 @objc CalculatorModel.buttonPressed(:) + 40
10 Calculator 0x102b9a6cc CalculatorController.touchUp(
:button:) + 64
11 Calculator 0x102b9a828 protocol witness for CalculatorKeypadViewDelegate.touchUp(:button:) in conformance CalculatorController + 44
12 Calculator 0x102bc7f64 specialized CalculatorKeypadView.touchesEnded(
:with:) + 264
13 Calculator 0x102bc4524 @objc CalculatorKeypadView.touchesBegan(_:with:) + 140
14 UIKitCore 0x183d9899c forwardTouchMethod + 315
15 UIKitCore 0x183d1a12c -[UIWindow _sendTouchesForEvent:] + 1227
16 UIKitCore 0x183d49c4c -[UIWindow sendEvent:] + 4371
17 UIKitCore 0x183eeaa64 -[UIApplication sendEvent:] + 891
18 UIKitCore 0x183d1ec2c __dispatchPreprocessedEventFromEventQueue + 8147
19 UIKitCore 0x183d13af0 __processEventQueue + 6543
20 UIKitCore 0x183d18f0c __eventFetcherSourceCallback + 167
21 CoreFoundation 0x181930448 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 23
22 CoreFoundation 0x181940578 __CFRunLoopDoSource0 + 203
23 CoreFoundation 0x181882734 __CFRunLoopDoSources0 + 255
24 CoreFoundation 0x181887e08 __CFRunLoopRun + 767
25 CoreFoundation 0x18189b174 CFRunLoopRunSpecific + 571
26 GraphicsServices 0x1a23da988 GSEventRunModal + 159
27 UIKitCore 0x18409da88 -[UIApplication _run] + 1079
28 UIKitCore 0x183e36f78 UIApplicationMain + 335
29 Calculator 0x102b94588 main + 176
30 dyld 0x102d0c4d0 start + 444

Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x1bc1f3bbc __pthread_kill + 8
1 libsystem_pthread.dylib 0x1dcc94844 pthread_kill + 207
2 libsystem_c.dylib 0x18bffc6ac abort + 123
3 libc++abi.dylib 0x199237de4 abort_message + 127
4 libc++abi.dylib 0x199228684 demangling_terminate_handler() + 299
5 libobjc.A.dylib 0x1991458f8 _objc_terminate() + 123
6 libc++abi.dylib 0x199237280 std::__terminate(void (*)()) + 15
7 libc++abi.dylib 0x199239e1c __cxa_rethrow + 143
8 libobjc.A.dylib 0x1991419c8 objc_exception_rethrow + 39
9 CoreFoundation 0x18189b260 CFRunLoopRunSpecific + 807
10 GraphicsServices 0x1a23da988 GSEventRunModal + 159
11 UIKitCore 0x18409da88 -[UIApplication _run] + 1079
12 UIKitCore 0x183e36f78 UIApplicationMain + 335
13 Calculator 0x102b94588 main + 176
14 dyld 0x102d0c4d0 start + 444

Thread 1 name: Dispatch queue: ellekit_exc_port
Thread 1:
0 libsystem_kernel.dylib 0x1bc1edaac mach_msg_trap + 8
1 libsystem_kernel.dylib 0x1bc1ee07c mach_msg + 71
2 libellekit.dylib 0x102fb48cc static ExceptionHandler.portLoop(:) + 144
3 libellekit.dylib 0x102fb4dac $defer #2 () in static ExceptionHandler.portLoop(
:) + 136
4 libellekit.dylib 0x102fb4a58 static ExceptionHandler.portLoop(:) + 540
5 libellekit.dylib 0x102fb4dac $defer #2 () in static ExceptionHandler.portLoop(
:) + 136
6 libellekit.dylib 0x102fb4a58 static ExceptionHandler.portLoop(:) + 540
7 libellekit.dylib 0x102fb4dac $defer #2 () in static ExceptionHandler.portLoop(
:) + 136
8 libellekit.dylib 0x102fb4a58 static ExceptionHandler.portLoop(:) + 540
9 libellekit.dylib 0x102fb4dac $defer #2 () in static ExceptionHandler.portLoop(
:) + 136
10 libellekit.dylib 0x102fb4a58 static ExceptionHandler.portLoop(_:) + 540
11 libellekit.dylib 0x102fb47f8 closure #1 in ExceptionHandler.startPortLoop() + 60
12 libellekit.dylib 0x102fb4c68 thunk for @escaping @callee_guaranteed @Sendable () -> () + 28
13 libdispatch.dylib 0x1815cf094 _dispatch_call_block_and_release + 23
14 libdispatch.dylib 0x1815d0094 _dispatch_client_callout + 15
15 libdispatch.dylib 0x181572bb8 _dispatch_continuation_pop$VARIANT$mp + 439
16 libdispatch.dylib 0x1815722e0 _dispatch_async_redirect_invoke + 587
17 libdispatch.dylib 0x18157fb94 _dispatch_root_queue_drain + 339
18 libdispatch.dylib 0x18158039c _dispatch_worker_thread2 + 171
19 libsystem_pthread.dylib 0x1dcc88dc4 _pthread_wqthread + 223
20 libsystem_pthread.dylib 0x1dcc8892c start_wqthread + 7

Thread 2:
0 libsystem_pthread.dylib 0x1dcc88924 start_wqthread + 0

Thread 3:
0 libsystem_pthread.dylib 0x1dcc88924 start_wqthread + 0

Thread 4 name: com.apple.uikit.eventfetch-thread
Thread 4:
0 libsystem_kernel.dylib 0x1bc1edaac mach_msg_trap + 8
1 libsystem_kernel.dylib 0x1bc1ee07c mach_msg + 71
2 CoreFoundation 0x181883c88 __CFRunLoopServiceMachPort + 367
3 CoreFoundation 0x181887f90 __CFRunLoopRun + 1159
4 CoreFoundation 0x18189b174 CFRunLoopRunSpecific + 571
5 Foundation 0x182fa7eac -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 231
6 Foundation 0x182fe6fd0 -[NSRunLoop(NSRunLoop) runUntilDate:] + 87
7 UIKitCore 0x18401cef4 -[UIEventFetcher threadMain] + 511
8 Foundation 0x182ff4bdc NSThread__start + 791
9 libsystem_pthread.dylib 0x1dcc8a338 _pthread_start + 115
10 libsystem_pthread.dylib 0x1dcc88938 thread_start + 7

Thread 5:
0 libsystem_pthread.dylib 0x1dcc88924 start_wqthread + 0

Filtered syslog

2024-10-22 09:09:15.4715 +0200 default 0x40b483 0x0 Calculator[75098] (UIKitCore): Sending UIEvent type: 0; subtype: 0; to windows: 1
2024-10-22 09:09:15.4715 +0200 default 0x40b483 0x0 Calculator[75098] (UIKitCore): Sending UIEvent type: 0; subtype: 0; to window: <Calculator.CalculatorWindow: 0x141d33db0>; contextId: 0x558988FA
2024-10-22 09:09:15.5042 +0200 default 0x40b483 0x0 Calculator[75098] (UIKitCore): Evaluating dispatch of UIEvent: 0x280259980; type: 0; subtype: 0; backing type: 11; shouldSend: 1; ignoreInteractionEvents: 0, systemGestureStateChange: 0
2024-10-22 09:09:15.5043 +0200 default 0x40b483 0x0 Calculator[75098] (UIKitCore): Sending UIEvent type: 0; subtype: 0; to windows: 1
2024-10-22 09:09:15.5043 +0200 default 0x40b483 0x0 Calculator[75098] (UIKitCore): Sending UIEvent type: 0; subtype: 0; to window: <Calculator.CalculatorWindow: 0x141d33db0>; contextId: 0x558988FA
2024-10-22 09:09:15.5069 +0200 info 0x40b483 0x0 Calculator[75098] (Calculate): CalculateExpressionError: (21)/(4)
2024-10-22 09:09:15.5069 +0200 info 0x40b483 0x0 Calculator[75098] (Calculate): CalculateExpressionError cleaned expression: (21)/(4)
2024-10-22 09:09:15.5107 +0200 info 0x40b483 0x0 Calculator[75098] (Calculate): CalculateExpressionError ret = 0
2024-10-22 09:09:15.5107 +0200 info 0x40b483 0x0 Calculator[75098] (Calculate): CalculateExpressionError result = 5.25
2024-10-22 09:09:15.5234 +0200 default 0x40b483 0x0 Calculator[75098] (CoreFoundation): *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString replaceCharactersInRange:withString:]: nil argument'...

EOF

Various other calculations will cause crashes, maybe all the ones that result in a decimal number.

This issue should be fixed in the latest commit. Please respond to this thread if the issue persists.