UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Visitor raiatea
Visitor
410 Views
Registered: ‎06-01-2015

xil_printf source code error ?

Hello,

I looked at the source code of xil_printf and found two strange things:

 

1) dangerous and may be interpretated as careless coding, all the rest of the code is now suspicious.

line 292

		if(ctrl != NULL) {
			ch = *ctrl;
		}
		else {
			ch = *ctrl;
                } 

2) could someone explain the use of the following code ? If it is useless it may be removed to reduce the size of the elf.

// lines starting with // are my own
// ctrl is a pointer to the current character in the format string
while ((ctrl != NULL) && (*ctrl != (char8)0)) { /* move format string chars to buffer until a */ // there is no buffer /* format control is found. */ // the output is direct if (*ctrl != '%') { outbyte(*ctrl); ctrl += 1; continue; } // here we exit a while *ctrl != '%', now *ctrl == '%', we are in a % format part if(ctrl != NULL) { ctrl += 1; } if(ctrl != NULL) { // next character after '%' ch = *ctrl; } switch (tolower((s32)ch)) { case '\\': // if format is '\', new to me switch (*ctrl) { // read again the same character: this looks like an error case 'r': // supposed to be reached when the string is %\\r outbyte( ((char8)0x0D)); break; case 'n': // supposed to be reached when the string is %\\n outbyte( ((char8)0x0D)); outbyte( ((char8)0x0A)); break; } ctrl += 1; // next character, error too late break;

The cases 'r' and 'n', supposed to be reached for '\r' and '\n' are in fact reached only for "%\\r" and "%\\n", and the compiler stores "\\" as '\'.

An error is that the switch is done twice on '\', ctrl should be incremented before the switch(*ctrl).

 

Anyway the ascii for CR '\r' is not stored by the compiler as two characters '\' and 'r' but as 0x0D, for LF '\n' it is 0x0A.

The % format syntax does not support any '\' code, or does it ?

 

The codes 0D and 0A are output in the first while loop. The tests after a '%' for a '\' seems useless and may be removed.

 

If I'm right, this code may need some clarification.

 

Regards

0 Kudos
1 Reply
Moderator
Moderator
344 Views
Registered: ‎10-06-2016

Re: xil_printf source code error ?

Hi @raiatea,

 

Thanks for repoting this out, I will provide the informatino to the developers so they can take a look.

 

Regards

Ibai


Ibai
Don’t forget to reply, kudo, and accept as solution.
0 Kudos