Jump to content
Sign in to follow this  
Neil

Libc Source Typo In Sprintf

Recommended Posts

Hi

 

I found that both sprintf and sprintf32 contain the code fragment

 

			// Next character if valid digit indicates field width
		unsigned char fieldWidth = 0;
		while( c > '0' && c <= '9' )
		{			
			fieldWidth *= 10;
			fieldWidth += c;
			fieldWidth -= '0';				
			c = format[fi++]; // read next string format character
			if ( !c ) goto end; // end of format string reached
		}

 

Which I think should be

 

			// Next character if valid digit indicates field width
		unsigned char fieldWidth = 0;
		while( c >= '0' && c <= '9' )
		{			
			fieldWidth *= 10;
			fieldWidth += c;
			fieldWidth -= '0';				
			c = format[fi++]; // read next string format character
			if ( !c ) goto end; // end of format string reached
		}

 

 

Note the c > '0' is now c >= '0'.

 

With the original code if you do %f10.2 for example, the width is set to 1 as the zero is ignored

 

 

Neil

 

OS XPpro, BoostC++ 6.90, PIC18f8722

Share this post


Link to post
Share on other sites

Thanks for reporting. Now fixed. Fix will be available in the next release.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...