From 131f7d18922950971015f7895941bcb041797c33 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 8 Feb 2024 13:27:07 -0800 Subject: [PATCH 1/7] Remove strtoul and strtoull PAL implementations --- src/coreclr/gc/unix/numasupport.cpp | 5 +- src/coreclr/inc/clrconfignocache.h | 8 +- src/coreclr/pal/inc/pal.h | 4 +- src/coreclr/pal/src/cruntime/string.cpp | 190 ------------------ src/coreclr/pal/src/include/pal/palinternal.h | 2 + src/coreclr/pal/tests/palsuite/CMakeLists.txt | 3 - .../palsuite/c_runtime/strtod/test1/test1.cpp | 92 --------- .../palsuite/c_runtime/strtod/test2/test2.cpp | 64 ------ .../c_runtime/strtoul/test1/test1.cpp | 71 ------- .../pal/tests/palsuite/compilableTests.txt | 3 - .../pal/tests/palsuite/paltestlist.txt | 3 - .../SignalObjectAndWaitTest.cpp | 4 +- .../StressLogAnalyzer/StressLogPlugin.cpp | 10 +- 13 files changed, 19 insertions(+), 440 deletions(-) delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/strtod/test1/test1.cpp delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/strtod/test2/test2.cpp delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/strtoul/test1/test1.cpp diff --git a/src/coreclr/gc/unix/numasupport.cpp b/src/coreclr/gc/unix/numasupport.cpp index 918d4816e9cddc..318a5daa35782c 100644 --- a/src/coreclr/gc/unix/numasupport.cpp +++ b/src/coreclr/gc/unix/numasupport.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -32,9 +33,9 @@ static int GetNodeNum(const char* path, bool firstOnly) if (strncmp(entry->d_name, "node", STRING_LENGTH("node"))) continue; - int nodeNum = strtoul(entry->d_name + STRING_LENGTH("node"), NULL, 0); + unsigned long nodeNum = strtoul(entry->d_name + STRING_LENGTH("node"), NULL, 0); if (result < nodeNum) - result = nodeNum; + result = nodeNum > INT_MAX ? INT_MAX : (int)nodeNum; if (firstOnly) break; diff --git a/src/coreclr/inc/clrconfignocache.h b/src/coreclr/inc/clrconfignocache.h index d15a566e9c989d..f75504a2289af0 100644 --- a/src/coreclr/inc/clrconfignocache.h +++ b/src/coreclr/inc/clrconfignocache.h @@ -41,8 +41,12 @@ class CLRConfigNoCache errno = 0; LPSTR endPtr; - result = strtoul(_value, &endPtr, radix); - bool fSuccess = (errno != ERANGE) && (endPtr != _value); + unsigned long rawResult = strtoul(_value, &endPtr, radix); + if ((DWORD)rawResult != rawResult || errno == ERANGE) + { + return false; + } + bool fSuccess = endPtr != _value; return fSuccess; } diff --git a/src/coreclr/pal/inc/pal.h b/src/coreclr/pal/inc/pal.h index 1a67e6203501f0..94f0fcf3833f7d 100644 --- a/src/coreclr/pal/inc/pal.h +++ b/src/coreclr/pal/inc/pal.h @@ -3982,8 +3982,6 @@ PAL_GetCurrentThreadAffinitySet(SIZE_T size, UINT_PTR* data); #define exit PAL_exit #define realloc PAL_realloc #define fopen PAL_fopen -#define strtoul PAL_strtoul -#define strtoull PAL_strtoull #define fprintf PAL_fprintf #define vfprintf PAL_vfprintf #define rand PAL_rand @@ -4084,7 +4082,7 @@ PALIMPORT char * __cdecl strpbrk(const char *, const char *); PALIMPORT char * __cdecl strstr(const char *, const char *); PALIMPORT char * __cdecl strtok_r(char *, const char *, char **); PALIMPORT int __cdecl atoi(const char *); -PALIMPORT ULONG __cdecl strtoul(const char *, char **, int); +PALIMPORT unsigned long __cdecl strtoul(const char *, char **, int); PALIMPORT ULONGLONG __cdecl strtoull(const char *, char **, int); PALIMPORT double __cdecl atof(const char *); PALIMPORT double __cdecl strtod(const char *, char **); diff --git a/src/coreclr/pal/src/cruntime/string.cpp b/src/coreclr/pal/src/cruntime/string.cpp index b66c3b20f53357..dd5245fd645260 100644 --- a/src/coreclr/pal/src/cruntime/string.cpp +++ b/src/coreclr/pal/src/cruntime/string.cpp @@ -103,193 +103,3 @@ _stricmp( PERF_EXIT(_stricmp); return ret; } - - -/*++ -Function: - PAL_strtoul - -Convert string to an unsigned long-integer value. - -Return Value - -strtoul returns the converted value, if any, or UINT32_MAX on -overflow. It returns 0 if no conversion can be performed. errno is -set to ERANGE if overflow or underflow occurs. - -Parameters - -szNumber Null-terminated string to convert to a ULONG -pszEnd Pointer to character that stops scan -nBase Number base to use - -Remarks - -strtoul stops reading the string szNumber at the first character it cannot -recognize as part of a number. This may be the terminating null -character, or it may be the first numeric character greater than or -equal to base. The LC_NUMERIC category setting of the current locale -determines recognition of the radix character in szNumber; for more -information, see setlocale. If pszEnd is not NULL, a pointer to the -character that stopped the scan is stored at the location pointed to -by pszEnd. If no conversion can be performed (no valid digits were -found or an invalid base was specified), the value of szNumber is stored -at the location pointed to by pszEnd. - -Notes : - MSDN states that only space and tab are accepted as leading whitespace, but - tests indicate that other whitespace characters (newline, carriage return, - etc) are also accepted. This matches the behavior on Unix systems. - - For strtoul, we need to check if the value to be returned - is outside the 32 bit range. If so, the returned value needs to be set - as appropriate, according to the MSDN pages and in all instances errno - must be set to ERANGE (The one exception is converting a string - representing a negative value to unsigned long). - Note that on 64 bit Windows, long's are still 32 bit. Thus, to match - Windows behavior, we must return long's in the 32 bit range. - --*/ - -/* The use of ULONG is by design, to ensure that a 32 bit value is always -returned from this function. If "unsigned long" is used instead of ULONG, -then a 64 bit value could be returned on 64 bit platforms like HP-UX, thus -breaking Windows behavior. */ -ULONG -__cdecl -PAL_strtoul(const char *szNumber, char **pszEnd, int nBase) -{ - unsigned long ulResult; - - PERF_ENTRY(strtoul); - ENTRY("strtoul (szNumber=%p (%s), pszEnd=%p, nBase=%d)\n", - szNumber?szNumber:"NULL", - szNumber?szNumber:"NULL", - pszEnd, - nBase); - - ulResult = strtoul(szNumber, pszEnd, nBase); - -#ifdef HOST_64BIT - if (ulResult > UINT32_MAX) - { - char ch = *szNumber; - while (isspace(ch)) - { - ch = *szNumber++; - } - /* If the string represents a positive number that is greater than - _UI32_MAX, set errno to ERANGE. Otherwise, don't set errno - to match Windows behavior. */ - if (ch != '-') - { - ulResult = UINT32_MAX; - errno = ERANGE; - } - } -#endif - - LOGEXIT("strtoul returning unsigned long %lu\n", ulResult); - PERF_EXIT(wcstoul); - - /* When returning unsigned long res from this function, it will be - implicitly cast to ULONG. This handles situations where a string that - represents a negative number is passed in to strtoul. The Windows - behavior is analogous to taking the binary equivalent of the negative - value and treating it as a positive number. Returning a ULONG from - this function, as opposed to native unsigned long, allows us to match - this behavior. The explicit cast to ULONG below is used to silence any - potential warnings due to the implicit casting. */ - return (ULONG)ulResult; - -} - -/*++ -Function: - PAL_strtoull - -Convert string to an unsigned long long-integer value. - -Return Value - -strtoull returns the converted value, if any, or UINT64_MAX on -overflow. It returns 0 if no conversion can be performed. errno is -set to ERANGE if overflow or underflow occurs. - -Parameters - -szNumber Null-terminated string to convert to a ULONGLONG -pszEnd Pointer to character that stops scan -nBase Number base to use - -Remarks - -strtoull stops reading the string szNumber at the first character it cannot -recognize as part of a number. This may be the terminating null -character, or it may be the first numeric character greater than or -equal to base. The LC_NUMERIC category setting of the current locale -determines recognition of the radix character in szNumber; for more -information, see setlocale. If pszEnd is not NULL, a pointer to the -character that stopped the scan is stored at the location pointed to -by pszEnd. If no conversion can be performed (no valid digits were -found or an invalid base was specified), the value of szNumber is stored -at the location pointed to by pszEnd. - -Notes : - MSDN states that only space and tab are accepted as leading whitespace, but - tests indicate that other whitespace characters (newline, carriage return, - etc) are also accepted. This matches the behavior on Unix systems. - - For strtoull, we need to check if the value to be returned - is outside the 64 bit range. If so, the returned value needs to be set - as appropriate, according to the MSDN pages and in all instances errno - must be set to ERANGE (The one exception is converting a string - representing a negative value to unsigned long). - --*/ - -/* The use of ULONGLONG is by design, to ensure that a 64 bit value is always -returned from this function. */ -ULONGLONG -__cdecl -PAL_strtoull(const char *szNumber, char **pszEnd, int nBase) -{ - unsigned long long ullResult; - - PERF_ENTRY(strtoull); - ENTRY("strtoull (szNumber=%p (%s), pszEnd=%p, nBase=%d)\n", - szNumber?szNumber:"NULL", - szNumber?szNumber:"NULL", - pszEnd, - nBase); - - ullResult = strtoull(szNumber, pszEnd, nBase); - - if (ullResult > UINT64_MAX) - { - char ch = *szNumber; - while (isspace(ch)) - { - ch = *szNumber++; - } - /* If the string represents a positive number that is greater than - UINT64_MAX, set errno to ERANGE. Otherwise, don't set errno - to match Windows behavior. */ - if (ch != '-') - { - ullResult = UINT64_MAX; - errno = ERANGE; - } - } - - LOGEXIT("strtoull returning unsigned long long %llu\n", ullResult); - PERF_EXIT(strtoull); - - /* When returning unsigned long long res from this function, it will be - implicitly cast to ULONGLONG. This handles situations where a string that - represents a negative number is passed in to strtoull. The Windows - behavior is analogous to taking the binary equivalent of the negative - value and treating it as a positive number. Returning a ULONGLONG from - this function, as opposed to native unsigned long long, allows us to match - this behavior. The explicit cast to ULONGLONG below is used to silence any - potential warnings due to the implicit casting. */ - return (ULONGLONG)ullResult; -} diff --git a/src/coreclr/pal/src/include/pal/palinternal.h b/src/coreclr/pal/src/include/pal/palinternal.h index 2193307d214527..5ba0a3364de214 100644 --- a/src/coreclr/pal/src/include/pal/palinternal.h +++ b/src/coreclr/pal/src/include/pal/palinternal.h @@ -182,6 +182,8 @@ function_name() to call the system's implementation #define strrchr DUMMY_strrchr #define strpbrk DUMMY_strpbrk #define strtod DUMMY_strtod +#define strtoul DUMMY_strtoul +#define strtoull DUMMY_strtoull #define strtok_r DUMMY_strtok_r #define tolower DUMMY_tolower #define toupper DUMMY_toupper diff --git a/src/coreclr/pal/tests/palsuite/CMakeLists.txt b/src/coreclr/pal/tests/palsuite/CMakeLists.txt index 2acc3f31b413d4..7f5bb8ae834909 100644 --- a/src/coreclr/pal/tests/palsuite/CMakeLists.txt +++ b/src/coreclr/pal/tests/palsuite/CMakeLists.txt @@ -196,9 +196,6 @@ add_executable_clr(paltests c_runtime/strpbrk/test1/test1.cpp c_runtime/strrchr/test1/test1.cpp c_runtime/strstr/test1/test1.cpp - c_runtime/strtod/test1/test1.cpp - c_runtime/strtod/test2/test2.cpp - c_runtime/strtoul/test1/test1.cpp c_runtime/tan/test1/test1.cpp c_runtime/tanf/test1/test1.cpp c_runtime/tanh/test1/test1.cpp diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/strtod/test1/test1.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/strtod/test1/test1.cpp deleted file mode 100644 index d5b6d0a66f6fb3..00000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/strtod/test1/test1.cpp +++ /dev/null @@ -1,92 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*===================================================================== -** -** Source: test1.c -** -** Purpose: Tests the PAL implementation of the strtod function. -** Convert a number of strings to doubles. Ensure they -** convert correctly. -** -** -**===================================================================*/ - -#include - - -struct testCase -{ - double CorrectResult; /* The returned double value */ - char ResultString[20]; /* The remainder string */ - char string[20]; /* The test string */ -}; - - -PALTEST(c_runtime_strtod_test1_paltest_strtod_test1, "c_runtime/strtod/test1/paltest_strtod_test1") -{ - - char * endptr; - double result; - int i; - - struct testCase testCases[] = - { - {1234,"","1234"}, - {-1234,"","-1234"}, - {1234.44,"","1234.44"}, - {1234e-5,"","1234e-5"}, - {1234e+5,"","1234e+5"}, - {12345E5,"","12345e5"}, - {1234.657e-8,"","1234.657e-8"}, - {1234567e-8,"foo","1234567e-8foo"}, - {999,"foo","999 foo"}, - {7,"foo"," 7foo"}, - {0,"a7","a7"}, - {-777777,"z zz","-777777z zz"} - }; - - /* - * Initialize the PAL - */ - if (0 != PAL_Initialize(argc,argv)) - { - return FAIL; - } - - /* Loop through the structure to test each case */ - for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) - { - result = strtod(testCases[i].string,&endptr); - - /* need to check the result and the endptr result */ - if ((testCases[i].CorrectResult != result) && - (strcmp(testCases[i].ResultString,endptr)!=0)) - { - Fail("ERROR: strtod returned %f instead of %f and " - "\"%s\" instead of \"%s\" for the test of \"%s\"\n", - result, - testCases[i].CorrectResult, - endptr, - testCases[i].ResultString, - testCases[i].string); - } - - } - - PAL_Terminate(); - return PASS; -} - - - - - - - - - - - - - diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/strtod/test2/test2.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/strtod/test2/test2.cpp deleted file mode 100644 index 038bbe07a1a117..00000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/strtod/test2/test2.cpp +++ /dev/null @@ -1,64 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*===================================================================== -** -** Source: test2.c -** -** Purpose: Tests strtod with overflows -** -** -**===================================================================*/ - -#include - -PALTEST(c_runtime_strtod_test2_paltest_strtod_test2, "c_runtime/strtod/test2/paltest_strtod_test2") -{ - /* Representation of positive infinty for a IEEE 64-bit double */ - INT64 PosInifity = (INT64)(0x7ff00000) << 32; - double HugeVal = *(double*) &PosInifity; - char *PosStr = "1E+10000"; - char *NegStr = "-1E+10000"; - double result; - - - if (PAL_Initialize(argc,argv)) - { - return FAIL; - } - - result = strtod(PosStr, NULL); - - if (result != HugeVal) - { - Fail("ERROR: wcstod interpreted \"%s\" as %g instead of %g\n", - PosStr, result, HugeVal); - } - - result = strtod(NegStr, NULL); - - if (result != -HugeVal) - { - Fail("ERROR: wcstod interpreted \"%s\" as %g instead of %g\n", - NegStr, result, -HugeVal); - } - - PAL_Terminate(); - - return PASS; -} - - - - - - - - - - - - - - - diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/strtoul/test1/test1.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/strtoul/test1/test1.cpp deleted file mode 100644 index c18b550d1e1441..00000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/strtoul/test1/test1.cpp +++ /dev/null @@ -1,71 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*============================================================================ -** -** Source: test1.c -** -** Purpose: -** Tests stroul with different bases and overflows, as well as valid input. -** Makes sure that the end pointer is correct. -** -** -**==========================================================================*/ - -#include - -char teststr1[] = "12345"; -char teststr2[] = "Z"; -char teststr3[] = "4294967295"; -char teststr4[] = "4294967296"; - -typedef struct -{ - char *str; - char *end; - int base; - ULONG result; -} TestCase; - -PALTEST(c_runtime_strtoul_test1_paltest_strtoul_test1, "c_runtime/strtoul/test1/paltest_strtoul_test1") -{ - TestCase TestCases[] = - { - { teststr1, teststr1 + 3, 4, 27}, - { teststr1, teststr1 + 5, 10, 12345}, - { teststr2, teststr2, 10, 0}, - { teststr3, teststr3+10, 10, 4294967295ul}, - { teststr4, teststr4+10, 10, 4294967295ul} - }; - - int NumCases = sizeof(TestCases) / sizeof(TestCases[0]); - - char *end; - ULONG l; - int i; - - if (PAL_Initialize(argc, argv)) - { - return FAIL; - } - - - for (i=0; i Date: Thu, 8 Feb 2024 13:38:59 -0800 Subject: [PATCH 2/7] Make _stricmp and family inlined wrappers around strcasecmp and family instead of full PAL implementations --- src/coreclr/pal/inc/pal.h | 14 ++- src/coreclr/pal/src/CMakeLists.txt | 1 - src/coreclr/pal/src/cruntime/string.cpp | 105 ------------------ src/coreclr/pal/src/cruntime/wchar.cpp | 4 +- src/coreclr/pal/src/include/pal/palinternal.h | 4 + src/coreclr/pal/tests/palsuite/CMakeLists.txt | 2 - .../c_runtime/_stricmp/test1/test1.cpp | 69 ------------ .../c_runtime/_strnicmp/test1/test1.cpp | 84 -------------- .../pal/tests/palsuite/compilableTests.txt | 2 - .../pal/tests/palsuite/paltestlist.txt | 2 - src/coreclr/utilcode/pedecoder.cpp | 2 +- 11 files changed, 19 insertions(+), 270 deletions(-) delete mode 100644 src/coreclr/pal/src/cruntime/string.cpp delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_stricmp/test1/test1.cpp delete mode 100644 src/coreclr/pal/tests/palsuite/c_runtime/_strnicmp/test1/test1.cpp diff --git a/src/coreclr/pal/inc/pal.h b/src/coreclr/pal/inc/pal.h index 94f0fcf3833f7d..5cf8825eabcb4e 100644 --- a/src/coreclr/pal/inc/pal.h +++ b/src/coreclr/pal/inc/pal.h @@ -4071,7 +4071,7 @@ PALIMPORT long long int __cdecl atoll(const char *) MATH_THROW_DECL; PALIMPORT size_t __cdecl strlen(const char *); PALIMPORT int __cdecl strcmp(const char*, const char *); PALIMPORT int __cdecl strncmp(const char*, const char *, size_t); -PALIMPORT int __cdecl _strnicmp(const char *, const char *, size_t); +PALIMPORT int __cdecl strncasecmp(const char *, const char *, size_t); PALIMPORT char * __cdecl strcat(char *, const char *); PALIMPORT char * __cdecl strncat(char *, const char *, size_t); PALIMPORT char * __cdecl strcpy(char *, const char *); @@ -4112,7 +4112,7 @@ PALIMPORT int remove(const char*); PALIMPORT DLLEXPORT errno_t __cdecl memcpy_s(void *, size_t, const void *, size_t) THROW_DECL; PALIMPORT errno_t __cdecl memmove_s(void *, size_t, const void *, size_t); -PALIMPORT DLLEXPORT int __cdecl _stricmp(const char *, const char *); +PALIMPORT DLLEXPORT int __cdecl strcasecmp(const char *, const char *); PALIMPORT char * __cdecl _gcvt_s(char *, int, double, int); PALIMPORT int __cdecl __iscsym(int); PALIMPORT DLLEXPORT int __cdecl _wcsicmp(const WCHAR *, const WCHAR*); @@ -4142,6 +4142,16 @@ PALIMPORT errno_t __cdecl _wcslwr_s(WCHAR *, size_t sz); PALIMPORT DLLEXPORT errno_t __cdecl _i64tow_s(long long, WCHAR *, size_t, int); PALIMPORT int __cdecl _wtoi(const WCHAR *); +inline int _stricmp(const char* a, const char* b) +{ + return strcasecmp(a, b); +} + +inline int _strnicmp(const char* a, const char* b, size_t c) +{ + return strncasecmp(a, b, c); +} + #ifdef __cplusplus extern "C++" { inline WCHAR *PAL_wcschr(WCHAR* S, WCHAR C) diff --git a/src/coreclr/pal/src/CMakeLists.txt b/src/coreclr/pal/src/CMakeLists.txt index 291f7ee2b031bf..4098d83921b78a 100644 --- a/src/coreclr/pal/src/CMakeLists.txt +++ b/src/coreclr/pal/src/CMakeLists.txt @@ -135,7 +135,6 @@ set(SOURCES cruntime/math.cpp cruntime/misc.cpp cruntime/printfcpp.cpp - cruntime/string.cpp cruntime/thread.cpp cruntime/wchar.cpp debug/debug.cpp diff --git a/src/coreclr/pal/src/cruntime/string.cpp b/src/coreclr/pal/src/cruntime/string.cpp deleted file mode 100644 index dd5245fd645260..00000000000000 --- a/src/coreclr/pal/src/cruntime/string.cpp +++ /dev/null @@ -1,105 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*++ - - - -Module Name: - - string.cpp - -Abstract: - - Implementation of the string functions in the C runtime library that are Windows specific. - - - ---*/ - -#include "pal/palinternal.h" -#include "pal/dbgmsg.h" -#include "pal/cruntime.h" - -#include -#include -#include -#include -#include -#include - - -SET_DEFAULT_DEBUG_CHANNEL(CRT); - -/*++ -Function: - _strnicmp - -compare at most count characters from two strings, ignoring case - -The strnicmp() function compares, with case insensitivity, at most count -characters from s1 to s2. All uppercase characters from s1 and s2 are -mapped to lowercase for the purposes of doing the comparison. - -Returns: - -Value Meaning - -< 0 s1 is less than s2 -0 s1 is equal to s2 -> 0 s1 is greater than s2 - ---*/ -int -__cdecl -_strnicmp( const char *s1, const char *s2, size_t count ) -{ - int ret; - - PERF_ENTRY(_strnicmp); - ENTRY("_strnicmp (s1=%p (%s), s2=%p (%s), count=%d)\n", s1?s1:"NULL", s1?s1:"NULL", s2?s2:"NULL", s2?s2:"NULL", count); - - ret = strncasecmp(s1, s2, count ); - - LOGEXIT("_strnicmp returning int %d\n", ret); - PERF_EXIT(_strnicmp); - return ret; -} - -/*++ -Function: - _stricmp - -compare two strings, ignoring case - -The stricmp() function compares, with case insensitivity, the string -pointed to by s1 to the string pointed to by s2. All uppercase -characters from s1 and s2 are mapped to lowercase for the purposes of -doing the comparison. - -Returns: - -Value Meaning - -< 0 s1 is less than s2 -0 s1 is equal to s2 -> 0 s1 is greater than s2 - ---*/ -int -__cdecl -_stricmp( - const char *s1, - const char *s2) -{ - int ret; - - PERF_ENTRY(_stricmp); - ENTRY("_stricmp (s1=%p (%s), s2=%p (%s))\n", s1?s1:"NULL", s1?s1:"NULL", s2?s2:"NULL", s2?s2:"NULL"); - - ret = strcasecmp(s1, s2); - - LOGEXIT("_stricmp returning int %d\n", ret); - PERF_EXIT(_stricmp); - return ret; -} diff --git a/src/coreclr/pal/src/cruntime/wchar.cpp b/src/coreclr/pal/src/cruntime/wchar.cpp index 3d887aecdb8835..8635b303d5783e 100644 --- a/src/coreclr/pal/src/cruntime/wchar.cpp +++ b/src/coreclr/pal/src/cruntime/wchar.cpp @@ -104,9 +104,9 @@ count Number of characters to compare Remarks -The _strnicmp function lexicographically compares, at most, the first +The _wcsnicmp function lexicographically compares, at most, the first count characters of string1 and string2. The comparison is performed -without regard to case; _strnicmp is a case-insensitive version of +without regard to case; _wcsnicmp is a case-insensitive version of strncmp. The comparison ends if a terminating null character is reached in either string before count characters are compared. If the strings are equal when a terminating null character is reached in diff --git a/src/coreclr/pal/src/include/pal/palinternal.h b/src/coreclr/pal/src/include/pal/palinternal.h index 5ba0a3364de214..3a8eac206ff2bd 100644 --- a/src/coreclr/pal/src/include/pal/palinternal.h +++ b/src/coreclr/pal/src/include/pal/palinternal.h @@ -184,6 +184,8 @@ function_name() to call the system's implementation #define strtod DUMMY_strtod #define strtoul DUMMY_strtoul #define strtoull DUMMY_strtoull +#define strcasecmp DUMMY_strcasecmp +#define strncasecmp DUMMY_strncasecmp #define strtok_r DUMMY_strtok_r #define tolower DUMMY_tolower #define toupper DUMMY_toupper @@ -377,6 +379,8 @@ function_name() to call the system's implementation #undef strpbrk #undef strtoul #undef strtoull +#undef strcasecmp +#undef strncasecmp #undef strtod #undef strtok_r #undef strdup diff --git a/src/coreclr/pal/tests/palsuite/CMakeLists.txt b/src/coreclr/pal/tests/palsuite/CMakeLists.txt index 7f5bb8ae834909..f878009c7b6418 100644 --- a/src/coreclr/pal/tests/palsuite/CMakeLists.txt +++ b/src/coreclr/pal/tests/palsuite/CMakeLists.txt @@ -237,8 +237,6 @@ add_executable_clr(paltests c_runtime/_putenv/test4/test4.cpp c_runtime/_rotl/test1/test1.cpp c_runtime/_rotr/test1/test1.cpp - c_runtime/_stricmp/test1/test1.cpp - c_runtime/_strnicmp/test1/test1.cpp c_runtime/_vsnprintf_s/test1/test1.cpp c_runtime/_vsnprintf_s/test10/test10.cpp c_runtime/_vsnprintf_s/test11/test11.cpp diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_stricmp/test1/test1.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_stricmp/test1/test1.cpp deleted file mode 100644 index c8b1c16b0d4ee1..00000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/_stricmp/test1/test1.cpp +++ /dev/null @@ -1,69 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*============================================================================ -** -** Source: test1.c -** -** Purpose: Do a lower case compare. Check two strings, only different -** because they have different capitalization, and they should return 0. Try -** two strings which will return less than 0 (one is smaller than the other). -** Also try the opposite, to get a return value greater than 0. -** -** -**==========================================================================*/ - -#include - -/* - * Note: The _stricmp is dependent on the LC_CTYPE category of the locale, - * and this is ignored by these tests. - */ -PALTEST(c_runtime__stricmp_test1_paltest_stricmp_test1, "c_runtime/_stricmp/test1/paltest_stricmp_test1") -{ - char *str1 = "foo"; - char *str2 = "fOo"; - char *str3 = "foo_bar"; - char *str4 = "foobar"; - - /* - * Initialize the PAL and return FAIL if this fails - */ - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - if (_stricmp(str1, str2) != 0) - { - Fail ("ERROR: _stricmp returning incorrect value:\n" - "_stricmp(\"%s\", \"%s\") != 0\n", str1, str2); - } - - if (_stricmp(str2, str3) >= 0) - { - Fail ("ERROR: _stricmp returning incorrect value:\n" - "_stricmp(\"%s\", \"%s\") >= 0\n", str2, str3); - } - - if (_stricmp(str3, str4) >= 0) - { - Fail ("ERROR: _stricmp returning incorrect value:\n" - "_stricmp(\"%s\", \"%s\") >= 0\n", str3, str4); - } - - if (_stricmp(str4, str1) <= 0) - { - Fail ("ERROR: _stricmp returning incorrect value:\n" - "_stricmp(\"%s\", \"%s\") <= 0\n", str4, str1); - } - - if (_stricmp(str3, str2) <= 0) - { - Fail ("ERROR: _stricmp returning incorrect value:\n" - "_stricmp(\"%s\", \"%s\") <= 0\n", str2, str3); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/coreclr/pal/tests/palsuite/c_runtime/_strnicmp/test1/test1.cpp b/src/coreclr/pal/tests/palsuite/c_runtime/_strnicmp/test1/test1.cpp deleted file mode 100644 index 4954abfb980db3..00000000000000 --- a/src/coreclr/pal/tests/palsuite/c_runtime/_strnicmp/test1/test1.cpp +++ /dev/null @@ -1,84 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*============================================================================ -** -** Source: test1.c -** -** Purpose: Test #1 for the _strnicmp function -** -** -**==========================================================================*/ - -#include - - -PALTEST(c_runtime__strnicmp_test1_paltest_strnicmp_test1, "c_runtime/_strnicmp/test1/paltest_strnicmp_test1") -{ - char str1[] = "foo"; - char str2[] = "foox"; - char str3[] = "fOo"; - char str4[] = "ABCDE"; - char str5[] = "ABCD["; - char str6[] = "abcde"; - char str7[] = "abcd^"; - - /* - * Initialize the PAL and return FAIL if this fails - */ - if (0 != (PAL_Initialize(argc, argv))) - { - return FAIL; - } - - if (_strnicmp(str1, str2, strlen(str2)) >= 0) - { - Fail ("ERROR: _strnicmp(\"%s\", \"%s\", %d) returned >= 0\n", - str1, str2, strlen(str2)); - } - - if (_strnicmp(str2, str1, strlen(str2)) <= 0) - { - Fail ("ERROR: _strnicmp(\"%s\", \"%s\", %d) returned <= 0\n", - str2, str1, strlen(str2)); - } - - if (_strnicmp(str1, str2, strlen(str1)) != 0) - { - Fail ("ERROR: _strnicmp(\"%s\", \"%s\", %d) returned != 0\n", - str1, str2, strlen(str1)); - } - - if (_strnicmp(str1, str3, strlen(str1)) != 0) - { - Fail ("ERROR: _strnicmp(\"%s\", \"%s\", %d) returned != 0\n", - str1, str3, strlen(str3)); - } - - if (_strnicmp(str3, str1, strlen(str1)) != 0) - { - Fail ("ERROR: _strnicmp(\"%s\", \"%s\", %d) returned != 0\n", - str3, str1, strlen(str1)); - } - - /* new testing */ - - /* str4 should be greater than str5 */ - if (_strnicmp(str4, str5, strlen(str4)) <= 0) - { - Fail ("ERROR: _strnicmp(\"%s\", \"%s\", %d) returned >= 0\n", - str4, str5, strlen(str4)); - } - - /* str6 should be greater than str7 */ - if (_strnicmp(str6, str7, strlen(str6)) <= 0) - { - Fail ("ERROR: _strnicmp(\"%s\", \"%s\", %d) returned <= 0\n", - str6, str7, strlen(str6)); - } - - - PAL_Terminate(); - - return PASS; -} diff --git a/src/coreclr/pal/tests/palsuite/compilableTests.txt b/src/coreclr/pal/tests/palsuite/compilableTests.txt index 0fa53a84081078..1b1d07245236cc 100644 --- a/src/coreclr/pal/tests/palsuite/compilableTests.txt +++ b/src/coreclr/pal/tests/palsuite/compilableTests.txt @@ -169,8 +169,6 @@ c_runtime/_putenv/test3/paltest_putenv_test3 c_runtime/_putenv/test4/paltest_putenv_test4 c_runtime/_rotl/test1/paltest_rotl_test1 c_runtime/_rotr/test1/paltest_rotr_test1 -c_runtime/_stricmp/test1/paltest_stricmp_test1 -c_runtime/_strnicmp/test1/paltest_strnicmp_test1 c_runtime/_vsnprintf_s/test1/paltest_vsnprintf_test1 c_runtime/_vsnprintf_s/test10/paltest_vsnprintf_test10 c_runtime/_vsnprintf_s/test11/paltest_vsnprintf_test11 diff --git a/src/coreclr/pal/tests/palsuite/paltestlist.txt b/src/coreclr/pal/tests/palsuite/paltestlist.txt index 5b462b234e8ea5..eff6efb16290fe 100644 --- a/src/coreclr/pal/tests/palsuite/paltestlist.txt +++ b/src/coreclr/pal/tests/palsuite/paltestlist.txt @@ -161,8 +161,6 @@ c_runtime/_putenv/test3/paltest_putenv_test3 c_runtime/_putenv/test4/paltest_putenv_test4 c_runtime/_rotl/test1/paltest_rotl_test1 c_runtime/_rotr/test1/paltest_rotr_test1 -c_runtime/_stricmp/test1/paltest_stricmp_test1 -c_runtime/_strnicmp/test1/paltest_strnicmp_test1 c_runtime/_vsnprintf_s/test1/paltest_vsnprintf_test1 c_runtime/_vsnprintf_s/test10/paltest_vsnprintf_test10 c_runtime/_vsnprintf_s/test11/paltest_vsnprintf_test11 diff --git a/src/coreclr/utilcode/pedecoder.cpp b/src/coreclr/utilcode/pedecoder.cpp index a919a9d1e0aa02..ee92bfaeedbfd4 100644 --- a/src/coreclr/utilcode/pedecoder.cpp +++ b/src/coreclr/utilcode/pedecoder.cpp @@ -1538,7 +1538,7 @@ CHECK PEDecoder::CheckILOnlyImportByNameTable(RVA rva) const IMAGE_IMPORT_BY_NAME *import = (IMAGE_IMPORT_BY_NAME*) GetRvaData(importRVA); - CHECK(SString::_stricmp((char *) import->Name, DLL_NAME) == 0 || _stricmp((char *) import->Name, EXE_NAME) == 0); + CHECK(SString::_stricmp((char *) import->Name, DLL_NAME) == 0 || SString::_stricmp((char *) import->Name, EXE_NAME) == 0); CHECK_OK; } From c79181b747306863127e8aef052f7b7bd1e9d174 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 8 Feb 2024 13:45:53 -0800 Subject: [PATCH 3/7] Remove strnlen --- src/coreclr/pal/inc/mbusafecrt.h | 6 +- src/coreclr/pal/inc/pal.h | 2 +- src/coreclr/pal/inc/rt/safecrt.h | 26 --------- src/coreclr/pal/src/CMakeLists.txt | 1 - src/coreclr/pal/src/include/pal/palinternal.h | 1 + src/coreclr/pal/src/safecrt/strlen_s.cpp | 57 ------------------- 6 files changed, 3 insertions(+), 90 deletions(-) delete mode 100644 src/coreclr/pal/src/safecrt/strlen_s.cpp diff --git a/src/coreclr/pal/inc/mbusafecrt.h b/src/coreclr/pal/inc/mbusafecrt.h index 2d72863299f036..7052b7834a1721 100644 --- a/src/coreclr/pal/inc/mbusafecrt.h +++ b/src/coreclr/pal/inc/mbusafecrt.h @@ -58,11 +58,7 @@ extern errno_t strncpy_s( char* outDest, size_t inDestBufferSize, const char* in extern errno_t wcsncpy_s( WCHAR* outDest, size_t inDestBufferSize, const WCHAR* inSrc, size_t inCount ); extern errno_t wcsncpy_s( WCHAR* outDest, size_t inDestBufferSize, const WCHAR* inSrc, size_t inCount ); -// strnlen is not required unless the source string is completely untrusted (e.g. anonymous input on a website) -#ifndef SUPPRESS_STRNLEN - extern size_t PAL_strnlen( const char* inString, size_t inMaxSize ); - extern size_t PAL_wcsnlen( const WCHAR* inString, size_t inMaxSize ); -#endif +extern size_t PAL_wcsnlen( const WCHAR* inString, size_t inMaxSize ); extern errno_t _itoa_s( int inValue, char* outBuffer, size_t inDestBufferSize, int inRadix ); extern errno_t _itow_s( int inValue, WCHAR* outBuffer, size_t inDestBufferSize, int inRadix ); diff --git a/src/coreclr/pal/inc/pal.h b/src/coreclr/pal/inc/pal.h index 5cf8825eabcb4e..f890a4f9253d9d 100644 --- a/src/coreclr/pal/inc/pal.h +++ b/src/coreclr/pal/inc/pal.h @@ -4026,7 +4026,6 @@ PAL_GetCurrentThreadAffinitySet(SIZE_T size, UINT_PTR* data); #define _pread PAL__pread #define _close PAL__close #define _flushall PAL__flushall -#define strnlen PAL_strnlen #ifdef HOST_AMD64 #define _mm_getcsr PAL__mm_getcsr @@ -4086,6 +4085,7 @@ PALIMPORT unsigned long __cdecl strtoul(const char *, char **, int); PALIMPORT ULONGLONG __cdecl strtoull(const char *, char **, int); PALIMPORT double __cdecl atof(const char *); PALIMPORT double __cdecl strtod(const char *, char **); +PALIMPORT size_t strnlen(const char *, size_t); PALIMPORT int __cdecl isprint(int); PALIMPORT int __cdecl isspace(int); PALIMPORT int __cdecl isalpha(int); diff --git a/src/coreclr/pal/inc/rt/safecrt.h b/src/coreclr/pal/inc/rt/safecrt.h index 8579b30eefa7e6..12b5eceaad5896 100644 --- a/src/coreclr/pal/inc/rt/safecrt.h +++ b/src/coreclr/pal/inc/rt/safecrt.h @@ -1117,32 +1117,6 @@ errno_t __cdecl _wcsnset_s(WCHAR *_Dst, size_t _SizeInWords, WCHAR _Value, size_ #endif #ifndef PAL_STDCPP_COMPAT -/* strnlen */ -/* - * strnlen, wcsnlen ; - * returns inMaxSize if the null character is not found. - */ -_SAFECRT__EXTERN_C -size_t __cdecl strnlen(const char* inString, size_t inMaxSize); - -#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL - -_SAFECRT__INLINE -size_t __cdecl strnlen(const char* inString, size_t inMaxSize) -{ - size_t n; - - /* Note that we do not check if s == nullptr, because we do not - * return errno_t... - */ - - for (n = 0; n < inMaxSize && *inString; n++, inString++) - ; - - return n; -} - -#endif /* wcsnlen */ _SAFECRT__EXTERN_C diff --git a/src/coreclr/pal/src/CMakeLists.txt b/src/coreclr/pal/src/CMakeLists.txt index 4098d83921b78a..22b1e1f78bdefc 100644 --- a/src/coreclr/pal/src/CMakeLists.txt +++ b/src/coreclr/pal/src/CMakeLists.txt @@ -182,7 +182,6 @@ set(SOURCES safecrt/sscanf_s.cpp safecrt/strcat_s.cpp safecrt/strcpy_s.cpp - safecrt/strlen_s.cpp safecrt/strncat_s.cpp safecrt/strncpy_s.cpp safecrt/vsprintf.cpp diff --git a/src/coreclr/pal/src/include/pal/palinternal.h b/src/coreclr/pal/src/include/pal/palinternal.h index 3a8eac206ff2bd..f1c703a37e9447 100644 --- a/src/coreclr/pal/src/include/pal/palinternal.h +++ b/src/coreclr/pal/src/include/pal/palinternal.h @@ -184,6 +184,7 @@ function_name() to call the system's implementation #define strtod DUMMY_strtod #define strtoul DUMMY_strtoul #define strtoull DUMMY_strtoull +#define strnlen DUMMY_strnlen #define strcasecmp DUMMY_strcasecmp #define strncasecmp DUMMY_strncasecmp #define strtok_r DUMMY_strtok_r diff --git a/src/coreclr/pal/src/safecrt/strlen_s.cpp b/src/coreclr/pal/src/safecrt/strlen_s.cpp deleted file mode 100644 index 0c35d3625df3fc..00000000000000 --- a/src/coreclr/pal/src/safecrt/strlen_s.cpp +++ /dev/null @@ -1,57 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*** -*strlen_s.c - contains strnlen() routine -* - -* -*Purpose: -* strnlen returns the length of a null-terminated string, -* not including the null byte itself, up to the specified max size -* -*******************************************************************************/ - - -#include -#include -#include -#include "internal_securecrt.h" - -#include "mbusafecrt_internal.h" - -/*** -*strnlen - return the length of a null-terminated string -* -*Purpose: -* Finds the length in bytes of the given string, not including -* the final null character. Only the first maxsize characters -* are inspected: if the null character is not found, maxsize is -* returned. -* -*Entry: -* const char * str - string whose length is to be computed -* size_t maxsize -* -*Exit: -* Length of the string "str", exclusive of the final null byte, or -* maxsize if the null character is not found. -* -*Exceptions: -* -*******************************************************************************/ - -size_t __cdecl PAL_strnlen(const char *str, size_t maxsize) -{ - size_t n; - - /* Note that we do not check if str == NULL, because we do not - * return errno_t... - */ - - for (n = 0; n < maxsize && *str; n++, str++) - ; - - return n; -} - From 134f49eed75e426c1f869b2a599805dd3217f523 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 8 Feb 2024 13:52:08 -0800 Subject: [PATCH 4/7] Make inline forwarder from _strdup to strdup --- src/coreclr/pal/inc/pal.h | 8 ++++++-- src/coreclr/pal/src/cruntime/file.cpp | 4 ++-- src/coreclr/pal/src/cruntime/malloc.cpp | 9 --------- src/coreclr/pal/src/file/directory.cpp | 4 ++-- src/coreclr/pal/src/include/pal/malloc.hpp | 6 ------ src/coreclr/pal/src/include/pal/palinternal.h | 2 ++ 6 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/coreclr/pal/inc/pal.h b/src/coreclr/pal/inc/pal.h index f890a4f9253d9d..4c59698307daaf 100644 --- a/src/coreclr/pal/inc/pal.h +++ b/src/coreclr/pal/inc/pal.h @@ -4021,7 +4021,6 @@ PAL_GetCurrentThreadAffinitySet(SIZE_T size, UINT_PTR* data); #define sincosf PAL_sincosf #define malloc PAL_malloc #define free PAL_free -#define _strdup PAL__strdup #define _open PAL__open #define _pread PAL__pread #define _close PAL__close @@ -4080,6 +4079,7 @@ PALIMPORT char * __cdecl strrchr(const char *, int); PALIMPORT char * __cdecl strpbrk(const char *, const char *); PALIMPORT char * __cdecl strstr(const char *, const char *); PALIMPORT char * __cdecl strtok_r(char *, const char *, char **); +PALIMPORT char * __cdecl strdup(const char*); PALIMPORT int __cdecl atoi(const char *); PALIMPORT unsigned long __cdecl strtoul(const char *, char **, int); PALIMPORT ULONGLONG __cdecl strtoull(const char *, char **, int); @@ -4152,6 +4152,11 @@ inline int _strnicmp(const char* a, const char* b, size_t c) return strncasecmp(a, b, c); } +inline char* _strdup(const char* a) +{ + return strdup(a); +} + #ifdef __cplusplus extern "C++" { inline WCHAR *PAL_wcschr(WCHAR* S, WCHAR C) @@ -4305,7 +4310,6 @@ inline __int64 abs(SSIZE_T _X) { PALIMPORT DLLEXPORT void * __cdecl malloc(size_t); PALIMPORT DLLEXPORT void __cdecl free(void *); PALIMPORT DLLEXPORT void * __cdecl realloc(void *, size_t); -PALIMPORT char * __cdecl _strdup(const char *); #if defined(_MSC_VER) #define alloca _alloca diff --git a/src/coreclr/pal/src/cruntime/file.cpp b/src/coreclr/pal/src/cruntime/file.cpp index a7a7a12a33375f..57cf7faa4caf3b 100644 --- a/src/coreclr/pal/src/cruntime/file.cpp +++ b/src/coreclr/pal/src/cruntime/file.cpp @@ -226,10 +226,10 @@ PAL_fopen(const char * fileName, const char * mode) goto done; } - UnixFileName = PAL__strdup(fileName); + UnixFileName = strdup(fileName); if (UnixFileName == NULL ) { - ERROR("PAL__strdup() failed\n"); + ERROR("strdup() failed\n"); SetLastError(ERROR_NOT_ENOUGH_MEMORY); goto done; } diff --git a/src/coreclr/pal/src/cruntime/malloc.cpp b/src/coreclr/pal/src/cruntime/malloc.cpp index 4351c47e31a4ee..c4b3797e0b30a6 100644 --- a/src/coreclr/pal/src/cruntime/malloc.cpp +++ b/src/coreclr/pal/src/cruntime/malloc.cpp @@ -104,12 +104,3 @@ CorUnix::InternalMalloc( pvMem = (void*)malloc(szSize); return pvMem; } - -char * -__cdecl -PAL__strdup( - const char *c_szStr - ) -{ - return strdup(c_szStr); -} diff --git a/src/coreclr/pal/src/file/directory.cpp b/src/coreclr/pal/src/file/directory.cpp index e30fd2d9236260..4cd0600e5cf603 100644 --- a/src/coreclr/pal/src/file/directory.cpp +++ b/src/coreclr/pal/src/file/directory.cpp @@ -406,10 +406,10 @@ CreateDirectoryA( goto done; } - unixPathName = PAL__strdup(lpPathName); + unixPathName = strdup(lpPathName); if (unixPathName == NULL ) { - ERROR("PAL__strdup() failed\n"); + ERROR("strdup() failed\n"); dwLastError = ERROR_NOT_ENOUGH_MEMORY; goto done; } diff --git a/src/coreclr/pal/src/include/pal/malloc.hpp b/src/coreclr/pal/src/include/pal/malloc.hpp index fb7c88d128c507..4e7b96da0e2283 100644 --- a/src/coreclr/pal/src/include/pal/malloc.hpp +++ b/src/coreclr/pal/src/include/pal/malloc.hpp @@ -46,12 +46,6 @@ extern "C" PAL_free( void *pvMem ); - - char * - __cdecl - PAL__strdup( - const char *c_szStr - ); } namespace CorUnix{ diff --git a/src/coreclr/pal/src/include/pal/palinternal.h b/src/coreclr/pal/src/include/pal/palinternal.h index f1c703a37e9447..632d769bfcdfbc 100644 --- a/src/coreclr/pal/src/include/pal/palinternal.h +++ b/src/coreclr/pal/src/include/pal/palinternal.h @@ -187,6 +187,7 @@ function_name() to call the system's implementation #define strnlen DUMMY_strnlen #define strcasecmp DUMMY_strcasecmp #define strncasecmp DUMMY_strncasecmp +#define strdup DUMMY_strdup #define strtok_r DUMMY_strtok_r #define tolower DUMMY_tolower #define toupper DUMMY_toupper @@ -382,6 +383,7 @@ function_name() to call the system's implementation #undef strtoull #undef strcasecmp #undef strncasecmp +#undef strdup #undef strtod #undef strtok_r #undef strdup From 2119f780b3a4c6914a2c095533fe7ef9b62bd7a9 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 9 Feb 2024 11:06:24 -0800 Subject: [PATCH 5/7] Add include for strcasecmp and strncasecmp --- src/coreclr/pal/inc/pal.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/coreclr/pal/inc/pal.h b/src/coreclr/pal/inc/pal.h index 4c59698307daaf..64eb19e9fd1784 100644 --- a/src/coreclr/pal/inc/pal.h +++ b/src/coreclr/pal/inc/pal.h @@ -42,6 +42,7 @@ Module Name: #include #include #include +#include #include #include #include From efafe8bdf20b6ca4ef92e29815a2abdeef0ed541 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 9 Feb 2024 12:03:35 -0800 Subject: [PATCH 6/7] Fix build failures --- src/coreclr/dlls/mscordac/mscordac_unixexports.src | 1 - src/coreclr/gc/unix/numasupport.cpp | 7 +++++-- src/coreclr/tools/StressLogAnalyzer/StressLogPlugin.cpp | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/coreclr/dlls/mscordac/mscordac_unixexports.src b/src/coreclr/dlls/mscordac/mscordac_unixexports.src index 6cdd5ff733bcf8..4e65be98fee183 100644 --- a/src/coreclr/dlls/mscordac/mscordac_unixexports.src +++ b/src/coreclr/dlls/mscordac/mscordac_unixexports.src @@ -70,7 +70,6 @@ nativeStringResourceTable_mscorrc #PAL__close #_wcsicmp -#_stricmp #sprintf_s #vsprintf_s #_snprintf_s diff --git a/src/coreclr/gc/unix/numasupport.cpp b/src/coreclr/gc/unix/numasupport.cpp index 318a5daa35782c..713811a1e997a6 100644 --- a/src/coreclr/gc/unix/numasupport.cpp +++ b/src/coreclr/gc/unix/numasupport.cpp @@ -34,8 +34,11 @@ static int GetNodeNum(const char* path, bool firstOnly) continue; unsigned long nodeNum = strtoul(entry->d_name + STRING_LENGTH("node"), NULL, 0); - if (result < nodeNum) - result = nodeNum > INT_MAX ? INT_MAX : (int)nodeNum; + if (nodeNum > INT_MAX) + nodeNum = INT_MAX; + + if (result < (int)nodeNum) + result = (int)nodeNum; if (firstOnly) break; diff --git a/src/coreclr/tools/StressLogAnalyzer/StressLogPlugin.cpp b/src/coreclr/tools/StressLogAnalyzer/StressLogPlugin.cpp index e86dec418a532d..c1dbaf82b69f11 100644 --- a/src/coreclr/tools/StressLogAnalyzer/StressLogPlugin.cpp +++ b/src/coreclr/tools/StressLogAnalyzer/StressLogPlugin.cpp @@ -354,7 +354,7 @@ bool FilterMessage(StressLog::StressLogHeader* hdr, ThreadStressLog* tsl, uint32 bool fLevelFilter = false; if (s_levelFilterCount > 0) { - int gcLogLevel = GcLogLevel(facility); + unsigned long gcLogLevel = (unsigned long)GcLogLevel(facility); for (int i = 0; i < s_levelFilterCount; i++) { if (s_levelFilter[i].minLevel <= gcLogLevel && gcLogLevel <= s_levelFilter[i].maxLevel) @@ -1368,7 +1368,7 @@ int ProcessStressLog(void* baseAddress, int argc, char* argv[]) // find the time interval that includes the GCs in question double startTime = INFINITY; double endTime = 0.0; - for (int i = s_gcFilterStart; i <= s_gcFilterEnd; i++) + for (unsigned int i = s_gcFilterStart; i <= s_gcFilterEnd; i++) { startTime = min(startTime, s_gcStartEnd[i].startTime); if (s_gcStartEnd[i].endTime != 0.0) From 845f8b19d7fefb9426185d4a49c715f7a48911d6 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 9 Feb 2024 16:35:17 -0800 Subject: [PATCH 7/7] Update src/coreclr/tools/StressLogAnalyzer/StressLogPlugin.cpp Co-authored-by: Aaron Robinson --- src/coreclr/tools/StressLogAnalyzer/StressLogPlugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/tools/StressLogAnalyzer/StressLogPlugin.cpp b/src/coreclr/tools/StressLogAnalyzer/StressLogPlugin.cpp index c1dbaf82b69f11..dc4a63c0e8db19 100644 --- a/src/coreclr/tools/StressLogAnalyzer/StressLogPlugin.cpp +++ b/src/coreclr/tools/StressLogAnalyzer/StressLogPlugin.cpp @@ -1368,7 +1368,7 @@ int ProcessStressLog(void* baseAddress, int argc, char* argv[]) // find the time interval that includes the GCs in question double startTime = INFINITY; double endTime = 0.0; - for (unsigned int i = s_gcFilterStart; i <= s_gcFilterEnd; i++) + for (unsigned long i = s_gcFilterStart; i <= s_gcFilterEnd; i++) { startTime = min(startTime, s_gcStartEnd[i].startTime); if (s_gcStartEnd[i].endTime != 0.0)