From ace14a9b7d713bf5f413abd257829cb6fb1c027b Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 5 May 2019 01:33:26 +0200 Subject: proto/libevdev: fix error handling code harder Issue: #944 --- proto-libevdev/ftnoir_protocol_libevdev.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/proto-libevdev/ftnoir_protocol_libevdev.cpp b/proto-libevdev/ftnoir_protocol_libevdev.cpp index 27b73f2d..612f5b27 100644 --- a/proto-libevdev/ftnoir_protocol_libevdev.cpp +++ b/proto-libevdev/ftnoir_protocol_libevdev.cpp @@ -1,3 +1,8 @@ +// strerror_r(3) +#ifndef _POSIX_C_SOURCE +# define _POSIX_C_SOURCE 200112L +#endif + #include "ftnoir_protocol_libevdev.h" #include "api/plugin-api.hpp" #include "compat/math.hpp" @@ -120,10 +125,17 @@ module_status evdev::initialize() { if (error_code) { + const char* msg; char buf[128] {}; - (void)strerror_r(error_code, buf, sizeof(buf)); - return error(QStringLiteral("libevdev call '%1' failed with error '%2' (%3)") - .arg(!error_expr ? "" : error_expr, buf).arg(error_code)); + + if (!(msg = strerror_r(error_code, buf, sizeof(buf)))) + { + snprintf(buf, sizeof(buf), "%d", error_code); + msg = buf; + } + + return error(QStringLiteral("libevdev call '%1' failed with error '%2'") + .arg(!error_expr ? "" : error_expr, msg)); } else return {}; -- cgit v1.2.3