chris@mimsy.UUCP (Chris Torek) (01/15/88)
Here, in reverse chronological order, are three related changes to lint. I have tried none of them. The first one (from Ray Butterworth, not Arthur Olson; sorry for any confusion) apparently causes lint to complain about if (a = b) but not if ((a = b) != 0) as well as changing the way `constant in conditional context' errors are flagged. One of ado's changes also changes the way such errors are flagged; which one is best, or whether they are complementary, I have not ascertained. From rbutterworth@watmath.UUCP (Ray Butterworth) Thu Aug 7 10:34:31 1986 Relay-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site maryland.UUCP Path: maryland!umcp-cs!seismo!husc6!harvard!panda!genrad!decvax!watmath!rbutterworth From: rbutterworth@watmath.UUCP (Ray Butterworth) Newsgroups: net.lang.c Subject: Re: expr?(void):(void) WHY I THINK IT'S *OK* ( or should be ) Message-ID: <2278@watmath.UUCP> Date: 7 Aug 86 14:34:31 GMT Date-Received: 10 Aug 86 00:37:29 GMT References: <501@bunny.UUCP> <500@copper.UUCP> <273@watmath.UUCP> <3220@utcsri.UUCP> Distribution: net Organization: U of Waterloo, Ontario Lines: 73 > Lint obviously does *some* analysis of this, since it can say > "constant in conditional context". BTW, I have a program that gives > that error, but the expression is in an ARRAY DIMENSION for crissake. > char foo[ THING1 > THING2 ? THING1 : THING2 ]; > Obviously it's going to be a constant. Any lint authors listening? > Turn that off when a constant expression is called for. While I'm > wishing for things, I wanna see 'assignment in conditional context'. > We all know why by now... ------/usr/src/lib/mip/cgram.y------(look for "con_e:") /* EXPRESSIONS */ con_e: { #ifdef LINT {extern int constexp;} constexp=1; #endif $<intval>$=instruct; stwart=instruct=0; } e %prec CM ={ $$ = icons( $2 ); instruct=$<intval>1; #ifdef LINT constexp=0; #endif } ; .e: e ------/usr/src/lib/mip/trees.c------(look for warning message) case BRANCH: ccwarn: #ifdef LINT {extern int constexp;} if (hflag&&!constexp) werror("constant in conditional context"); #endif case PLUS: ------/usr/src/usr.bin/lint/lpass1.c------(add to definitions of externals) int constexp=0; ------/usr/src/usr.bin/lint/lpass1.c------(in function contx()) contx( p, down, pl, pr ) register NODE *p; register *pl, *pr; { *pl = *pr = VAL; if (p->in.type==UNDEF) down=VAL; /* (void) cast */ switch( p->in.op ){ case NOT: *pl=down; case ANDAND: case OROR: if (hflag&&(p->in.right->in.op==ASSIGN)) werror("Possible unintended assignment"); case QUEST: *pr = down; case CBRANCH: if (hflag&&(p->in.left->in.op==ASSIGN)) werror("possible unintended assignment"); break; case SCONV: case PCONV: From ado@elsie.UUCP (Arthur David Olson) Sun Aug 18 21:50:55 1985 Relay-Version: version B 2.10.1 6/24/83; site umcp-cs.UUCP Posting-Version: version B 2.10.3 alpha 4/15/85; site elsie.UUCP Path: umcp-cs!cvl!elsie!ado From: ado@elsie.UUCP (Arthur David Olson) Newsgroups: net.lang.c Subject: 4.1bsd lint additions to catch "if (condition) ;" Message-ID: <5205@elsie.UUCP> Date: Sun, 18-Aug-85 21:50:55 EDT Date-Received: Sun, 18-Aug-85 22:30:15 EDT References: <389@phri.UUCP> Distribution: net Organization: NIH-LEC, Bethesda, MD Lines: 84 In article <389@phri.UUCP>, roy@phri.UUCP (Roy Smith) writes: > > Here's one that just got me: > > if (sv > score); <----- note extraneous semi-colon > score = sv; Here are additions to 4.1bsd's "lint" to catch constructs like that above. Warnings are only produced if lint's "-h" flag is used. Two files are involved. In the description below, all code to be added appears between "#ifndef OLDVERSION" and "#endif" directives. As usual, the trade secret status of the code precludes a clearer posting. First, additions to "lint.c". Add this declaration just before the function "ecode": #ifndef OLDVERSION char * gripenull; #endif . . .and, as the last statement in "ecode", add this: #ifndef OLDVERSION gripenull = 0; #endif Second, additions to "cgram.y". Just after the declaration of "fake", add a declaration of "gripenull": #ifndef OLDVERSION extern char * gripenull; #endif In the code handling the "ifprefix statement" variant of a "statement" add this code: | ifprefix statement ={ deflab($1); #ifndef OLDVERSION gripenull = 0; #endif In the code handling the "ifelprefix statement" variant of a "statement" add this code: | ifelprefix statement ={ if( $1 != NOLAB ){ deflab( $1 ); reached = 1; } #ifndef OLDVERSION gripenull = 0; #endif In the code handling the "SM" variant of a "statement" add this code: | SM /* #ifndef OLDVERSION */ ={ if (hflag && gripenull != 0) werror(gripenull); } /* #endif OLDVERSION */ In the code for "ifprefix"es, add this code: ={ ecomp( buildtree( CBRANCH, $3, bcon( $$=getlab()) ) ) ; #ifndef OLDVERSION gripenull = "bodyless if"; #endif And, finally, in the code for "ifelprefix"es, add this code: ={ if( reached ) branch( $$ = getlab() ); else $$ = NOLAB; #ifndef OLDVERSION gripenull = "bodyless else"; #endif -- Lint is an Oscar Madison trademark. -- UUCP: ..decvax!seismo!elsie!ado ARPA: elsie!ado@seismo.ARPA DEC, VAX and Elsie are Digital Equipment and Borden trademarks From cvl!elsie!ado Fri Jul 20 14:20:59 1984 Relay-Version: version B 2.10 5/3/83; site umcp-cs.UUCP Posting-Version: version B 2.10.1 6/24/83; site elsie.UUCP Path: umcp-cs!cvl!elsie!ado From: ado@elsie.UUCP Newsgroups: net.bugs.4bsd Subject: "lint -h" misses constants in conditional contexts (w/changes) Message-ID: <1115@elsie.UUCP> Date: Fri, 20-Jul-84 14:20:59 EDT Article-I.D.: elsie.1115 Posted: Fri Jul 20 14:20:59 1984 Date-Received: Fri, 20-Jul-84 20:38:16 EDT Organization: NIH-LEC, Bethesda, MD Lines: 48 Index-- /usr/src/cmd/mip/trees.c /usr/src/cmd/mip/cgram.y Description-- Use of lint's "-h" option misses some constants in conditional contexts. Repeat by-- Pass this through "lint -h": main() { if (0 + 1) printf("true\n"); else printf("false\n"); printf((0 + 1) ? "true\n" : "false\n"); switch (0 + 1) { case 0: printf("false\n"); case 1: printf("true\n"); } } Note that a diagnostic message is produced for line 3 only. Fix-- ed - /usr/src/cmd/mip/trees.c /QUEST.*ICON/a #ifndef OLDVERSION if( hflag ) werror( "constant in conditional context" ); #endif . w q ed - /usr/src/cmd/mip/cgram.y /switchpart:/+2a #ifndef OLDVERSION if (hflag && ((union ndu *) $3)->in.op == ICON) werror( "constant in conditional context" ); #endif . w q -- ...decvax!allegra!umcp-cs!elsie!ado (301) 496-5688 (DEC, VAX and Elsie are Digital Equipment Corp. and Borden's trademarks) -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris
lvc@tut.cis.ohio-state.edu (Lawrence V. Cipriani) (01/16/88)
In article <10190@mimsy.UUCP>, chris@mimsy.UUCP (Chris Torek) writes: > Here, in reverse chronological order, are three related changes to > lint. ...like it says... While we are posting fixes for lint, here is an amusing one: In the lpass2.c file around line 499 (depending on your version of lint) there is: if( (t=BTYPE(pt1->aty)==STRTY) || t==UNIONTY ){ suggested change: if( (t=BTYPE(pt1->aty))==STRTY || t==UNIONTY ){ If you have the following chdir call in a C file, svr2 lint does not complain about the type mismatch, however, bsd 4.2 lint flags it correctly. chdir('/'); > In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) > Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris -- Larry Cipriani - using a guest account at lvc@tut.cis.ohio-state.edu a.k.a. ...!cbosgd!osu-cis!tut.cis.ohio-state.edu!lvc
dhesi@bsu-cs.UUCP (Rahul Dhesi) (01/18/88)
In article <4710@tut.cis.ohio-state.edu> lvc@tut.cis.ohio-state.edu (Lawrence V. Cipriani) writes: >In the lpass2.c file around line 499 (depending on your version of >lint) there is: > > if( (t=BTYPE(pt1->aty)==STRTY) || t==UNIONTY ){ > >suggested change: > > if( (t=BTYPE(pt1->aty))==STRTY || t==UNIONTY ){ Please be warned that I am collecting all context diffs, isolated lines of source code, etc., that are posted to Usenet. By carefully piecing everything together, I hope to have the entire source to UNIX--kernel, utilities, and all--in another 10 years. And it will be completely free of any copyright or source license restrictions! -- Rahul Dhesi UUCP: <backbones>!{iuvax,pur-ee,uunet}!bsu-cs!dhesi
garys@bunker.UUCP (Gary M. Samuelson) (01/19/88)
In article <1882@bsu-cs.UUCP> dhesi@bsu-cs.UUCP (Rahul Dhesi) writes: >Please be warned that I am collecting all context diffs, isolated lines >of source code, etc., that are posted to Usenet. By carefully piecing >everything together, I hope to have the entire source to UNIX--kernel, >utilities, and all--in another 10 years. And it will be completely >free of any copyright or source license restrictions! That will only work if you assume that every code fragment has at least one bug, misfeature, or suggested improvement which is discussed on the net. Hmm, that may not be such an unreasonable assumption after all! :-) Gary Samuelson