vjeantet / alerter

Send User Alert Notification on Mac OS X from the command-line.
MIT License
936 stars 62 forks source link

Throws exception when using -actions ... without -closeLabel #12

Open vanHoesel opened 6 years ago

vanHoesel commented 6 years ago

This works fine: alerter -message "Choose pill" -actions "Blue","Red" -dropdownLabel "Colour" -closeLabel "No Thanks" -json

but the moment you do not pass -closeLabel (with the label string), then only the 'dropdown' button appears and when you click on it, you get a complete stack trace plus Abort trap: 6

nicolasff commented 1 year ago

This still occurs in the latest version (1.0.1), I found this GitHub issue looking for a previous report of this bug. The stack trace wasn't reported by the originator, so I'm adding it here.

Note that even if -closeLabel is passed, clicking on the -dropdownLabel option ("Colour" in the example) still leads to a crash. The same happens if -dropdownLabel is omitted and the "Show" option is selected, basically any click on the drop-down label causes a crash whether it's been re-titled or not.

Command:

alerter -message "Choose pill" -actions "Blue","Red" -dropdownLabel "Colour"

Selecting "Blue" or "Red" from the drop-down makes alerter print that color as it exits. Selecting "Colour" terminates the program with a non-zero return code and prints:

alerter[30392:247506236] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndexedSubscript:]: index 9223372036854775807 beyond bounds [0 .. 1]'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007ff81039a18a __exceptionPreprocess + 242
    1   libobjc.A.dylib                     0x00007ff80fec042b objc_exception_throw + 48
    2   CoreFoundation                      0x00007ff8104743ca -[__NSCFString characterAtIndex:].cold.1 + 0
    3   CoreFoundation                      0x00007ff810310c6e +[NSNull null] + 0
    4   alerter                             0x000000010237c83e -[AppDelegate userNotificationCenter:didActivateNotification:] + 540
    5   Foundation                          0x00007ff811248f4e -[_NSConcreteUserNotificationCenter _sendDelegateMessage:sendToAppDelegate:withObject:] + 118
    6   Foundation                          0x00007ff8117e8962 -[_NSConcreteUserNotificationCenter _notificationClickedMessage:] + 460
    7   Foundation                          0x00007ff811200411 __54-[_NSConcreteUserNotificationCenter _serverConnection]_block_invoke_4 + 49
    8   libdispatch.dylib                   0x00007ff8100a4d91 _dispatch_call_block_and_release + 12
    9   libdispatch.dylib                   0x00007ff8100a6033 _dispatch_client_callout + 8
    10  libdispatch.dylib                   0x00007ff8100b2fcf _dispatch_main_queue_drain + 954
    11  libdispatch.dylib                   0x00007ff8100b2c07 _dispatch_main_queue_callback_4CF + 31
    12  CoreFoundation                      0x00007ff810362205 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    13  CoreFoundation                      0x00007ff810321f2f __CFRunLoopRun + 2452
    14  CoreFoundation                      0x00007ff810320f31 CFRunLoopRunSpecific + 560
    15  HIToolbox                           0x00007ff819da1f3d RunCurrentEventLoopInMode + 292
    16  HIToolbox                           0x00007ff819da1d4e ReceiveNextEventCommon + 657
    17  HIToolbox                           0x00007ff819da1aa8 _BlockUntilNextEventMatchingListInModeWithFilter + 64
    18  AppKit                              0x00007ff8133bd25c _DPSNextEvent + 858
    19  AppKit                              0x00007ff8133bc106 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1214
    20  AppKit                              0x00007ff8133ae788 -[NSApplication run] + 586
    21  alerter                             0x000000010237d93d main + 147
    22  dyld                                0x00007ff80feed41f start + 1903
)
libc++abi: terminating due to uncaught exception of type NSException
[1]    30392 abort      alerter -message "Choose pill" -actions "Blue","Red" -dropdownLabel "Colour"

The index being accessed at the time of the crash is reported to be 9223372036854775807, which is $2^{63}-1$.

The issue might be in this code: https://github.com/vjeantet/alerter/blob/0a654d1e38b7aeb94242757a84354b111dd1f6cf/alerter/AppDelegate.m#L462-L466