Bug 12663

Summary: Ambiguous if statement
Product: Base System Reporter: Adam Wight <adamw>
Component: kernAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 4.0-CURRENT   
Hardware: Any   
OS: Any   

Description Adam Wight 1999-07-16 10:40:01 UTC
    The file sys/i386/apm/apm.c contains an ambiguous if...else statement
    that appears to be parsed correctly by the compiler, but could break
    silently depending on the compiler release.

Fix: Sorry, you might have to use patch -l...

===================================================================
RCS file: /usr/cvs/src/sys/i386/apm/apm.c,v
retrieving revision 1.90


!   if (events & (POLLIN | POLLRDNORM))
!       if (sc->event_count)
            revents |= events & (POLLIN | POLLRDNORM);
!       else 
            selrecord(p, &sc->sc_rsel);

    return (revents);
  }  
--- 1283,1295 ----
    struct apm_softc *sc = &apm_softc;
    int revents = 0;

!   if (events & (POLLIN | POLLRDNORM)) {
!       if (sc->event_count) {
            revents |= events & (POLLIN | POLLRDNORM);
!       } else {
            selrecord(p, &sc->sc_rsel);
+       }
+   }

    return (revents);
  }--Ng5dN5MzwZo8Ju70fMly3qGf2dDWIN4JMGhMij3ow1dQw9kV
Content-Type: text/plain; name="file.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="file.diff"

diff -c -r1.90 apm.c
*** apm.c   1999/07/10 18:08:48 1.90
--- apm.c   1999/07/13 17:45:38
***************  
*** 1283,1293 ****
    struct apm_softc *sc = &apm_softc;
    int revents = 0;
Comment 1 nate 1999-07-16 16:22:19 UTC
Adam Wight writes:
> 
> >Number:         12663
> >Category:       kern
> >Synopsis:       Ambiguous if statement
> >Confidential:   no
> >Severity:       non-critical
> >Priority:       low
> >Responsible:    freebsd-bugs
> >State:          open
> >Quarter:        
> >Keywords:       
> >Date-Required:
> >Class:          change-request
> >Submitter-Id:   current-users
> >Arrival-Date:   Fri Jul 16 02:40:01 PDT 1999
> >Closed-Date:
> >Last-Modified:
> >Originator:     Adam Wight
> >Release:        FreeBSD 4.0-CURRENT i386
> >Organization:
> >Environment:
>     all
> 
> >Description:
>     The file sys/i386/apm/apm.c contains an ambiguous if...else statement
>     that appears to be parsed correctly by the compiler, but could break
>     silently depending on the compiler release.

No, they could not break silently, as the syntax is guaranteed to be
correct by the ANSI-C standard.  If it broke, the compiler would be
broke and a number of other such code in many systems would also break.


Nate
Comment 2 iwasaki 1999-07-21 05:40:00 UTC
Nate Williams writes:
> No, they could not break silently, as the syntax is guaranteed to be
> correct by the ANSI-C standard.  If it broke, the compiler would be
> broke and a number of other such code in many systems would also break.

You might be right, Nate.  But I forgot to fix it up when I ported 
the code from NetBSD's one. Also I like a lot the style as Mr. Adam Wight 
pointed out because It is preventible from missing { and } when few more 
lines are needed in the block afterward.

Thank you Adam and Nate, I'll fix it soon if there is no objections.
Comment 3 Mitsuru IWASAKI freebsd_committer freebsd_triage 1999-07-22 15:46:44 UTC
State Changed
From-To: open->closed

Fixed.  Thanks!