public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] libc: Fix compilation for new sig2str/str2sig implementation
@ 2021-08-02 14:00 Christoph Muellner
  2021-08-02 14:20 ` Joel Sherrill
  2021-08-02 14:47 ` Corinna Vinschen
  0 siblings, 2 replies; 3+ messages in thread
From: Christoph Muellner @ 2021-08-02 14:00 UTC (permalink / raw)
  To: newlib; +Cc: Kito Cheng, Christoph Muellner

A recent patch introduced new code for sig2str/str2sig.
This code does not properly exclude code that requires
SIGRTMIN/SIGRTMAX to be defined and triggers the following
compile error:

  newlib/libc/signal/sig2str.c:199:8: error: 'SIGRTMIN' undeclared
  newlib/libc/signal/sig2str.c:200:29: error: 'SIGRTMAX' undeclared

Let's add the missing guards.

Fixes: 2b50ec0cd205 ("libc: Fix compilation for new sig2str/str2sig implementation")

Signed-off-by: Christoph Muellner <cmuellner@gcc.gnu.org>
---
 newlib/libc/signal/sig2str.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/newlib/libc/signal/sig2str.c b/newlib/libc/signal/sig2str.c
index 940a5eab9..d3be1ba68 100644
--- a/newlib/libc/signal/sig2str.c
+++ b/newlib/libc/signal/sig2str.c
@@ -194,6 +194,7 @@ sig2str(int signum, char *str)
 {
   const sig_name_and_num *sptr;
 
+#if defined (SIGRTMIN) && defined (SIGRTMAX)
   /* If signum falls in lower half of the real time signals range, define
    * the saved str value as "RTMIN+n" according to the Issue 8 standard */
   if ((SIGRTMIN + 1) <= signum &&
@@ -209,6 +210,7 @@ sig2str(int signum, char *str)
     sprintf(str, "RTMAX-%d", (SIGRTMAX - signum));
     return 0;
   }
+#endif
 
   /* Otherwise, search for signal matching signum in sig_array. If found,
    * save its string value in str. */
@@ -231,6 +233,7 @@ str2sig(const char *restrict str, int *restrict pnum)
   const sig_name_and_num *sptr;
   unsigned long is_valid_decimal;
 
+#if defined (SIGRTMIN) && defined (SIGRTMAX)
   /* i686 Cygwin only supports one RT signal. For this case, skip checks
    * for "RTMIN+n" and "RTMAX-m". */
   if (SIGRTMIN != SIGRTMAX) {
@@ -269,6 +272,7 @@ str2sig(const char *restrict str, int *restrict pnum)
       return -1;
     }
   }
+#endif
 
   /*If str is a valid signal name, save its corresponding number in pnum. */
   for (sptr = sig_array; sptr < &sig_array[NUM_OF_SIGS]; sptr++) {
@@ -289,9 +293,10 @@ str2sig(const char *restrict str, int *restrict pnum)
   /* If str is a representation of a decimal value, save its integer value
    * in pnum. */
   if (1 <= is_valid_decimal &&
-      is_valid_decimal <= SIGRTMAX) {
+      is_valid_decimal <= (NSIG - 1)) {
     *pnum = is_valid_decimal;
     return 0;
   }
+
   return -1;
 }
-- 
2.31.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] libc: Fix compilation for new sig2str/str2sig implementation
  2021-08-02 14:00 [PATCH] libc: Fix compilation for new sig2str/str2sig implementation Christoph Muellner
@ 2021-08-02 14:20 ` Joel Sherrill
  2021-08-02 14:47 ` Corinna Vinschen
  1 sibling, 0 replies; 3+ messages in thread
From: Joel Sherrill @ 2021-08-02 14:20 UTC (permalink / raw)
  To: Christoph Muellner; +Cc: Newlib, Kito Cheng

I'm ok with this. We discussed this as needed during the patch review
but it must have slipped through the cracks while we were discussing
the guards for the method prototype.

