From gordont@proving-ground.sd.bluemt.net  Wed Nov  8 18:05:05 2000
Return-Path: <gordont@proving-ground.sd.bluemt.net>
Received: from proving-ground.sd.bluemt.net (dhcp76-36.sd.bmarts.com [209.247.76.36])
	by hub.freebsd.org (Postfix) with ESMTP id E08F737B4C5
	for <FreeBSD-gnats-submit@freebsd.org>; Wed,  8 Nov 2000 18:05:03 -0800 (PST)
Received: (from gordont@localhost)
	by proving-ground.sd.bluemt.net (8.11.1/8.11.1) id eA92ENt24175;
	Wed, 8 Nov 2000 18:14:23 -0800 (PST)
	(envelope-from gordont)
Message-Id: <200011090214.eA92ENt24175@proving-ground.sd.bluemt.net>
Date: Wed, 8 Nov 2000 18:14:23 -0800 (PST)
From: gordont@bluemtn.net
Sender: gordont@proving-ground.sd.bluemt.net
Reply-To: gordont@bluemtn.net
To: FreeBSD-gnats-submit@freebsd.org
Subject: snake_saver and star_saver fail to compile with -Wall -Werror<Synopsis of the problem (one line)>
X-Send-Pr-Version: 3.2

>Number:         22710
>Category:       kern
>Synopsis:       snake_saver and star_saver fail to compile with -Wall -Werror
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    yokota
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Nov 08 18:10:01 PST 2000
>Closed-Date:    Fri Jul 20 08:04:12 PDT 2001
>Last-Modified:  Fri Jul 20 08:04:23 PDT 2001
>Originator:     Gordon Tetlow
>Release:        FreeBSD 4.2-BETA i386
>Organization:
Blue Mountain
>Environment:

	
N/A

>Description:

	
Compiling snake_saver.ko and star_saver.ko with -Wall -Werror produces an
error about array indices being of type 'char'

>How-To-Repeat:

	
(Again, assuming Bourne Shell)
cd /usr/src/sys/modules/syscons/{snake,star}
CC='cc -Wall -Werror' make

>Fix:

	
similar to PR 22709. Was bored at work and thought I would do something very
minorly constructive.

-gordon

--- snake_saver.c.orig	Wed Nov  8 17:59:25 2000
+++ snake_saver.c	Wed Nov  8 17:59:49 2000
@@ -89,7 +89,7 @@
 				scp->xsize : -scp->xsize);
 			for (f=0; f< messagelen; f++)
 				savs[f] = scp->xpos + scp->ypos*scp->xsize;
-			sc_vtb_putc(&scp->scr, savs[0], sc->scr_map[*save],
+			sc_vtb_putc(&scp->scr, savs[0], sc->scr_map[(int) *save],
 				    (FG_LIGHTGREY | BG_BLACK) << 8);
 			blanked = 1;
 		}
@@ -111,7 +111,7 @@
 			diry = -diry;
 		savs[0] += dirx + diry;
 		for (f=messagelen-1; f>=0; f--)
-			sc_vtb_putc(&scp->scr, savs[f], sc->scr_map[save[f]],
+			sc_vtb_putc(&scp->scr, savs[f], sc->scr_map[(int) save[f]],
 				    (FG_LIGHTGREY | BG_BLACK) << 8);
 	}
 	else {
--- star_saver.c.orig	Wed Nov  8 18:05:31 2000
+++ star_saver.c	Wed Nov  8 18:05:52 2000
@@ -99,7 +99,7 @@
 		}
 		cell = random() % NUM_STARS;
 		sc_vtb_putc(&scp->scr, stars[cell][0], 
-			    sc->scr_map[pattern[stars[cell][1]]],
+			    sc->scr_map[(int) pattern[stars[cell][1]]],
 			    colors[random()%sizeof(colors)] << 8);
 		if ((stars[cell][1]+=(random()%4)) >= sizeof(pattern)-1) {
 			stars[cell][0] = random() % (scp->xsize*scp->ysize);

>Release-Note:
>Audit-Trail:

From: Peter Wemm <peter@netplex.com.au>
To: gordont@bluemtn.net
Cc: FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: pending/22710: snake_saver and star_saver fail to compile with -Wall -Werror<Synopsis of the problem (one line)> 
Date: Thu, 09 Nov 2000 16:23:59 +0800

 gordont@bluemtn.net wrote:
 [..]
 > similar to PR 22709. Was bored at work and thought I would do something very
 > minorly constructive.
 > 
 > -gordon
 > -			sc_vtb_putc(&scp->scr, savs[0], sc->scr_map[*save],
 > +			sc_vtb_putc(&scp->scr, savs[0], sc->scr_map[(int) *save
 
 Actually, this is quite incorrect..  All you are doing is hiding the problem
 instead of fixing it.  If you have 0x80 (-128 decimal), then casting it to
 an int ends up with (int) -128, which is still a negative array offset.
 
 sc->scr_map[(unsigned char)*save]; 
 
 would work, because you end up with a positive index value in all cases.
 
 I'm one of these crazy people that likes to compile things with
 switches like -funsigned-char. :-)
 
 Cheers,
 -Peter
 --
 Peter Wemm - peter@FreeBSD.org; peter@yahoo-inc.com; peter@netplex.com.au
 "All of this is for nothing if we don't go to the stars" - JMS/B5
 
 
Responsible-Changed-From-To: gnats-admin->yokota 
Responsible-Changed-By: dirk 
Responsible-Changed-When: Thu Nov 9 03:45:56 PST 2000 
Responsible-Changed-Why:  
Over to Mr. syscons... 

Kazutaka, can you please look at the patches and commit them  
if appropriate? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=22710 

From: Gordon Tetlow <gordont@bluemtn.net>
To: Peter Wemm <peter@netplex.com.au>
Cc: FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: pending/22710: snake_saver and star_saver fail to compile with
 -Wall -Werror<Synopsis of the problem (one line)> 
Date: Thu, 9 Nov 2000 12:27:11 -0800 (PST)

 On Thu, 9 Nov 2000, Peter Wemm wrote:
 
 > sc->scr_map[(unsigned char)*save]; 
 > 
 > would work, because you end up with a positive index value in all cases.
 > 
 > I'm one of these crazy people that likes to compile things with
 > switches like -funsigned-char. :-)
 
 Well, it would probably be better to use the cast since that makes it
 explicit. It's been a while since I've done C, which is why I wanted to
 work on something small to begin with.
 
 Also, compiling with switches -Wall -Werror -funsigned-char still causes
 the make to error-out.
 
 -gordon
 
 
State-Changed-From-To: open->closed 
State-Changed-By: yokota 
State-Changed-When: Fri Jul 20 08:04:12 PDT 2001 
State-Changed-Why:  
Fixed by nyan in both 5.0-CURRENT and RELENG_4. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=22710 
>Unformatted:
