Usenet comp.os.linux.alpha (1997-2013)
 help / color / mirror / Atom feed
* sprintf bug?
@ 2000-05-26  4:00 U.V. Ravindra
  2000-05-26  4:00 ` Andreas Kahari
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: U.V. Ravindra @ 2000-05-26  4:00 UTC (permalink / raw)




I'm using SuSE 6.3 (Kernel 2.2.13 glibc 2.1.2) on an Alpha EV67.
Here's what I'm trying  to do

	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

This is clearly wrong - the 'i' at the end of the 'after'
output is extraneous.  I find that the call to sprintf
puts junk characters at the end of the string.  The problem
is random (in the sense that not all calls to sprintf
put junk characters in buffr), but consistent (in the sense
that it is the SAME sprintf call/s that exhibit this
erroneous behavior).

Anyone aware of a problem with glibc 2.1.2's sprintf?

Advance thanks for all answers.

UVR.



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



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: sprintf bug?
  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
  2000-05-27  4:00 ` Juergen Heinzl
  2000-05-27  4:00 ` Harlan Grove
  2 siblings, 1 reply; 8+ messages in thread
From: Andreas Kahari @ 2000-05-26  4:00 UTC (permalink / raw)


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

In article <8gmhrd$jqj$1@nnrp1.deja.com>,
  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.
> Here's what I'm trying  to do
>
> 	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
>
>

I don't have access to a Linux box right now and I can't reproduce your
result on my Solaris box.

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?

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.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: sprintf bug?
  2000-05-26  4:00 ` Andreas Kahari
@ 2000-05-26  4:00   ` U.V. Ravindra
  2000-05-27  4:00     ` Tony Hammitt
  0 siblings, 1 reply; 8+ messages in thread
From: U.V. Ravindra @ 2000-05-26  4:00 UTC (permalink / raw)


[-- 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.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: sprintf bug?
  2000-05-26  4:00 sprintf bug? U.V. Ravindra
  2000-05-26  4:00 ` Andreas Kahari
@ 2000-05-27  4:00 ` Juergen Heinzl
  2000-05-27  4:00 ` Harlan Grove
  2 siblings, 0 replies; 8+ messages in thread
From: Juergen Heinzl @ 2000-05-27  4:00 UTC (permalink / raw)


In article <8gmhrd$jqj$1@nnrp1.deja.com>, U.V. Ravindra wrote:
>
>
>I'm using SuSE 6.3 (Kernel 2.2.13 glibc 2.1.2) on an Alpha EV67.
>Here's what I'm trying  to do
>
>	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
[...]
You call printf() passing some junk and then expect
reasonable behaviour afterwards ? Good luck.
[...]

Ta',
Juergen

-- 
\ Real name     : J�rgen Heinzl                 \       no flames      /
 \ EMail Private : juergen@monocerus.demon.co.uk \ send money instead /



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: sprintf bug?
  2000-05-26  4:00   ` U.V. Ravindra
@ 2000-05-27  4:00     ` Tony Hammitt
  0 siblings, 0 replies; 8+ messages in thread
From: Tony Hammitt @ 2000-05-27  4:00 UTC (permalink / raw)


So, are the types of your functions that you are using in the
real sprintf() call known by the compiler to be signed int's?
If they are some other type, try changing the % escape to the
correct one.  If they are int's, try changing their type and
the % escape.

If that doesn't do anything (as I would expect), try
"for(i=0; i<4096; i++) buffr[i]=0;" before the sprint statement
to de-junk the buffer.

If all else fails, you could open a fifo, print to the pipe,
then read the value you printed into the buffer.  Yuck.  But
if sprintf is really broken, what can you do?

Can you describe the application a little?  Is it threaded?
Can you show the problem with < 50 lines of code total?  If
so, can you post it here?

Regards,

Tony Hammitt


"U.V. Ravindra" wrote:
> 
> 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.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: sprintf bug?
  2000-05-26  4:00 sprintf bug? U.V. Ravindra
  2000-05-26  4:00 ` Andreas Kahari
  2000-05-27  4:00 ` Juergen Heinzl
@ 2000-05-27  4:00 ` Harlan Grove
  2000-05-27  4:00   ` sandrews
  2 siblings, 1 reply; 8+ messages in thread
From: Harlan Grove @ 2000-05-27  4:00 UTC (permalink / raw)


In article <8gmhrd$jqj$1@nnrp1.deja.com>,
  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.
> Here's what I'm trying  to do
>
> 	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>

Looks like a bug, but one not shared by i386 Red Hat 6.0 at least.

Try storing sprintf()'s result in an integer variable and printing that
value. Is it 8 or 9?


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



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: sprintf bug?
  2000-05-27  4:00 ` Harlan Grove
@ 2000-05-27  4:00   ` sandrews
  2000-05-28  4:00     ` Tony Hammitt
  0 siblings, 1 reply; 8+ messages in thread
From: sandrews @ 2000-05-27  4:00 UTC (permalink / raw)


Harlan Grove wrote:
> 
> In article <8gmhrd$jqj$1@nnrp1.deja.com>,
>   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.
> > Here's what I'm trying  to do
> >
> >       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>
> 
> Looks like a bug, but one not shared by i386 Red Hat 6.0 at least.
> 

This is NOT a bug, buffr contains junk @ the first printf statement.

--
"You can open self extracting archives using PKZIP25.EXE 
  or unrar" - censored by Microsoft."
"You can unzip a self extracting .EXE with WinZip" -BANNED BY MICROSOFT"



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: sprintf bug?
  2000-05-27  4:00   ` sandrews
@ 2000-05-28  4:00     ` Tony Hammitt
  0 siblings, 0 replies; 8+ messages in thread
From: Tony Hammitt @ 2000-05-28  4:00 UTC (permalink / raw)


sandrews wrote:
> 
> Harlan Grove wrote:
> >
> > In article <8gmhrd$jqj$1@nnrp1.deja.com>,
> >   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.
> > > Here's what I'm trying  to do
> > >
> > >       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>
> >
> > Looks like a bug, but one not shared by i386 Red Hat 6.0 at least.
> >
> 
> This is NOT a bug, buffr contains junk @ the first printf statement.
> 
> --

What junk are you talking about?  There is something else in the
string before the sprintf statement, so what?  Lots of people use
the same buffer over and over again in a function.  It saves space
and speeds things up.

The string should be "0, 0, 0, " not "0, 0, 0,i".  The last space
is missing and other buffer contents were left in its place.  UVR
posted a code fragment, not the whole program.

This is most certainly a bug.

Regards,

Tony



> "You can open self extracting archives using PKZIP25.EXE
>   or unrar" - censored by Microsoft."
> "You can unzip a self extracting .EXE with WinZip" -BANNED BY MICROSOFT"



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2000-05-28  4:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2000-05-27  4:00     ` Tony Hammitt
2000-05-27  4:00 ` Juergen Heinzl
2000-05-27  4:00 ` Harlan Grove
2000-05-27  4:00   ` sandrews
2000-05-28  4:00     ` Tony Hammitt

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