From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1914) id 7C9773857827; Mon, 16 May 2022 08:44:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7C9773857827 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Pierre-Marie de Rodat To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-494] [Ada] sigaction result not properly checked in __gnat_install_handler (QNX) X-Act-Checkin: gcc X-Git-Author: Joel Brobecker X-Git-Refname: refs/heads/master X-Git-Oldrev: 839e7f16abda3fd8bd46d59ff1521d402d328a24 X-Git-Newrev: 1bdf9fa390282299418e21534674d0ab252e9f34 Message-Id: <20220516084433.7C9773857827@sourceware.org> Date: Mon, 16 May 2022 08:44:33 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 May 2022 08:44:33 -0000 https://gcc.gnu.org/g:1bdf9fa390282299418e21534674d0ab252e9f34 commit r13-494-g1bdf9fa390282299418e21534674d0ab252e9f34 Author: Joel Brobecker Date: Fri Mar 11 03:39:53 2022 +0000 [Ada] sigaction result not properly checked in __gnat_install_handler (QNX) The QNX version of __gnat_install_handler calls sigaction for a number of signals, and then prints an error message when the the call failed. But unfortunately, except for the first call, we forgot to store sigaction's return value, so the check that ensues uses a potentially uninitialized variable, which the compiler does detect (this is how we found this issue). This change fixes this by make sure we store the result of each sigaction call before checking it. While at it, we noticed a thinko in the error messages all alerting about the SIGFPE signal, rather than the signal it just tested. Most likely a copy/paste thinko. Fixed by this change as well. gcc/ada/ * init.c (__gnat_install_handler) [__QNX__]: Save sigaction's return value in err before checking err's value. Fix incorrect signal names in perror messages. Diff: --- gcc/ada/init.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gcc/ada/init.c b/gcc/ada/init.c index 4615cc152b2..89f16a176d3 100644 --- a/gcc/ada/init.c +++ b/gcc/ada/init.c @@ -2625,26 +2625,26 @@ __gnat_install_handler (void) } } if (__gnat_get_interrupt_state (SIGILL) != 's') { - sigaction (SIGILL, &act, NULL); + err = sigaction (SIGILL, &act, NULL); if (err == -1) { err = errno; - perror ("error while attaching SIGFPE"); + perror ("error while attaching SIGILL"); perror (strerror (err)); } } if (__gnat_get_interrupt_state (SIGSEGV) != 's') { - sigaction (SIGSEGV, &act, NULL); + err = sigaction (SIGSEGV, &act, NULL); if (err == -1) { err = errno; - perror ("error while attaching SIGFPE"); + perror ("error while attaching SIGSEGV"); perror (strerror (err)); } } if (__gnat_get_interrupt_state (SIGBUS) != 's') { - sigaction (SIGBUS, &act, NULL); + err = sigaction (SIGBUS, &act, NULL); if (err == -1) { err = errno; - perror ("error while attaching SIGFPE"); + perror ("error while attaching SIGBUS"); perror (strerror (err)); } }