[PATCH 1/1] libc: Added implementation for sig2str/str2sig.

Matthew Joyce mfjoyce2004@gmail.com
Tue Aug 3 03:57:39 GMT 2021


Hi Corinna,

Thanks very much for the suggestion...that sounds sensible. I just
made the edits in a new patch (hopefully that's ok).

I'm really glad to help...thank you very much for your patience as well!

Sincerely,

Matt



On Mon, Aug 2, 2021 at 1:48 PM Corinna Vinschen <vinschen@redhat.com> wrote:
>
> Hi Matt,
>
> a collegue of mine pointed out that it might be good idea to be more
> paranoid in terms of the output string size:
>
> On Jul 31 15:22, Matt Joyce wrote:
> > +sig2str(int signum, char *str)
> > +{
> > +  const sig_name_and_num *sptr;
> > +
> > +  /* 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 &&
> > +      signum <= (SIGRTMIN + SIGRTMAX) / 2) {
> > +    sprintf(str, "RTMIN+%d", (signum-SIGRTMIN));
>
>        snprintf(str, SIG2STR_MAX, "RTMIN+%d", (signum-SIGRTMIN));
>
> > +    return 0;
> > +  }
> > +
> > +  /* If signum falls in upper half of the real time signals range, define
> > +   * the saved str value as "RTMAX-m" according to the Issue 8 standard */
> > +  if ((((SIGRTMIN + SIGRTMAX) / 2) + 1) <= signum &&
> > +         signum <= (SIGRTMAX - 1)) {
> > +    sprintf(str, "RTMAX-%d", (SIGRTMAX - signum));
>
>        snprintf(str, SIG2STR_MAX, "RTMAX+%d", (signum-SIGRTMIN));
>
> > +    return 0;
> > +  }
> > +
> > +  /* Otherwise, search for signal matching signum in sig_array. If found,
> > +   * save its string value in str. */
> > +  for (sptr = sig_array; sptr < &sig_array[NUM_OF_SIGS]; sptr++) {
> > +    if (sptr->sig_num == signum) {
> > +      strcpy(str, sptr->sig_name);
>
>          strlcpy(str, sptr->sig_name, SIG2STR_MAX);
>
> What do you think?
>
>
> Corinna
>


More information about the Newlib mailing list