Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Properly pass wchar * type to giterr_set #4014

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

Merged
merged 2 commits into from
Dec 7, 2016
Merged

Properly pass wchar * type to giterr_set #4014

merged 2 commits into from
Dec 7, 2016

Conversation

bokic
Copy link
Contributor

@bokic bokic commented Nov 20, 2016

Ensure correct type is passed, no garbage text is sent, and mute compiler warning.

@@ -174,7 +174,7 @@ GIT_INLINE(int) git_win32__file_attribute_to_stat(
/* st_size gets the UTF-8 length of the target name, in bytes,
* not counting the NULL terminator */
if ((st->st_size = git__utf16_to_8(NULL, 0, target)) < 0) {
giterr_set(GITERR_OS, "Could not convert reparse point name for '%s'", path);
giterr_set(GITERR_OS, "Could not convert reparse point name for '%S'", path);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

IIRC, %S means that the argument should have the opposite size of the format string. So for the narrow printf family of functions, %S is a wchar_t * and for the Unicode/wide wprintf family of functions, %S is a narrow char *. Is my memory correct here?

If so, can we change this to %ls which (again, IIRC) indicates a wide string always, regardless of whether you're feeding it to printf or wprintf.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checked with MinGW 5.3.0, and, you are right. %S seem to reverse the character width.

So, yes %ls format is better for this case.

@ethomson
Copy link
Member

ethomson commented Dec 7, 2016

Thanks! 😀

@ethomson ethomson merged commit 1576973 into libgit2:master Dec 7, 2016
@carlosmn carlosmn mentioned this pull request Dec 10, 2016
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

Successfully merging this pull request may close these issues.

2 participants