diff --git a/src/header/string/mod.rs b/src/header/string/mod.rs index 1bec129c0e284205de659e421302a22b4fa3b7a1..f19e201d8bc13eceeb709024ea8b8efc093f876a 100644 --- a/src/header/string/mod.rs +++ b/src/header/string/mod.rs @@ -366,7 +366,9 @@ pub unsafe extern "C" fn strrchr(s: *const c_char, c: c_int) -> *mut c_char { #[no_mangle] pub unsafe extern "C" fn strsignal(sig: c_int) -> *const c_char { - signal::_signal_strings[sig as usize].as_ptr() as *const c_char + signal::_signal_strings.get(sig as usize).unwrap_or( + &signal::_signal_strings[0] // Unknown signal message + ).as_ptr() as *const c_char } #[no_mangle] diff --git a/tests/Makefile b/tests/Makefile index d4e0e9a40bf8f85f9410b4769ee5e76e0c928c03..31421c63ce33d088b08effd36d4dbf33e06d91f4 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -61,6 +61,7 @@ EXPECT_NAMES=\ string/strstr \ string/strtok \ string/strtok_r \ + string/strsignal \ strings \ sys_epoll/epoll \ time/asctime \ diff --git a/tests/expected/string/strsignal.stderr b/tests/expected/string/strsignal.stderr new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/expected/string/strsignal.stdout b/tests/expected/string/strsignal.stdout new file mode 100644 index 0000000000000000000000000000000000000000..833dc63089f8b334fb8a8a44240a95b46f0ee313 --- /dev/null +++ b/tests/expected/string/strsignal.stdout @@ -0,0 +1 @@ +# strsignal # diff --git a/tests/string/strsignal.c b/tests/string/strsignal.c new file mode 100644 index 0000000000000000000000000000000000000000..1ddf08630da4b306f7b3feab13e8e8056ea18848 --- /dev/null +++ b/tests/string/strsignal.c @@ -0,0 +1,28 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <signal.h> + +#include "test_helpers.h" + +int main(void) { + puts("# strsignal #"); + char *x = strsignal(SIGHUP); + int res; + if (strcmp(x, "Hangup")) { + printf("Incorrect strsignal (1), found: .%s.\n", x); + exit(EXIT_FAILURE); + } + x = strsignal(0); + if (strcmp(x, "Unknown signal")) { + printf("Incorrect strsignal (2), found: .%s.\n", x); + exit(EXIT_FAILURE); + } + x = strsignal(100); + if (strcmp(x, "Unknown signal")) { + printf("Incorrect strsignal (3), found: .%s.\n", x); + exit(EXIT_FAILURE); + } + + +}