Skip to content

Commit 96da5a0

Browse files
authored
Remove C-String PAL wrappers (#98189)
1 parent 35bff27 commit 96da5a0

File tree

26 files changed

+60
-825
lines changed

26 files changed

+60
-825
lines changed

src/coreclr/dlls/mscordac/mscordac_unixexports.src

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ nativeStringResourceTable_mscorrc
7070
#PAL__close
7171

7272
#_wcsicmp
73-
#_stricmp
7473
#sprintf_s
7574
#vsprintf_s
7675
#_snprintf_s

src/coreclr/gc/unix/numasupport.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <stdio.h>
1010
#include <dirent.h>
1111
#include <string.h>
12+
#include <limits.h>
1213
#include <sys/syscall.h>
1314
#include <minipal/utils.h>
1415

@@ -32,9 +33,12 @@ static int GetNodeNum(const char* path, bool firstOnly)
3233
if (strncmp(entry->d_name, "node", STRING_LENGTH("node")))
3334
continue;
3435

35-
int nodeNum = strtoul(entry->d_name + STRING_LENGTH("node"), NULL, 0);
36-
if (result < nodeNum)
37-
result = nodeNum;
36+
unsigned long nodeNum = strtoul(entry->d_name + STRING_LENGTH("node"), NULL, 0);
37+
if (nodeNum > INT_MAX)
38+
nodeNum = INT_MAX;
39+
40+
if (result < (int)nodeNum)
41+
result = (int)nodeNum;
3842

3943
if (firstOnly)
4044
break;

src/coreclr/inc/clrconfignocache.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ class CLRConfigNoCache
4141

4242
errno = 0;
4343
LPSTR endPtr;
44-
result = strtoul(_value, &endPtr, radix);
45-
bool fSuccess = (errno != ERANGE) && (endPtr != _value);
44+
unsigned long rawResult = strtoul(_value, &endPtr, radix);
45+
if ((DWORD)rawResult != rawResult || errno == ERANGE)
46+
{
47+
return false;
48+
}
49+
bool fSuccess = endPtr != _value;
4650
return fSuccess;
4751
}
4852

