Bug 79230 - bad source code
bad source code
Status: CLOSED UPSTREAM
Product: Red Hat Linux
Classification: Retired
Component: ncurses4 (Show other bugs)
8.0
i386 Linux
low Severity low
: ---
: ---
Assigned To: Eido Inoue
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2002-12-08 05:30 EST by d.binderman
Modified: 2005-10-31 17:00 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2004-04-19 15:36:41 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description d.binderman 2002-12-08 05:30:32 EST
Description of Problem:

Hello there,

I just tried to compile package ncurses4-5.0-9 from Redhat 8.0.

Here are some of the compiler messages.

../test/newdemo.c:278: warning: operation on `x1' may be undefined
../test/newdemo.c:281: warning: operation on `y1' may be undefined
../test/newdemo.c:285: warning: operation on `x2' may be undefined
../test/newdemo.c:288: warning: operation on `y2' may be undefined
../test/newdemo.c:292: warning: operation on `x3' may be undefined
../test/newdemo.c:295: warning: operation on `y3' may be undefined

Here is a patch which fixes the messages.

*** ./test/newdemo.c.old	2002-11-18 10:33:53.000000000 +0000
--- ./test/newdemo.c	2002-11-18 10:37:15.000000000 +0000
***************
*** 275,298 ****
      xd3  = 0; yd3 = 1;
      nodelay(win,TRUE);
      while(wgetch(win) == ERR)
!     {   x1 = xd1 > 0 ? ++x1 : --x1;
          if(x1 <= 1 || x1 >= w - 2)
              xd1 = xd1 ? 0 : 1;
!         y1 = yd1 > 0 ? ++y1 : --y1;
          if(y1 <= 1 || y1 >= h - 2)
  	    yd1 = yd1 ? 0 : 1;
  
!         x2 = xd2 > 0 ? ++x2 : --x2;
          if(x2 <= 1 || x2 >= w - 2)
              xd2 = xd2 ? 0 : 1;
!         y2 = yd2 > 0 ? ++y2 : --y2;
          if(y2 <= 1 || y2 >= h - 2)
              yd2 = yd2 ? 0 : 1;
  
!         x3 = xd3 > 0 ? ++x3 : --x3;
          if(x3 <= 1 || x3 >= w - 2)
  	    xd3 = xd3 ? 0 : 1;
!         y3 = yd3 > 0 ? ++y3 : --y3;
          if(y3 <= 1 || y3 >= h - 2)
              yd3 = yd3 ? 0 : 1;
  
--- 275,298 ----
      xd3  = 0; yd3 = 1;
      nodelay(win,TRUE);
      while(wgetch(win) == ERR)
!     {   x1 = xd1 > 0 ? (x1 + 1) : (x1 - 1);
          if(x1 <= 1 || x1 >= w - 2)
              xd1 = xd1 ? 0 : 1;
!         y1 = yd1 > 0 ? (y1 + 1) : (y1 - 1);
          if(y1 <= 1 || y1 >= h - 2)
  	    yd1 = yd1 ? 0 : 1;
  
!         x2 = xd2 > 0 ? (x2 + 1) : (x2 - 1);
          if(x2 <= 1 || x2 >= w - 2)
              xd2 = xd2 ? 0 : 1;
!         y2 = yd2 > 0 ? (y2 + 1) : (y2 - 1);
          if(y2 <= 1 || y2 >= h - 2)
              yd2 = yd2 ? 0 : 1;
  
!         x3 = xd3 > 0 ? (x3 + 1) : (x3 - 1);
          if(x3 <= 1 || x3 >= w - 2)
  	    xd3 = xd3 ? 0 : 1;
!         y3 = yd3 > 0 ? (y3 + 1) : (y3 - 1);
          if(y3 <= 1 || y3 >= h - 2)
              yd3 = yd3 ? 0 : 1;
  


Version-Release number of selected component (if applicable):


How Reproducible:


Steps to Reproduce:
1. 
2. 
3. 

Actual Results:


Expected Results:


Additional Information:
Comment 1 Eido Inoue 2004-04-19 15:36:41 EDT
The code is technically legal and correct C and use of side effects--
although it's style would be questioned.

The warnings do not occur with the default flag settings in the
Makefile (nor is it compiled and packaged), and the code is demo/test
code which won't be used in the actual library, so I'm going to leave
it as-is.
Comment 2 d.binderman 2004-04-19 15:48:41 EDT
>The code is technically legal and correct C and use of side effects--
>although it's style would be questioned.

The compiler doesn't think so. It's a fine point, which I am
willing to let slip, but usually a compiler has a much better idea
of the language standard than most developers.

>The warnings do not occur with the default flag settings in the 
>Makefile

Good point.


>the code is demo/test
>code which won't be used in the actual library, so I'm going to leave
>it as-is.

Seems ok to me.

Comment 3 Eido Inoue 2004-04-19 16:01:51 EDT
>>The code is technically legal and correct C and use of side effects--
>>although it's style would be questioned.

>The compiler doesn't think so.

Sure it does. That's why it's a "warning" and not an "error". It's a
warning because the type of code used requires an intimate knowledge
of order-of-evaluation with C-- which programmers (because they know
many languages with different order-of-evaluations and often get them
mixed up or forget). The compiler is giving a "warning" because it's
legal C but is statistically highly likely to be a bug and/or have
unintended consequences during run-time.
 
Comment 4 d.binderman 2004-04-19 17:47:31 EDT
>Sure it does. That's why it's a "warning" and not an "error". 

Not quite. C and C++ are permissive programming languages.
Given any old rubbish, they just shut up & try to compile it,
i.e. they always try to trust the programmer.
This is rule 1 for any C or C++ compiler.

Only by turning up the warning levels can you get most
C compilers to complain about rubbish code.

I've done that, it's complained about rubbish code.
The rest is up to you.


Note You need to log in before you can comment on or make changes to this bug.