Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

snprintf behaviour different from the standard #28

Open
jaybh opened this issue Nov 5, 2014 · 1 comment
Open

snprintf behaviour different from the standard #28

jaybh opened this issue Nov 5, 2014 · 1 comment

Comments

@jaybh
Copy link

jaybh commented Nov 5, 2014

Precision modifier when used with %s, should not pad the result with spaces. However, it does in the little kernel library.

char *temp  = “hello”;
char result[20];
snprintf (result, sizeof(result), “%.10s”, temp); // Notice the dot after the % sign
printf(“%s\n”, result);
Expected output

hello

Observed output

     hello

In essense, snprintf is padding spaces when it should not be with a precision modifier used with strings.
At least, it doesn’t on my Ubuntu 12.04 x86_64 system, and also shouldn’t according to the man page.

@travisg
Copy link
Member

travisg commented Nov 5, 2014

Yeah, it doesn't handle . precision specifiers. It's something I've been meaning to work on, thanks for reminding me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants