Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.
Bug 79230 - bad source code
Summary: bad source code
Keywords:
Status: CLOSED UPSTREAM
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: ncurses4
Version: 8.0
Hardware: i386
OS: Linux
low
low
Target Milestone: ---
Assignee: Eido Inoue
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2002-12-08 10:30 UTC by d.binderman
Modified: 2005-10-31 22:00 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2004-04-19 19:36:41 UTC


Attachments (Terms of Use)

Description d.binderman 2002-12-08 10:30:32 UTC
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 19:36:41 UTC
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 19:48:41 UTC
>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 20:01:51 UTC
>>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 21:47:31 UTC
>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.