Re: [PATCH 1/1] libc: Added implementation for sig2str/str2sig.
Matthew Joyce <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <CALo2L3PhfqYg4Hz3aPeQFTgN_rzfFNouS1PgfpEC6B-vtnr-9w@mail.gmail.com> |
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 <[email protected]> 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 >