🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: mod.computers.gould
Article #8

cc bug with short unsigned constants

#8
From: Larry Parmelee
Date: Fri, 22 Nov 1985 14:59
50 lines
1795 bytes
Index:	/usr/src/lib/ccom

Description:
	Unsigned short integer constants sometimes get sign extension, 
	when this is not desired.

Repeat-By:
	Compile the following little program, and run it.
	
------cut here------
main()
{
    int i, ij1, ij2;
    unsigned short int j;
 	
    i = 10;
    j = (unsigned short)(01<<15);

    ij1 = i + j ;				/* Line 9 */
    ij2 = i + (unsigned short)(01<<15) ; 	/* Line 10-- BUG!!! */

    printf("i=0x%x, j=0x%x,  ij1=0x%x,  ij2=0x%x \n",i,j,ij1,ij2);
}
------cut here------

	The output from the above is:

i=0xa, j=0x8000,  ij1=0x800a,  ij2=0xffff800a
	
	Line 9 produces the following code:  (No Bug)

--	line 9, file "main.c"
	movh	11w+LOC1[b2],r0
	andw	#0xffff,r0
	addw	8w+LOC1[b2],r0
	movw	r0,9w+LOC1[b2]

	Line 10 produces this--(BUG!!!: Note the missing "andw")

--	line 10, file "main.c"
	movh	#0x8000,r0
	addw	8w+LOC1[b2],r0
	movw	r0,10w+LOC1[b2]

	The operation (in the above, addition) does not seem to be significant;
	The same problem occurs with "or".

	-Larry Parmelee
	parmelee@gvax.cs.cornell.edu
	{allegra,ihnp4,decvax}!cornell!parmelee
Technical Details
Message-ID: <8511221459.AA15354@systems.cs.cornell.edu>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!ucbvax!gouldbugs

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site ucbvax.BERKELEY.EDU
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!ucbvax!gouldbugs
From: parmelee@SYSTEMS.CS.CORNELL.EDU (Larry Parmelee)
Newsgroups: mod.computers.gould
Subject: cc bug with short unsigned constants
Message-ID: <8511221459.AA15354@systems.cs.cornell.edu>
Date: Fri, 22-Nov-85 09:59:13 EST
Article-I.D.: systems.8511221459.AA15354
Posted: Fri Nov 22 09:59:13 1985
Date-Received: Mon, 25-Nov-85 07:37:10 EST
Sender: daemon@ucbvax.BERKELEY.EDU
Organization: The ARPA Internet
Lines: 50
Approved: gouldbugs@brl.arpa