src/coreclr/pal/inc/mbusafecrt.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@ extern errno_t strncpy_s( char* outDest, size_t inDestBufferSize, const char* in
5858
extern errno_t wcsncpy_s( WCHAR* outDest, size_t inDestBufferSize, const WCHAR* inSrc, size_t inCount );
5959
extern errno_t wcsncpy_s( WCHAR* outDest, size_t inDestBufferSize, const WCHAR* inSrc, size_t inCount );
6060

61-
// strnlen is not required unless the source string is completely untrusted (e.g. anonymous input on a website)
62-
#ifndef SUPPRESS_STRNLEN
63-
extern size_t PAL_strnlen( const char* inString, size_t inMaxSize );
64-
extern size_t PAL_wcsnlen( const WCHAR* inString, size_t inMaxSize );
65-
#endif
61+
extern size_t PAL_wcsnlen( const WCHAR* inString, size_t inMaxSize );
6662

6763
extern errno_t _itoa_s( int inValue, char* outBuffer, size_t inDestBufferSize, int inRadix );
6864
extern errno_t _itow_s( int inValue, WCHAR* outBuffer, size_t inDestBufferSize, int inRadix );

src/coreclr/pal/inc/pal.h

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Module Name:
4242
#include <stdarg.h>
4343
#include <stdint.h>
4444
#include <string.h>
45+
#include <strings.h>
4546
#include <errno.h>
4647
#include <ctype.h>
4748
#include <sys/stat.h>
@@ -3982,8 +3983,6 @@ PAL_GetCurrentThreadAffinitySet(SIZE_T size, UINT_PTR* data);
39823983
#define exit PAL_exit
39833984
#define realloc PAL_realloc
39843985
#define fopen PAL_fopen
3985-
#define strtoul PAL_strtoul
3986-
#define strtoull PAL_strtoull
39873986
#define fprintf PAL_fprintf
39883987
#define vfprintf PAL_vfprintf
39893988
#define rand PAL_rand
@@ -4023,12 +4022,10 @@ PAL_GetCurrentThreadAffinitySet(SIZE_T size, UINT_PTR* data);
40234022
#define sincosf PAL_sincosf
40244023
#define malloc PAL_malloc
40254024
#define free PAL_free
4026-
#define _strdup PAL__strdup
40274025
#define _open PAL__open
40284026
#define _pread PAL__pread
40294027
#define _close PAL__close
40304028
#define _flushall PAL__flushall
4031-
#define strnlen PAL_strnlen
40324029

40334030
#ifdef HOST_AMD64
40344031
#define _mm_getcsr PAL__mm_getcsr
@@ -4073,7 +4070,7 @@ PALIMPORT long long int __cdecl atoll(const char *) MATH_THROW_DECL;
40734070
PALIMPORT size_t __cdecl strlen(const char *);
40744071
PALIMPORT int __cdecl strcmp(const char*, const char *);
40754072
PALIMPORT int __cdecl strncmp(const char*, const char *, size_t);
4076-
PALIMPORT int __cdecl _strnicmp(const char *, const char *, size_t);
4073+
PALIMPORT int __cdecl strncasecmp(const char *, const char *, size_t);
40774074
PALIMPORT char * __cdecl strcat(char *, const char *);
40784075
PALIMPORT char * __cdecl strncat(char *, const char *, size_t);
40794076
PALIMPORT char * __cdecl strcpy(char *, const char *);
@@ -4083,11 +4080,13 @@ PALIMPORT char * __cdecl strrchr(const char *, int);
40834080
PALIMPORT char * __cdecl strpbrk(const char *, const char *);
40844081
PALIMPORT char * __cdecl strstr(const char *, const char *);
40854082
PALIMPORT char * __cdecl strtok_r(char *, const char *, char **);
4083+
PALIMPORT char * __cdecl strdup(const char*);
40864084
PALIMPORT int __cdecl atoi(const char *);
4087-
PALIMPORT ULONG __cdecl strtoul(const char *, char **, int);
4085+
PALIMPORT unsigned long __cdecl strtoul(const char *, char **, int);
40884086
PALIMPORT ULONGLONG __cdecl strtoull(const char *, char **, int);
40894087
PALIMPORT double __cdecl atof(const char *);
40904088
PALIMPORT double __cdecl strtod(const char *, char **);
4089+
PALIMPORT size_t strnlen(const char *, size_t);
40914090
PALIMPORT int __cdecl isprint(int);
40924091
PALIMPORT int __cdecl isspace(int);
40934092
PALIMPORT int __cdecl isalpha(int);
@@ -4114,7 +4113,7 @@ PALIMPORT int remove(const char*);
41144113

41154114
PALIMPORT DLLEXPORT errno_t __cdecl memcpy_s(void *, size_t, const void *, size_t) THROW_DECL;
41164115
PALIMPORT errno_t __cdecl memmove_s(void *, size_t, const void *, size_t);
4117-
PALIMPORT DLLEXPORT int __cdecl _stricmp(const char *, const char *);
4116+
PALIMPORT DLLEXPORT int __cdecl strcasecmp(const char *, const char *);
41184117
PALIMPORT char * __cdecl _gcvt_s(char *, int, double, int);
41194118
PALIMPORT int __cdecl __iscsym(int);
41204119
PALIMPORT DLLEXPORT int __cdecl _wcsicmp(const WCHAR *, const WCHAR*);
@@ -4144,6 +4143,21 @@ PALIMPORT errno_t __cdecl _wcslwr_s(WCHAR *, size_t sz);
41444143
PALIMPORT DLLEXPORT errno_t __cdecl _i64tow_s(long long, WCHAR *, size_t, int);
41454144
PALIMPORT int __cdecl _wtoi(const WCHAR *);
41464145

4146+
inline int _stricmp(const char* a, const char* b)
4147+
{
4148+
return strcasecmp(a, b);
4149+
}
4150+
4151+
inline int _strnicmp(const char* a, const char* b, size_t c)
4152+
{
4153+
return strncasecmp(a, b, c);
4154+
}
4155+
4156+
inline char* _strdup(const char* a)
4157+
{
4158+
return strdup(a);
4159+
}
4160+
41474161
#ifdef __cplusplus
41484162
extern "C++" {
41494163
inline WCHAR *PAL_wcschr(WCHAR* S, WCHAR C)
@@ -4297,7 +4311,6 @@ inline __int64 abs(SSIZE_T _X) {
42974311
PALIMPORT DLLEXPORT void * __cdecl malloc(size_t);
42984312
PALIMPORT DLLEXPORT void __cdecl free(void *);
42994313
PALIMPORT DLLEXPORT void * __cdecl realloc(void *, size_t);
4300-
PALIMPORT char * __cdecl _strdup(const char *);
43014314

43024315
#if defined(_MSC_VER)
43034316
#define alloca _alloca

src/coreclr/pal/inc/rt/safecrt.h

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,32 +1117,6 @@ errno_t __cdecl _wcsnset_s(WCHAR *_Dst, size_t _SizeInWords, WCHAR _Value, size_
11171117
#endif
11181118

11191119
#ifndef PAL_STDCPP_COMPAT
1120-
/* strnlen */
1121-
/*
1122-
* strnlen, wcsnlen ;
1123-
* returns inMaxSize if the null character is not found.
1124-
*/
1125-
_SAFECRT__EXTERN_C
1126-
size_t __cdecl strnlen(const char* inString, size_t inMaxSize);
1127-
1128-
#if _SAFECRT_USE_INLINES || _SAFECRT_IMPL
1129-
1130-
_SAFECRT__INLINE
1131-
size_t __cdecl strnlen(const char* inString, size_t inMaxSize)
1132-
{
1133-
size_t n;
1134-
1135-
/* Note that we do not check if s == nullptr, because we do not
1136-
* return errno_t...
1137-
*/
1138-
1139-
for (n = 0; n < inMaxSize && *inString; n++, inString++)
1140-
;
1141-
1142-
return n;
1143-
}
1144-
1145-
#endif
11461120

11471121
/* wcsnlen */
11481122
_SAFECRT__EXTERN_C

src/coreclr/pal/src/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ set(SOURCES
135135
cruntime/math.cpp
136136
cruntime/misc.cpp
137137
cruntime/printfcpp.cpp
138-
cruntime/string.cpp
139138
cruntime/thread.cpp
140139
cruntime/wchar.cpp
141140
debug/debug.cpp
@@ -183,7 +182,6 @@ set(SOURCES
183182
safecrt/sscanf_s.cpp
184183
safecrt/strcat_s.cpp
185184
safecrt/strcpy_s.cpp
186-
safecrt/strlen_s.cpp
187185
safecrt/strncat_s.cpp
188186
safecrt/strncpy_s.cpp
189187
safecrt/vsprintf.cpp

src/coreclr/pal/src/cruntime/file.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,10 @@ PAL_fopen(const char * fileName, const char * mode)
226226
goto done;
227227
}
228228

229-
UnixFileName = PAL__strdup(fileName);
229+
UnixFileName = strdup(fileName);
230230
if (UnixFileName == NULL )
231231
{
232-
ERROR("PAL__strdup() failed\n");
232+
ERROR("strdup() failed\n");
233233
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
234234
goto done;
235235
}

src/coreclr/pal/src/cruntime/malloc.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,3 @@ CorUnix::InternalMalloc(
104104
pvMem = (void*)malloc(szSize);
105105
return pvMem;
106106
}
107-
108-
char *
109-
__cdecl
110-
PAL__strdup(
111-
const char *c_szStr
112-
)
113-
{
114-
return strdup(c_szStr);
115-
}

0 commit comments

Comments
 (0)