This is the mail archive of the newlib@sources.redhat.com mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: fix switch statement in signal.c


Geoff Keating wrote:
> 
> I didn't know that you weren't allowed to do this, and apparently the
> authors of signal.c didn't either, but Mark Mitchell does know and he
> just committed some substantial changes to the GCC C frontend that
> included this check.
> 
> (SIG_DFL and similar are #defined to be like (void (*)(int))-2
> which is not an 'integral constant expression'.)
> 
> OK to commit?
> 

Yes, please check the code in.  This requirement is well-documented in the ANSI standard.

Thanks,

-- Jeff Johnston (Red Hat Inc.)

> --
> - Geoffrey Keating <geoffk@cygnus.com>
> 
> ===File ~/patches/cygnus/newlib-signalcase.patch============
> 2000-09-18  Geoffrey Keating  <geoffk@cygnus.com>
> 
>         * libc/signal/signal.c (__sigtramp_r): ISO C requires
>         case labels to be integral constant expressions, so
>         use an if/else tree instead.
>         (_raise_r): Likewise.
> 
> Index: libc/signal/signal.c
> ===================================================================
> RCS file: /cvs/src/src/newlib/libc/signal/signal.c,v
> retrieving revision 1.2
> diff -c -p -r1.2 signal.c
> *** signal.c    2000/04/17 17:10:15     1.2
> --- signal.c    2000/09/19 05:37:14
> *************** _raise_r (ptr, sig)
> *** 167,173 ****
>        int sig;
>   {
>     _sig_func_ptr func;
> -   int result = 0;
> 
>     if (sig < 0 || sig >= NSIG)
>       {
> --- 167,172 ----
> *************** _raise_r (ptr, sig)
> *** 178,204 ****
>     if (ptr->_sig_func == NULL && _init_signal_r (ptr) != 0)
>       return -1;
> 
> !   switch ((_POINTER_INT) ptr->_sig_func[sig])
>       {
> -     case SIG_DFL:
> -       return _kill_r (ptr, _getpid_r (ptr), sig);
> -
> -     case SIG_IGN:
> -       break;
> -
> -     case SIG_ERR:
>         ptr->_errno = EINVAL;
> !       result = 1;
> !       break;
> !
> !     default:
> !       func = ptr->_sig_func[sig];
>         ptr->_sig_func[sig] = SIG_DFL;
>         func (sig);
> !       break;
>       }
> -
> -   return result;
>   }
> 
>   int
> --- 177,198 ----
>     if (ptr->_sig_func == NULL && _init_signal_r (ptr) != 0)
>       return -1;
> 
> !   func = ptr->_sig_func[sig];
> !   if (func == SIG_DFL)
> !     return _kill_r (ptr, _getpid_r (ptr), sig);
> !   else if (func == SIG_IGN)
> !     return 0;
> !   else if (func == SIG_ERR)
>       {
>         ptr->_errno = EINVAL;
> !       return 1;
> !     }
> !   else
> !     {
>         ptr->_sig_func[sig] = SIG_DFL;
>         func (sig);
> !       return 0;
>       }
>   }
> 
>   int
> *************** __sigtramp_r (ptr, sig)
> *** 215,234 ****
> 
>     if (ptr->_sig_func == NULL && _init_signal_r (ptr) != 0)
>       return -1;
> -
> -   switch ((_POINTER_INT) ptr->_sig_func[sig])
> -     {
> -     case SIG_DFL:
> -       return 1;
> 
> !     case SIG_ERR:
> !       return 2;
> !
> !     case SIG_IGN:
> !       return 3;
> !
> !     default:
> !       func = ptr->_sig_func[sig];
>         ptr->_sig_func[sig] = SIG_DFL;
>         func (sig);
>         return 0;
> --- 209,224 ----
> 
>     if (ptr->_sig_func == NULL && _init_signal_r (ptr) != 0)
>       return -1;
> 
> !   func = ptr->_sig_func[sig];
> !   if (func == SIG_DFL)
> !     return 1;
> !   else if (func == SIG_ERR)
> !     return 2;
> !   else if (func == SIG_IGN)
> !     return 3;
> !   else
> !     {
>         ptr->_sig_func[sig] = SIG_DFL;
>         func (sig);
>         return 0;
> ============================================================

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]