Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!casbah.acns.nwu.edu!nucsrl!igloo!ddsw1!olsa99!zeusa!hendrik From: hendrik@zeusa.UUCP (Hendrik Vermooten) Newsgroups: comp.lang.c Subject: Re: New 'n' Improved comp.lang.c FAQ List Summary: Another bug Message-ID: <906@zeusa.UUCP> Date: 6 Apr 91 09:42:35 GMT References: <910401.0xf001@etiquette.uu.net> <1991Apr1.203024.19679@unlv.edu> Organization: ZEUS software, Verwoerdburg Lines: 24 In article <1991Apr1.203024.19679@unlv.edu>, grover@big-joe.cs.unlv.edu (Kevin Grover) writes: > > [misc deleted. . .] > > Q: Why doesn't this function work: > > > > char *itoa(int i) > > { > > static char retbuf[5]; /* biggest int: 32769 */ > > sprintf("%d", retbuf, i); > > return retbuf; > > } WOW! char retbuf[5]; /* biggest int: 32769 */ Watch it: 5 isn't enough; what about -32767 followed by a '\0': it has to be char retbuf[7]; Maybe this is a way of teaching beginning C users how C can overwrite the local stack frame and make a DOS machine freeze up and a UNIX box coredump :-) -- -------------------------------------------------------------------------- Hendrik Vermooten, ZEUS software TEL +27 12 64-5507, FAX +27 12 64-8382 Bang: ..!uunet!ddsw1!olsa99!zeusa!hendrik or hendrik@zeusa.UUCP --------------------------------------------------------------------------