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

Use snprintf in pal_icushim.c #92452

Merged
merged 3 commits into from
Sep 23, 2023
Merged
Changes from 2 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
28 changes: 15 additions & 13 deletions src/native/libs/System.Globalization.Native/pal_icushim.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ FOR_ALL_ICU_FUNCTIONS

#define MaxICUVersionStringLength 33

#else

#define VERSION_PREFIX_NONE ""
#define VERSION_PREFIX_SUSE "suse"

// .[suse]x.x.x, considering the max number of decimal digits for each component
#define MaxICUVersionStringLength (sizeof(VERSION_PREFIX_SUSE) + 33)

#endif

static void* libicuuc = NULL;
Expand All @@ -44,7 +52,7 @@ ucol_safeClone_func ucol_safeClone_ptr = NULL;

#define PER_FUNCTION_BLOCK(fn, lib, required) \
c_static_assert_msg((sizeof(#fn) + MaxICUVersionStringWithSuffixLength + 1) <= sizeof(symbolName), "The symbolName is too small for symbol " #fn); \
sprintf(symbolName, #fn "%s", symbolVersion); \
snprintf(symbolName, SYMBOL_NAME_SIZE, #fn "%s", symbolVersion); \
fn##_ptr = (TYPEOF(fn)*)dlsym(lib, symbolName); \
if (fn##_ptr == NULL && required) { fprintf(stderr, "Cannot get symbol %s from " #lib "\nError: %s\n", symbolName, dlerror()); abort(); }

Expand All @@ -55,24 +63,24 @@ static int FindSymbolVersion(int majorVer, int minorVer, int subVer, char* symbo
if (dlsym(libicuuc, "u_strlen") == NULL)
{
// Now try just the _majorVer added
sprintf(symbolVersion, "_%d%s", majorVer, suffix);
sprintf(symbolName, "u_strlen%s", symbolVersion);
snprintf(symbolVersion, MaxICUVersionStringWithSuffixLength, "_%d%s", majorVer, suffix);
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved
snprintf(symbolName, SYMBOL_NAME_SIZE, "u_strlen%s", symbolVersion);
if (dlsym(libicuuc, symbolName) == NULL)
{
if (minorVer == -1)
return false;

// Now try the _majorVer_minorVer added
sprintf(symbolVersion, "_%d_%d%s", majorVer, minorVer, suffix);
sprintf(symbolName, "u_strlen%s", symbolVersion);
snprintf(symbolVersion, MaxICUVersionStringWithSuffixLength, "_%d_%d%s", majorVer, minorVer, suffix);
snprintf(symbolName, SYMBOL_NAME_SIZE, "u_strlen%s", symbolVersion);
if (dlsym(libicuuc, symbolName) == NULL)
{
if (subVer == -1)
return false;

// Finally, try the _majorVer_minorVer_subVer added
sprintf(symbolVersion, "_%d_%d_%d%s", majorVer, minorVer, subVer, suffix);
sprintf(symbolName, "u_strlen%s", symbolVersion);
snprintf(symbolVersion, MaxICUVersionStringWithSuffixLength, "_%d_%d_%d%s", majorVer, minorVer, subVer, suffix);
snprintf(symbolName, SYMBOL_NAME_SIZE, "u_strlen%s", symbolVersion);
if (dlsym(libicuuc, symbolName) == NULL)
{
return false;
Expand Down Expand Up @@ -214,12 +222,6 @@ static int FindICULibs(char* symbolName, char* symbolVersion)

#else // !TARGET_WINDOWS && !TARGET_OSX && !TARGET_ANDROID

#define VERSION_PREFIX_NONE ""
#define VERSION_PREFIX_SUSE "suse"

// .[suse]x.x.x, considering the max number of decimal digits for each component
#define MaxICUVersionStringLength (sizeof(VERSION_PREFIX_SUSE) + 33)

// Version ranges to search for each of the three version components
// The rationale for major version range is that we support versions higher or
// equal to the version we are built against and less or equal to that version
Expand Down