From owner-freebsd-bugs Fri Oct 30 07:10:03 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id HAA19220 for freebsd-bugs-outgoing; Fri, 30 Oct 1998 07:10:03 -0800 (PST) (envelope-from owner-freebsd-bugs@FreeBSD.ORG) Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id HAA19157 for ; Fri, 30 Oct 1998 07:09:59 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.8.8/8.8.5) id HAA16910; Fri, 30 Oct 1998 07:10:00 -0800 (PST) Received: from beebite.ugh.net.au ([203.17.118.121]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id HAA18601 for ; Fri, 30 Oct 1998 07:02:30 -0800 (PST) (envelope-from andrew@ugh.net.au) Received: (from andrew@localhost) by beebite.ugh.net.au (8.8.8/8.8.8) id PAA08422; Fri, 30 Oct 1998 15:00:54 GMT (envelope-from andrew) Message-Id: <199810301500.PAA08422@beebite.ugh.net.au> Date: Fri, 30 Oct 1998 15:00:54 GMT From: andrew@ugh.net.au Reply-To: andrew@ugh.net.au To: FreeBSD-gnats-submit@FreeBSD.ORG X-Send-Pr-Version: 3.2 Subject: bin/8501: snake has a segmentation fault depending on the terminal type Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >Number: 8501 >Category: bin >Synopsis: snake has a segmentation fault depending on the terminal type >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Oct 30 07:10:00 PST 1998 >Last-Modified: >Originator: Andrew >Organization: UgH! >Release: FreeBSD 2.2.7-STABLE i386 >Environment: The termcap entry for my terminal dosn't define bc or bs >Description: When I run snake it crashes with a segmentation fault at line 660 when it calls strlen(BS). BS is set to NULL. This is because the termcap entry for my terminal dosn't define bc or bs. >How-To-Repeat: Use a termcap entry that dosn't define bs or bc and run snake >Fix: I have wrapped the strlen call in a test for BS "NULLness". I did the same for ND and KL as they seemed likely to suffer the same fate if their corresponding tgetstrs returned NULL. While I was at it I also removed a few variables that were declared but never used...just the odd int and char. There was also some odd logic determining if the terminal had an addressable cursor or home + 4 local motions. I have changed this to what I think is a correct state. I added in a few lines to hide the cursor when playing. I rewrote the delay function so it wouldn't waste bandwidth when playing via telnet. The new delay function should be better on the CPU as well. The new delay function does what the coments indicate the earlier function was intended to do (delay for t/20 seconds) although the old function didn't always acheive this. Patches are attached below: --- snake.h.orig Sun Sep 4 14:03:20 1994 +++ snake.h Sat Oct 31 00:56:10 1998 @@ -50,7 +50,8 @@ *HO, *CM, *TA, *LL, *KL, *KR, *KU, *KD, - *TI, *TE, *KS, *KE; + *TI, *TE, *KS, *KE, + *VI, *VE; int LINES, COLUMNS; /* physical screen size. */ int lcnt, ccnt; /* user's idea of screen size */ char xBC, PC; --- snake.c.orig Mon Mar 2 03:41:58 1998 +++ snake.c Sat Oct 31 00:56:10 1998 @@ -104,7 +104,7 @@ { extern char *optarg; extern int optind; - int ch, i, j, k; + int ch, i; void stop(); rawscores = open(_PATH_RAWSCORES, O_RDWR|O_CREAT, 0664); @@ -170,6 +170,7 @@ signal (SIGINT, stop); putpad(TI); /* String to begin programs that use cm */ putpad(KS); /* Put terminal in keypad transmit mode */ + putpad(VI); /* Hide cursor */ snrand(&finish); snrand(&you); @@ -364,8 +365,6 @@ if (same(&you,&money)) { - char xp[20]; - struct point z; loot += 25; if(k < repeat) pchar(&you,' '); @@ -632,7 +631,6 @@ snap() { struct point p; - int i; if(you.line < 3){ pchar(point(&p,you.col,0),'-'); @@ -708,7 +706,7 @@ surround(ps) struct point *ps;{ struct point x; - int i,j; + int j; if(ps->col == 0)ps->col++; if(ps->line == 0)ps->line++; @@ -869,8 +867,6 @@ suspend() { - char *sh; - ll(); cook(); kill(getpid(), SIGTSTP); --- move.c.orig Tue May 30 13:37:26 1995 +++ move.c Sat Oct 31 00:56:10 1998 @@ -96,6 +96,8 @@ #else #include #endif +#include + #include "snake.h" int CMlength; @@ -186,7 +188,7 @@ struct point *sp; { - int distance,f,tfield,j; + int distance,f,tfield; if (cursor.line > LINES || cursor.line <0 || cursor.col <0 || cursor.col > COLUMNS) @@ -339,7 +341,7 @@ } ll(){ - int j,l; + int l; struct point z; l = lcnt + 2; @@ -524,12 +526,7 @@ delay(t) int t; { - int k,j; - - k = baudrate() * t / 300; - for(j=0;jAudit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message