Skip to content

Commit 0e800cf

Browse files
committed
CDRIVER-5826 Fix result of bson_strerror_r on macOS (#1807)
1 parent 2c4dd75 commit 0e800cf

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/libbson/src/bson/bson-error.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ bson_strerror_r (int err_code, /* IN */
130130
// required) by the POSIX spec (see:
131131
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/strerror.html#tag_16_574_08).
132132
(void) strerror_r (err_code, buf, buflen);
133+
ret = buf;
133134
#elif defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 700
134135
// The behavior (of `strerror_l`) is undefined if the locale argument to
135136
// `strerror_l()` is the special locale object LC_GLOBAL_LOCALE or is not a

src/libbson/tests/test-bson-error.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,20 @@ test_bson_error_basic (void)
3030
ASSERT_CMPUINT32 (error.code, ==, 456u);
3131
}
3232

33+
static void
34+
test_bson_strerror_r (void)
35+
{
36+
FILE *f = fopen ("file-that-does-not-exist", "r");
37+
ASSERT (!f);
38+
char errmsg_buf[BSON_ERROR_BUFFER_SIZE];
39+
char *errmsg = bson_strerror_r (errno, errmsg_buf, sizeof errmsg_buf);
40+
// Check a message is returned. Do not check platform-dependent contents:
41+
ASSERT (errmsg);
42+
}
3343

3444
void
3545
test_bson_error_install (TestSuite *suite)
3646
{
3747
TestSuite_Add (suite, "/bson/error/basic", test_bson_error_basic);
48+
TestSuite_Add (suite, "/bson/strerror_r", test_bson_strerror_r);
3849
}

0 commit comments

Comments
 (0)