[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] Re: sprintf
From: |
David Brown |
Subject: |
[avr-gcc-list] Re: sprintf |
Date: |
Fri, 27 Feb 2009 22:10:16 +0100 |
User-agent: |
Thunderbird 2.0.0.19 (Windows/20081209) |
David VanHorn wrote:
> I solved my problem by inserting the null with
> memset((A_String+16), 0, 1); and the same for B_String.
A_String[16] = 0;
would be a much more efficient way of performing the same operation.
Interesting.. I would expect this to result in a loop writing out a
bunch of zeroes.
I'm going to play with this some more tomorrow when I'm not tired, and
see if I can make sense of how the strings are getting munged.
It makes sense to plant the trailing zero on every write by sprintf, and
that does seem to fit with the symptoms.
I was thinking that it was ONLY writing the char I gave it.
There is nothing in the code that you posted so far to indicate that
sprintf or memset are remotely sane ways to write this code. The code:
sprintf((A_String + i), "%c", 0xff)
has exactly the same effect as:
A_String[i] = 0xff;
A_String[i + 1] = 0x00;
delay_about_1000_processor_cycles();
waste_about_2000_bytes_of_code_space();
and
memset((A_String + 16), 0, 1);
has the same effect as :
A_String[16] = 0x00;
delay_about_30_processor_cycles();
waste_about_80_bytes_of_code_space();
My estimates might be a bit off, but you get the idea.
And again, if you want help, post the actual code, including relevant
function and variable declarations, and required standard #includes.
For example, if you had given us the definition of A_String, we could
tell you if there is a buffer overflow in your code. If I can take your
code, cut and paste it into a C file, and compile it myself, then I can
give much more useful advice.
mvh.,
David
- [avr-gcc-list] sprintf, David VanHorn, 2009/02/26
- Re: [avr-gcc-list] sprintf, Dave Hylands, 2009/02/26
- Re: [avr-gcc-list] sprintf, David VanHorn, 2009/02/26
- [avr-gcc-list] Re: sprintf,
David Brown <=
- Re: [avr-gcc-list] Re: sprintf, Vincent Trouilliez, 2009/02/27
- Re: [avr-gcc-list] Re: sprintf, David VanHorn, 2009/02/27
- Re: [avr-gcc-list] Re: sprintf, Vincent Trouilliez, 2009/02/27
- Re: [avr-gcc-list] Re: sprintf, David VanHorn, 2009/02/27
- Re: [avr-gcc-list] Re: sprintf, David Kelly, 2009/02/27
- Re: [avr-gcc-list] Re: sprintf, Russell Shaw, 2009/02/28
- [avr-gcc-list] Re: sprintf, David Brown, 2009/02/28
- Re: [avr-gcc-list] Re: sprintf, David VanHorn, 2009/02/28
- Re: [avr-gcc-list] Re: sprintf, David Kelly, 2009/02/27
- Re: [avr-gcc-list] Re: sprintf, David VanHorn, 2009/02/27