On Mon, Aug 2, 2021 at 9:01 AM Christoph Muellner <cmuellner@gcc.gnu.org> wrote:
>
> A recent patch introduced new code for sig2str/str2sig.
> This code does not properly exclude code that requires
> SIGRTMIN/SIGRTMAX to be defined and triggers the following
> compile error:
>
>   newlib/libc/signal/sig2str.c:199:8: error: 'SIGRTMIN' undeclared
>   newlib/libc/signal/sig2str.c:200:29: error: 'SIGRTMAX' undeclared
>
> Let's add the missing guards.
>
> Fixes: 2b50ec0cd205 ("libc: Fix compilation for new sig2str/str2sig implementation")
>
> Signed-off-by: Christoph Muellner <cmuellner@gcc.gnu.org>
> ---
>  newlib/libc/signal/sig2str.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/newlib/libc/signal/sig2str.c b/newlib/libc/signal/sig2str.c
> index 940a5eab9..d3be1ba68 100644
> --- a/newlib/libc/signal/sig2str.c
> +++ b/newlib/libc/signal/sig2str.c
> @@ -194,6 +194,7 @@ sig2str(int signum, char *str)
>  {
>    const sig_name_and_num *sptr;
>
> +#if defined (SIGRTMIN) && defined (SIGRTMAX)
>    /* If signum falls in lower half of the real time signals range, define
>     * the saved str value as "RTMIN+n" according to the Issue 8 standard */
>    if ((SIGRTMIN + 1) <= signum &&
> @@ -209,6 +210,7 @@ sig2str(int signum, char *str)
>      sprintf(str, "RTMAX-%d", (SIGRTMAX - signum));
>      return 0;
>    }
> +#endif
>
>    /* Otherwise, search for signal matching signum in sig_array. If found,
>     * save its string value in str. */
> @@ -231,6 +233,7 @@ str2sig(const char *restrict str, int *restrict pnum)
>    const sig_name_and_num *sptr;
>    unsigned long is_valid_decimal;
>
> +#if defined (SIGRTMIN) && defined (SIGRTMAX)
>    /* i686 Cygwin only supports one RT signal. For this case, skip checks
>     * for "RTMIN+n" and "RTMAX-m". */
>    if (SIGRTMIN != SIGRTMAX) {
> @@ -269,6 +272,7 @@ str2sig(const char *restrict str, int *restrict pnum)
>        return -1;
>      }
>    }
> +#endif
>
>    /*If str is a valid signal name, save its corresponding number in pnum. */
>    for (sptr = sig_array; sptr < &sig_array[NUM_OF_SIGS]; sptr++) {
> @@ -289,9 +293,10 @@ str2sig(const char *restrict str, int *restrict pnum)
>    /* If str is a representation of a decimal value, save its integer value
>     * in pnum. */
>    if (1 <= is_valid_decimal &&
> -      is_valid_decimal <= SIGRTMAX) {
> +      is_valid_decimal <= (NSIG - 1)) {
>      *pnum = is_valid_decimal;
>      return 0;
>    }
> +
>    return -1;
>  }
> --
> 2.31.1
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] libc: Fix compilation for new sig2str/str2sig implementation
  2021-08-02 14:00 [PATCH] libc: Fix compilation for new sig2str/str2sig implementation Christoph Muellner
  2021-08-02 14:20 ` Joel Sherrill
@ 2021-08-02 14:47 ` Corinna Vinschen
  1 sibling, 0 replies; 3+ messages in thread
From: Corinna Vinschen @ 2021-08-02 14:47 UTC (permalink / raw)
  To: Christoph Muellner; +Cc: newlib, Kito Cheng

On Aug  2 16:00, Christoph Muellner wrote:
> A recent patch introduced new code for sig2str/str2sig.
> This code does not properly exclude code that requires
> SIGRTMIN/SIGRTMAX to be defined and triggers the following
> compile error:
> 
>   newlib/libc/signal/sig2str.c:199:8: error: 'SIGRTMIN' undeclared
>   newlib/libc/signal/sig2str.c:200:29: error: 'SIGRTMAX' undeclared
> 
> Let's add the missing guards.
> 
> Fixes: 2b50ec0cd205 ("libc: Fix compilation for new sig2str/str2sig implementation")
> 
> Signed-off-by: Christoph Muellner <cmuellner@gcc.gnu.org>
> ---
>  newlib/libc/signal/sig2str.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)

Pushed.


Thanks,
Corinna


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-02 14:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-02 14:00 [PATCH] libc: Fix compilation for new sig2str/str2sig implementation Christoph Muellner
2021-08-02 14:20 ` Joel Sherrill
2021-08-02 14:47 ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).