Skip to content
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: 2 additions & 0 deletions src/libmongoc/src/mongoc/mongoc-config-private.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
// clang-format off

// MONGOC_CXX_COMPILER_ID identifies the (optional) C++ compiler detected by CMake.
// Set to "" to if no check attempted.
// Set to "Unknown" if check attempted and no C++ compiler was found.
#define MONGOC_CXX_COMPILER_ID "@MONGOC_CXX_COMPILER_ID@"
#define MONGOC_CXX_COMPILER_VERSION "@MONGOC_CXX_COMPILER_VERSION@"

Expand Down
8 changes: 7 additions & 1 deletion src/libmongoc/src/mongoc/mongoc-handshake.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,11 +491,17 @@ _set_compiler_info(mongoc_handshake_t *handshake)
mcommon_string_append_printf(&append, " %s", MONGOC_COMPILER_VERSION);
#endif

mcommon_string_append(&append, " CXX=" MONGOC_CXX_COMPILER_ID);
#ifdef MONGOC_CXX_COMPILER_ID
if (0 != strlen(MONGOC_CXX_COMPILER_ID)) {
Copy link
Contributor

@eramongodb eramongodb Dec 16, 2025

Choose a reason for hiding this comment

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

Prior code permitted MONGOC_CXX_COMPILER_ID to be undefined:

" CXX=" MONGOC_CXX_COMPILER_ID // -> " CXX="

This call to strlen() must either support a similar pattern:

if (0 != strlen("" MONGOC_CXX_COMPILER_ID)) { ... }

or be guarded by an ifdef:

#ifdef MONGOC_CXX_COMPILER_ID
   if (0 != strlen(MONGOC_CXX_COMPILER_ID)) { ... }
#endif

Copy link
Collaborator Author

@kevinAlbs kevinAlbs Dec 16, 2025

Choose a reason for hiding this comment

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

Updated as suggested. I expect MONGOC_CXX_COMPILER_ID is always defined after configuring mongoc-config-private.h.in. But this might avoid the risk of breaking consumers if they bring-their-own mongoc-config-private.h.

MONGOC_CXX_COMPILER_VERSION is updated for consistency.

mcommon_string_append(&append, " CXX=" MONGOC_CXX_COMPILER_ID);
}
#endif

#ifdef MONGOC_CXX_COMPILER_VERSION
if (0 != strlen(MONGOC_CXX_COMPILER_VERSION)) {
mcommon_string_append(&append, " " MONGOC_CXX_COMPILER_VERSION);
}
#endif

handshake->compiler_info = mcommon_string_from_append_destroy_with_steal(&append);
}
Expand Down