Mail Archives: cygwin/2000/06/28/22:46:28
------_=_NextPart_001_01BFE174.1DCE6FEC
Content-Type: text/plain;
charset="iso-8859-1"
Hi all,
I think there is a bug with sprintf in 1.1.2. The following is the
code snippet that reproduces the bug:
int
maint(int argc, char *argv[])
{
char buf[256];
double dbl = 0.0;
sprintf(buf, "%4.3e\n", dbl);
printf("%s", buf); /* buf contains garbage characters. */
return;
}
It seems if you have a non-zero value after the dot in the format,
then sprintf includes that many garbage characters. In the above case,
there are 3 garbage characters.
--jc
--
jimen AT adtech-inc DOT com Adtech, Inc. (808) 734-3300
------_=_NextPart_001_01BFE174.1DCE6FEC
Content-Type: text/html;
charset="iso-8859-1"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2650.12">
<TITLE>sprintf bug</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=2>Hi all,</FONT>
</P>
<P><FONT SIZE=2>I think there is a bug with sprintf in 1.1.2. The following is the</FONT>
<BR><FONT SIZE=2>code snippet that reproduces the bug:</FONT>
</P>
<P><FONT SIZE=2>int</FONT>
<BR><FONT SIZE=2>maint(int argc, char *argv[])</FONT>
<BR><FONT SIZE=2>{</FONT>
<BR><FONT SIZE=2> char buf[256];</FONT>
<BR><FONT SIZE=2> double dbl = 0.0;</FONT>
</P>
<P><FONT SIZE=2> sprintf(buf, "%4.3e\n", dbl);</FONT>
<BR><FONT SIZE=2> printf("%s", buf); /* buf contains garbage characters. */</FONT>
</P>
<P><FONT SIZE=2> return;</FONT>
<BR><FONT SIZE=2>}</FONT>
</P>
<P><FONT SIZE=2>It seems if you have a non-zero value after the dot in the format,</FONT>
<BR><FONT SIZE=2>then sprintf includes that many garbage characters. In the above case,</FONT>
<BR><FONT SIZE=2>there are 3 garbage characters.</FONT>
</P>
<P><FONT SIZE=2>--jc</FONT>
<BR><FONT SIZE=2>--</FONT>
<BR><FONT SIZE=2>jimen AT adtech-inc DOT com Adtech, Inc. (808) 734-3300</FONT>
</P>
</BODY>
</HTML>
------_=_NextPart_001_01BFE174.1DCE6FEC--
- Raw text -