This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Same post from Internet Explorer:
I'm using CCS 3.3.38.2 with DM6437. I'm using standard C64+ libraries (I already saw unexpected behavior of miniprintf library) and compile project with C mode. This code gives me wrong results:
char buf[256], buf2[256];
char *ptr = (char*)0;
int test = snprintf(buf, sizeof(buf),
"%.*s123456789",
0,
ptr);
ptr = (char*)0x04000000;
test = snprintf(buf2, sizeof(buf2),
"%.*s123456789",
0,
ptr);
printf("buf: %s\r\n", buf);
printf("buf2: %s\r\n", buf2);
This gives me buf different from buf2, buf is starting with additional NULL char. Other compilers I tested give correct results.
Could anyone confirm this problem?
Are there any alternative libraries (except for miniprintf)?
I was able to reproduce this on a DM6437 EVM (output below), it looks like this is probably a bug in the run time support library (RTS). I would have expected the %.*s to print no characters and thus whatever ptr pointed to should be ignored which appears to not be the case.
buf:
buf2: 123456789
I will submit this to our software team for consideration as a bug, in the mean time if you wanted to dig into this yourself you can find the source for the run time support library in C:\CCStudio_v3.3\C6000\cgtools\lib\rts.src. Unfortunately I do not know of any alternate libraries for the snprintf function, the alternate for printf would be the BIOS function LOG_printf.
Thanks for quick reply and suggestion.
I modified _printfi.c file, I think
/*------------------------------------------------------------------------*/
/* Handle NULL strings. */
/*------------------------------------------------------------------------*/
if (strbuf == NULL)
{
if (pfield->precision > 0) //<<<< added <<<<<
_outc('\0', _op);
return;
}
should do the trick.
Another question: where could I find default options used to compile RTS shipped with CCS? I see them in spru187g.pdf, but they dissapeared from newer versions. I can't find them using google or TI keyword search with "mk6x" keyword. Libraries I rebuilt (ar6x using 'r' option and replacing only _printfi.obj) have slightly different sizes than shipped with CCS.
In this case you probably want to look at the SPRU187 version that is included with your CCS, probably C:\CCStudio_v3.3\docs\PDF\spru187n.pdf. Chances are it was built using "mk6x -o -mo --RTS -mv64+ rts.src -l rts64plus.lib". In the latest compiler releases for 6.1 the build method for the RTS changed so it no longer uses mk6x but rather a perl script, and when they make a new version of SPRU187 it overwrites the old SPRU187 on our web site, which is why there is no reference to mk6x in the current SPRU187o.
Just another FYI on this, it turns out this bug was submitted a while ago under the number SDSCM00024893 and it was fixed in CGT 6.0.19, so if future users do not want to modify their RTS they can use the 6.0.19 or newer toolset.
Just FYI - bug still exists in cgtools 6.1.7. Also my patch had to be corrected - there was risk of reading one byte from address when unitialized pointer pointed (I'm using custom string-like type with buffer pointer and length, precision = length should be checked in first place, buffer pointer often can be unitialized).
I can confirm that this is still happening in the newer CGT based on your test case, I believe we improperly identified the issue you pointed out as belonging to this bug. There is investigation going on internally to determine how best to handle this, it may end up as another new bug #. Thank you for pointing this out.
I'm using now
/*------------------------------------------------------------------------*/
/* Handle NULL strings. */
/*------------------------------------------------------------------------*/
if (pfield->precision == 0)
return;
if (strbuf == NULL)
{
_outc('\0', _op);
return;
}