Skip to content

CDRIVER-6011 fix message of bson_strerror_r on Windows #2011

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 3 commits into from
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libbson/src/bson/bson-error.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ bson_strerror_r (int err_code, /* IN */
#if defined(_WIN32)
// Windows does not provide `strerror_l` or `strerror_r`, but it does
// unconditionally provide `strerror_s`.
if (strerror_s (buf, buflen, err_code) != 0) {
if (strerror_s (buf, buflen, err_code) == 0) {
ret = buf;
}
#elif defined(_AIX)
Expand Down
4 changes: 4 additions & 0 deletions src/libbson/tests/test-bson-error.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ test_bson_strerror_r (void)
char *errmsg = bson_strerror_r (errno, errmsg_buf, sizeof errmsg_buf);
// Check a message is returned. Do not check platform-dependent contents:
ASSERT (errmsg);
const char *unknown_msg = "Unknown error";
if (strstr (errmsg, unknown_msg)) {
test_error ("Expected error message to contain platform-dependent content, not: '%s'", errmsg);
}
}

void
Expand Down