Usenet comp.os.linux.alpha (1997-2013)
 help / color / mirror / Atom feed
From: U.V. Ravindra <uvr@usa.net>
Subject: Re: sprintf bug?
Date: 2000/05/26	[thread overview]
Message-ID: <8gmp47$p5t$1@nnrp1.deja.com> (raw)
In-Reply-To: 8gmilh$kcj$1@nnrp1.deja.com

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1330 bytes --]

Andreas Kahari <andkaha@my-deja.com> wrote:
>   U.V. Ravindra <uvr@usa.net> wrote:
> >
> > I'm using SuSE 6.3 (Kernel 2.2.13 glibc 2.1.2) on an Alpha EV67.
> >
> > 	char buffr[4096+1]
> >
> > 	...
> > 	...
> > 	printf("before %s\n", buffr);
> > 	sprintf(buffr, "0, 0, 0, ");
> > 	printf("after %s\n", buffr);
> >
> > And I see the output:
> >
> > before dwki_nr_ibind(100, fname_var, 0,
> > after 0, 0, 0,i
> >

<snip>

> It seems to me that you're only using 'sprintf' to copy a string into
> an array of characters. Why don't you use 'strcpy', 'memcpy', or a
> simple loop instead?

Actually, in my actual program, the "0, 0, 0, " is being printed
from a function call as
	sprintf(buffr, "%d, %d, %d, ", fx1(), var_1, fx2());
But I have managed to debug the problem to the point where I know
what really is happening here.  The 'i' is a remainder from the
previous contents of the string, which indicates that sprintf
isn't putting the \0 where it should.

-Ravindra

> But I agree, it looks strange... The 'i' should have been '\0' (or
> "<space>\0").
>
> /A
>
> --
> # Andreas K�h�ri, <URL:http://hello.to/andkaha/>.
> # All junk e-mail is reported to the
> # appropriate authorities, no exceptions.
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>


Sent via Deja.com http://www.deja.com/
Before you buy.



  reply	other threads:[~2000-05-26  4:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-05-26  4:00 sprintf bug? U.V. Ravindra
2000-05-26  4:00 ` Andreas Kahari
2000-05-26  4:00   ` U.V. Ravindra [this message]
2000-05-27  4:00     ` Tony Hammitt
2000-05-27  4:00 ` Harlan Grove
2000-05-27  4:00   ` sandrews
2000-05-28  4:00     ` Tony Hammitt
2000-05-27  4:00 ` Juergen Heinzl
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox