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

realname() (former user()) is broken on Windows #15

Closed
Vlad-Shcherbina opened this issue Jun 24, 2020 · 0 comments · Fixed by #16
Closed

realname() (former user()) is broken on Windows #15

Vlad-Shcherbina opened this issue Jun 24, 2020 · 0 comments · Fixed by #16

Comments

@Vlad-Shcherbina
Copy link
Contributor

To reproduce, run the following program:

// [dependencies]
// whoami = "0.8.1"
fn main() {
    whoami::user();
}

or

// whoami = trunk
fn main() {
    whoami::realname();
}

It fails:

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `16`,
 right: `15`

The assertion is here: https://github.com/libcala/whoami/blob/14f0e4a4cebb5debf7284da5b83152689161857c/src/windows.rs#L149

This happens because realname_os() is copy-pasted from username_os(), with GetUserNameW replaced with GetUserNameExW. But unlike GetUserNameW, GetUserNameExW on success returns the number of characters NOT counting the null terminator.

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 a pull request may close this issue.

1 participant