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

Corinna Vinschen <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.