| Issue 8: | sformatf(double) passes strange arguments to helper function on subsequent calls on arm7tdmi and crashes system, whereas sprintf() does not |
‹ Prev
8 of 8
|
| 1 person starred this issue and may be notified of changes. | Back to list |
What steps will reproduce the problem? 1. Replace sprintf() with sformatf(). 2. Call sformatf(&(str[strnlen(str, SD_BYTES_PER_SECTOR)]), "Lat = %2.9lf\n", Latitude); 3. **heap overflow** **exit called** What is the expected output? str contains (i.e.) "Lat = 32.133231521\n\0". You get this correct functionality if calls to sformatf are replaced by calls to sprintf() (newlib C lib v1.20). sprintf uses malloc however, which is not desired in an embedded system, so a fix is required. What do you see instead? **heap overflow** **exit called** (I believe this is sort of a generic C lib explosion notification, as format does not use the heap, nor do I). What version of the product are you using? On what operating system? Just got format out of svn again last week. OS is raw ARM7TDMI code that boots to main(). I've tried every possible permutation of the examples for sprintf, all seem to exhibit the same behaviour, leading me to believe that the problem is in the call to format(), not in the helper function. Also put calls to printf in the helper function, which showed that the helper function is called multiple times for each call to sformatf. The first call always looks appropriate, however, subsequent calls (only when floating point is used) tend to give addr's for the dest pointer that is not in the valid ram address space...
May 6, 2014
#1
bahamasf...@gmail.com
Jun 11, 2014
What about the call to strnlen()? Is "str" long enough to do the append without running past the end of the allocated space? It looks like you're trying to do a strncat() operation.
Jun 11, 2014
Note: the float code does use quite a few stack slots (maybe 40-50 words at a guess) so you need to allow for that in your stack allocation.
Jun 11, 2014
And if possible please provide a simple example in C (not C++.... horrible abomination of a language) that would help me track down the issue.
Oct 21, 2014
I wonder if this is because of the way varargs are passed in the ARM EABI? See the definition of CONFIG_VA_LIST_AS_ARRAY_TYPE in format_config.h. It might be worth trying forcing that flag set or clear and see what the outcome is.
Nov 20, 2014
Issue found in passing varargs on ARM with latest GCC. Now fixed with use of va_copy(), and no longer need per-platform fudging.
Status:
Fixed
|