From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 111c93,c1db52110ef2b04a X-Google-Attributes: gid111c93,public X-Google-Thread: 1103af,c1db52110ef2b04a X-Google-Attributes: gid1103af,public From: Tony Hammitt Subject: Re: sprintf bug? Date: 2000/05/27 Message-ID: <392F4B37.88818C54@kc.rr.com>#1/1 X-Deja-AN: 627842878 Content-Transfer-Encoding: 8bit References: <8gmhrd$jqj$1@nnrp1.deja.com> <8gmilh$kcj$1@nnrp1.deja.com> <8gmp47$p5t$1@nnrp1.deja.com> X-Accept-Language: en Content-Type: text/plain; charset=iso-8859-1 X-Complaints-To: abuse@rr.com X-Trace: typhoon.kc.rr.com 959400762 24.94.177.44 (Fri, 26 May 2000 23:12:42 CDT) MIME-Version: 1.0 Reply-To: thammitt@kc.rr.com NNTP-Posting-Date: Fri, 26 May 2000 23:12:42 CDT Newsgroups: comp.os.linux.alpha,comp.os.linux.misc 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 wrote: > > U.V. Ravindra 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 > > > > > > > > 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 > > "\0"). > > > > /A > > > > -- > > # Andreas K�h�ri, . > > # 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.