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 80671 - bad source code
Summary: bad source code
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gnuchess
Version: 8.0
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Karsten Hopp
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2002-12-29 17:27 UTC by d.binderman
Modified: 2007-04-18 16:49 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2003-07-08 13:00:25 UTC


Attachments (Terms of Use)

Description d.binderman 2002-12-29 17:27:18 UTC
From Bugzilla Helper:
User-Agent: Mozilla/4.6 [en-gb]C-CCK-MCD NetscapeOnline.co.uk  (Win98; I)

Description of problem:

Hello there,

I have just tried to compile package gnuchess-5.02-9 from Redhat 8.0

I got the following messages from the compiler.

cc: Warning: book.c, line 309: In this statement, this argument to printf and conversion specifier "%2.0f" combine integer and floating-point types.  
Behavior can be unpredictable. (outfloatint)
cc: Warning: cmd.c, line 267: In this statement, this argument to sscanf is of "pointer to short" type and is not appropriate for the conversion 
specifier 
"%d".  The value may overwrite other data or produce unexpected results. (inptrtype)
cc: Warning: cmd.c, line 267: In this statement, this argument to sscanf is of "pointer to short" type and is not appropriate for the conversion 
specifier 
"%d".  The value may overwrite other data or produce unexpected results. (inptrtype)
cc: Warning: cmd.c, line 397: In this statement, this argument to printf and conversion specifier "%.2f" combine integer and floating-point types.  
Behavior can be unpredictable. (outfloatint)
cc: Warning: iterate.c, line 98: In this statement, this argument to printf is of "float" type and is not appropriate for the conversion specifier "%s".  The 
value will be formatted in an unintended manner. (outstringtype)
cc: Warning: iterate.c, line 98: In this statement, the number of conversion specifiers to printf exceeds the number of values to be converted.  
Conversion specifiers from "%6.2f" onward will process meaningless and perhaps invalid data. (outtoofew)
cc: Info: players.c, line 192: In this statement, an array is being accessed outside the bounds specified for the array type. (subscrbounds)

Here is an untested patch to shut up the compiler.

./src/book.c.old ./src/book.c
*** ./src/book.c.old	Sun Dec 15 10:38:59 2002
--- ./src/book.c	Sun Dec 15 10:39:56 2002
***************
*** 306,312 ****
          tot = r[matches[k]].wins+r[matches[k]].draws+r[matches[k]].losses;
          if (tot != 0)
            printf("B p=%2.0f\n",
! 	   100*(r[matches[k]].wins+r[matches[k]].draws)/tot);
          else
            printf("p=NO EXPERIENCES\n");
        }
--- 306,312 ----
          tot = r[matches[k]].wins+r[matches[k]].draws+r[matches[k]].losses;
          if (tot != 0)
            printf("B p=%2.0f\n",
! 	   (float) 100*(r[matches[k]].wins+r[matches[k]].draws)/tot);
          else
            printf("p=NO EXPERIENCES\n");
        }
./src/cmd.c.old ./src/cmd.c
*** ./src/cmd.c.old	Sun Dec 15 10:40:11 2002
--- ./src/cmd.c	Sun Dec 15 10:43:43 2002
***************
*** 264,270 ****
       }
     }	
     else if (strcmp (cmd, "rating") == 0) {
!       sscanf(inputstr,"%d %d",&myrating,&opprating); 
        fprintf(ofp,"my rating = %d, opponent rating = %d\n",myrating,opprating); 
        /* Change randomness of book based on opponent rating. */
        /* Basically we play narrower book the higher the opponent */
--- 264,270 ----
       }
     }	
     else if (strcmp (cmd, "rating") == 0) {
!       sscanf(inputstr,"%hd %hd",&myrating,&opprating); 
        fprintf(ofp,"my rating = %d, opponent rating = %d\n",myrating,opprating); 
        /* Change randomness of book based on opponent rating. */
        /* Basically we play narrower book the higher the opponent */
***************
*** 394,400 ****
  	 if (!(flags & XBOARD)) {
  	   printf ("Time Control: %d moves in %.2f secs\n", 
  	          MoveLimit[white], TimeLimit[white]);
! 	   printf("Fischer increment of %.2f seconds\n",TCinc);
  	 }
        }
     }
--- 394,400 ----
  	 if (!(flags & XBOARD)) {
  	   printf ("Time Control: %d moves in %.2f secs\n", 
  	          MoveLimit[white], TimeLimit[white]);
! 	   printf("Fischer increment of %.2f seconds\n", (float) TCinc);
  	 }
        }
     }
./src/iterate.c.old ./src/iterate.c
./src/players.c.old ./src/players.c
*** ./src/players.c.old	Sun Dec 15 10:45:14 2002
--- ./src/players.c	Sun Dec 15 10:46:07 2002
***************
*** 189,195 ****
  	*p++;
    } while (*p != '\0');
    *x = '\000';
!   memset(playerdb,0,sizeof(playerdb[MAXPLAYERS]));
    DBReadPlayer ();
    index = DBSearchPlayer (lname);
    if (index == -1) {
--- 189,195 ----
  	*p++;
    } while (*p != '\0');
    *x = '\000';
!   memset( playerdb, 0, sizeof(playerdb));
    DBReadPlayer ();
    index = DBSearchPlayer (lname);
    if (index == -1) {


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


How reproducible:
Always

Steps to Reproduce:
1. compile with Compaq C compiler
2.
3.
    

Additional info:


Use of Compaq C compiler not significant.

Any C compiler that checks printf'scanf parameter
lists will produce similar messages.

Comment 1 Karsten Hopp 2003-06-04 11:17:10 UTC
I'm only interested in gcc errors/messages, sorry. I recompiled gnuchess to check for 
problems, but didn't get any of your messages. 
This needs to be fixed upstream: bug-gnu-chess@gnu.org 

Comment 2 d.binderman 2003-07-05 08:20:32 UTC
>I'm only interested in gcc errors/messages, sorry. 

That's a very short sighted policy.

You would be very well advised to look at any warning
any compiler produces, especially compilers which have
better checking.

>I recompiled gnuchess to check for 
>problems, but didn't get any of your messages. 

Suggest try using the -Wall flag on gcc.

>This needs to be fixed upstream: bug-gnu-chess@gnu.org

I've found some problems, I've provided a patch, what's
so hard about you applying the patch and fixing it ?


Comment 3 Karsten Hopp 2003-07-08 13:00:25 UTC
no problem at all even with -Wall: 
.... 
gcc -DHAVE_CONFIG_H -I. -I. -I.    -pthread -O2 -Wall -c `test -f book.c || echo './'`book.c 
source='cmd.c' object='cmd.o' libtool=no \ 
depfile='.deps/cmd.Po' tmpdepfile='.deps/cmd.TPo' \ 
depmode=gcc3 /bin/sh ../depcomp \ 
gcc -DHAVE_CONFIG_H -I. -I. -I.    -pthread -O2 -Wall -c `test -f cmd.c || echo './'`cmd.c 
.... 
 
I won't add patches for compilers which aren't part of our distribution unless the same bugs 
show up with our compiler. 
Please report this bug to the gnuchess maintainers, they will be happy about your patch and 
it will be fixed in their next release. That one will be picked up by all distributions and the  
problem is gone for all of them. I'm not rejecting your patch because I don't like it, it's just 
because I don't need it for Red Hat Linux and fixing the problem upstream is the better way to 
handle this. 


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