[comp.sys.atari.st] sozobon C bug in puts,printf...

gossa@rdge44.enet.dec.com (Andrew Goss) (05/26/90)

	Can someone help me, I seem to have come across a bug in DLIBS 1.2
in the terminal printing functions:

		puts()
		printf()

	They don't seem able to handle strings of length > 256 chars.

		value = puts("<string of > 256 chrs>");

	after executing this value = 257 and only the first 256 chars have 
been printed.
	Inspection of the .s files shows that HCC is generating correct code
so the problem must lie in the DLIB puts() and printf() routines.

	- Andrew Goss - 

steve@thelake.mn.org (Steve Yelvington) (05/26/90)

[In article <11959@shlump.nac.dec.com>,
 gossa@rdge44.enet.dec.com (Andrew Goss) writes ... ]

> 	Can someone help me, I seem to have come across a bug in DLIBS 1.2
> in the terminal printing functions:
> 		puts()
> 		printf()
> 	They don't seem able to handle strings of length > 256 chars.
> 		value = puts("<string of > 256 chrs>");
> 	after executing this value = 257 and only the first 256 chars have 
> been printed.
> 	Inspection of the .s files shows that HCC is generating correct code
> so the problem must lie in the DLIB puts() and printf() routines.

puts() and printf() are not at fault.

Note the following demonstration program and the generated code. The
LONGSTRING data in the C file contains 361 bytes (including \0); L3 in the
assembly output stops at 256 and then appends $0. The the 256-byte limit
for string literals lies in hcc. I was a beta tester and knew about it in
1988. I assumed a caveat had made its way into the docs ... but I just
checked and sure enough, it didn't.

#include <stdio.h>
#define LONGSTRING \
"123456789012345678901234567890123456789012345678901234567890\
123456789012345678901234567890123456789012345678901234567890\
123456789012345678901234567890123456789012345678901234567890\
123456789012345678901234567890123456789012345678901234567890\
123456789012345678901234567890123456789012345678901234567890\
123456789012345678901234567890123456789012345678901234567890"
main()
	{
	puts(LONGSTRING);
	}

	.data
L3:	.dc.b	$31,$32,$33,$34,$35,$36,$37,$38,$39,$30,$31
	.dc.b	$32,$33,$34,$35,$36,$37,$38,$39,$30,$31,$32,$33,$34,$35,$36,$37
	.dc.b	$38,$39,$30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$30,$31,$32
	.dc.b	$33,$34,$35,$36,$37,$38,$39,$30,$31,$32,$33,$34,$35,$36,$37,$38
	.dc.b	$39,$30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$30,$31,$32,$33
	.dc.b	$34,$35,$36,$37,$38,$39,$30,$31,$32,$33,$34,$35,$36,$37,$38,$39
	.dc.b	$30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$30,$31,$32,$33,$34
	.dc.b	$35,$36,$37,$38,$39,$30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$30
	.dc.b	$31,$32,$33,$34,$35,$36,$37,$38,$39,$30,$31,$32,$33,$34,$35
	.dc.b	$36,$37,$38,$39,$30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$30,$31
	.dc.b	$32,$33,$34,$35,$36,$37,$38,$39,$30,$31,$32,$33,$34,$35,$36
	.dc.b	$37,$38,$39,$30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$30,$31,$32
	.dc.b	$33,$34,$35,$36,$37,$38,$39,$30,$31,$32,$33,$34,$35,$36,$37
	.dc.b	$38,$39,$30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$30,$31,$32,$33
	.dc.b	$34,$35,$36,$37,$38,$39,$30,$31,$32,$33,$34,$35,$36,$37,$38
	.dc.b	$39,$30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$30,$31,$32,$33,$34
	.dc.b	$35,$36,$37,$38,$39,$30,$31,$32,$33,$34,$35,$36
	.dc.b	0
	.text
	.globl	_main
_main:
	link	a6,#0
	move.l	#L3,-(sp)
	jsr	_puts
	addq.w	#4,sp
	unlk	a6
	rts

-- 
   Steve Yelvington at the lake in Minnesota
   steve@thelake.mn.org 

   "Heavier-than-air flying machines are impossible." - Lord Kelvin