Skip to content

Commit ba87297

Browse files
committed
selftests:timers: posix_timers: Fix warn_unused_result in __fatal_error()
__fatal_error routine doesn't check strerror_r() return value, which results in the following compile time warning: posix_timers.c: In function ‘__fatal_error’: posix_timers.c:31:9: warning: ignoring return value of ‘strerror_r’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 31 | strerror_r(errno, buf, sizeof(buf)); Fix this by adding a check for return value and error handling appropriate for the GNU-specific strerror_r() in use in __fatal_error(). Check if return string is null and handle accordingly. From Linux strerror_r() manual page: "The GNU-specific strerror_r() returns a pointer to a string containing the error message. This may be either a pointer to a string that the function stores in buf, or a pointer to some (immutable) static string (in which case buf is unused). If the function stores a string in buf, then at most buflen bytes are stored (the string may be truncated if buflen is too small and errnum is unknown). The string always includes a terminating null byte." Signed-off-by: Shuah Khan <skhan@linuxfoundation.org> Acked-by: John Stultz <jstultz@google.com> Acked-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent 1ad9998 commit ba87297

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

tools/testing/selftests/timers/posix_timers.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@
2626
static void __fatal_error(const char *test, const char *name, const char *what)
2727
{
2828
char buf[64];
29+
char *ret_str = NULL;
2930

30-
strerror_r(errno, buf, sizeof(buf));
31+
ret_str = strerror_r(errno, buf, sizeof(buf));
3132

32-
if (name && strlen(name))
33-
ksft_exit_fail_msg("%s %s %s %s\n", test, name, what, buf);
33+
if (name && strlen(name) && ret_str)
34+
ksft_exit_fail_msg("%s %s %s %s\n", test, name, what, ret_str);
35+
else if (ret_str)
36+
ksft_exit_fail_msg("%s %s %s\n", test, what, ret_str);
3437
else
35-
ksft_exit_fail_msg("%s %s %s\n", test, what, buf);
38+
ksft_exit_fail_msg("%s %s\n", test, what);
39+
3640
}
3741

3842
#define fatal_error(name, what) __fatal_error(__func__, name, what)

0 commit comments

Comments
 (0)