Repository navigation
Description
Description
Hello,
PR incoming ... EDIT: #1946
I've been working on fixing espanso (when installed via nix on aarch64-darwin) for nearly a year now: NixOS/nixpkgs#247162 (although I only opened the issue about 8 months ago).
I use rust but don't have a background in objective C or C++, so the issue has taken a long time for me to sort out, but I think I finally have it figured out:
the signature for the function in question suggests a void * return value but the function body lacks a return statement: https://github.com/espanso/espanso/blob/dev/espanso-detect/src/mac/native.mm
In both C++ and objective C this should result in the warning:
warning: non-void function does not return a value [-Wreturn-type]
For whatever reason it still successfully compiles and runs natively on aarch64-darwin (with cargo build) and doesn't even result in any compilation errors, but from what I can tell, because a void * function is not the same as a void function, this results in undefined behavior: https://stackoverflow.com/questions/1610030/why-does-flowing-off-the-end-of-a-non-void-function-without-returning-a-value-no
When espanso is built with nixpkgs on aarch64-darwin (which uses clang by default), this results in espanso daemon failing and a Trace/BPT trap: 5 error (please see my issue above).
If one simply adds return NULL;, to this specific function (espanso-detect/src/mac/native.mm:detect_initialize) espanso builds and runs as expected.
I don't know why cc-rs doesn't seem to show any version of this warning in its build logs: warning: non-void function does not return a value [-Wreturn-type] -- when I make a toy void * function and omit a return, I get a warning when compiling with clang and an error / refuses to compile at all in xcode.
I have a one-line PR ready to fix this specific function, but I'd like to expand it to also include some kind of warning or compile error which should help point me to any other instances of this problem in the codebase so I can fix those as well.
Also, I do not know why espanso compiled natively with cargo works without this error; perhaps it's using a different C standard than nix? Again, I apologize for now knowing much about c-based languages, and I appreciate any input others can offer.
Steps to reproduce
$ nix run github:nixos/nixpkgs#espanso -- daemon
09:37:07 [daemon(84858)] [INFO] reading configs from: "/Users/n8henrie/.config/espanso"
09:37:07 [daemon(84858)] [INFO] reading packages from: "/Users/n8henrie/.config/espanso/match/packages"
09:37:07 [daemon(84858)] [INFO] using runtime dir: "/Users/n8henrie/Library/Caches/espanso"
09:37:07 [daemon(84858)] [INFO] system info: Darwin v14.4.1 - kernel: 23.4.0
09:37:07 [daemon(84858)] [INFO] watching for changes in path: "/Users/n8henrie/.config/espanso"
09:37:07 [daemon(84858)] [INFO] espanso version: 2.1.8
09:37:07 [daemon(84858)] [INFO] spawning the worker process...
09:37:07 [daemon(84858)] [INFO] binded to IPC unix socket: /Users/n8henrie/Library/Caches/espanso/espansodaemonv2.sock
09:37:07 [worker(84885)] [INFO] reading configs from: "/Users/n8henrie/.config/espanso"
09:37:07 [worker(84885)] [INFO] reading packages from: "/Users/n8henrie/.config/espanso/match/packages"
09:37:07 [worker(84885)] [INFO] using runtime dir: "/Users/n8henrie/Library/Caches/espanso"
09:37:07 [worker(84885)] [INFO] system info: Darwin v14.4.1 - kernel: 23.4.0
09:37:08 [worker(84885)] [INFO] binded to IPC unix socket: /Users/n8henrie/Library/Caches/espanso/espansoworkerv2.sock
09:37:08 [worker(84885)] [INFO] using CocoaAppInfoProvider
09:37:08 [worker(84885)] [INFO] monitoring the status of secure input
09:37:08 [worker(84885)] [INFO] monitoring the status of the daemon process
09:37:08 [worker(84885)] [INFO] using CocoaSource
09:37:08 [daemon(84858)] [ERROR] received unexpected exit code from worker 90, exitingIn contrast, with this PR, espanso runs and functions as expected.
Expected behavior
A non-void function should have a return; for a void * function, it should return NULL; at the end. This should avoid the possibility of UB, make the espanso codebase more correct, and as a happy result should finally fix this longstanding issue for nix + aarch64-darwin + espanso users .
Screenshots
No response
Logs
No response
Your environment
- Public source code: ?
- Environment name and version (e.g., Rust 1.59.0): rustc 1.77.1, nixpkgs-unstable
- Operating system and version (e.g., Ubuntu 20.04.2 LTS): MacOS 14.4.1
- Espanso version (e.g., 2.1.4-beta): current
devat 4c36a0e
Self-service
- I'd be willing to fix this bug myself.
Activity
Fix non-void function missing a return
Fix non-void function missing a return
Pre release (#2124)
Fix non-void function missing a return (espanso#1946)