From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mimir.eigenstate.org ([206.124.132.107]) by ur; Wed Mar 22 00:48:50 EDT 2017 Received: from oneeye (unknown [98.207.157.125]) by mimir.eigenstate.org (Postfix) with ESMTPSA id 7EA02600F5 for <9front@9front.org>; Wed, 22 Mar 2017 00:48:44 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eigenstate.org; s=mail; t=1490158124; bh=gh5bnipqWAyu4ssIslfYP4krYjIjgJdsNEAgFassYDw=; h=Date:From:To:Subject; b=GygDHRZ7QqXIcQLokaIKan1dHqZXAOMp+f7e/jfGl3ERqD3j2Dswfp6WUsczi4T6v aiGT9ab1KSLO/plSgzFlMlSmUVmDsandGNaSJUUeAvo9OLEaoQxYAIvc2j5x5aKvl3 YHN8BxvwLvb0FBGOc8+uYqY7BsIF1UJtZudooXiA= Date: Tue, 21 Mar 2017 21:48:43 -0700 From: Ori Bernstein To: 9front@9front.org Subject: Patch: Assemblers do not handle minimum vlong value correctly. Message-Id: <20170321214843.03541405e369f0c84be4a3f1@eigenstate.org> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.29; amd64-portbld-freebsd11.0) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: lossless webscale service-based core-aware controller The Plan 9 assemblers use strtoll to parse the integer literals in their input. It turns out that this is almost correct, but VLONG_MIN is clamped. This patch changes to use strtoull in order to allow the full range of integers. Below is a program that demosntrates the problem: term% cat test.s GLOBL L2<>+0(SB),$8 DATA L2<>+0(SB)/8,$-9223372036854775808 TEXT main+0(SB),2,$0 MOVQ L2<>+0(SB),AX RET term% 6a test.s term% 6l test.6 /amd64/lib/libc.a term% acid 6.out 6.out:amd64 plan 9 executable /sys/lib/acid/port /sys/lib/acid/amd64 acid: new() 33489: overflow _main SUBQ $0x90,SP 33489: breakpoint main+0x8 RET acid: *L2 0x8000000000000001 acid: -9223372036854775808 0x8000000000000000 And the patch: diff -r a01d0802d023 sys/src/cmd/cc/lexbody --- a/sys/src/cmd/cc/lexbody Mon Mar 20 19:15:40 2017 +0100 +++ b/sys/src/cmd/cc/lexbody Tue Mar 21 21:45:44 2017 -0700 @@ -343,10 +343,9 @@ goto casee; *cp = 0; if(sizeof(yylval.lval) == sizeof(vlong)) - yylval.lval = strtoll(symb, nil, 10); + yylval.lval = strtoull(symb, nil, 10); else - yylval.lval = strtol(symb, nil, 10); - + yylval.lval = strtoul(symb, nil, 10); ncu: while(c == 'U' || c == 'u' || c == 'l' || c == 'L') c = GETC(); -- Ori Bernstein