delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2000/06/28/22:46:28

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sourceware DOT cygnus DOT com>
List-Archive: <http://sourceware.cygnus.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sourceware DOT cygnus DOT com>
List-Help: <mailto:cygwin-help AT sourceware DOT cygnus DOT com>, <http://sourceware.cygnus.com/ml/#faqs>
Sender: cygwin-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com
Message-ID: <B9906C3F4BB3D311A60F009027463EE991BC99@mgmgrand.adtech-inc.com>
From: "Jimen.Ching" <JChing AT adtech-inc DOT com>
To: cygwin AT sourceware DOT cygnus DOT com
Subject: sprintf bug
Date: Wed, 28 Jun 2000 16:45:32 -1000
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2650.21)

------_=_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.&nbsp; 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>&nbsp; char buf[256];</FONT>
<BR><FONT SIZE=2>&nbsp; double dbl = 0.0;</FONT>
</P>

<P><FONT SIZE=2>&nbsp; sprintf(buf, &quot;%4.3e\n&quot;, dbl);</FONT>
<BR><FONT SIZE=2>&nbsp; printf(&quot;%s&quot;, buf); /* buf contains garbage characters. */</FONT>
</P>

<P><FONT SIZE=2>&nbsp; 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.&nbsp; 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&nbsp;&nbsp;&nbsp;&nbsp; Adtech, Inc.&nbsp;&nbsp;&nbsp; (808) 734-3300</FONT>
</P>

</BODY>
</HTML>
------_=_NextPart_001_01BFE174.1DCE6FEC--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019