Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 3 additions & 2 deletions src/coreclr/gc/unix/numasupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <stdio.h>
#include <dirent.h>
#include <string.h>
#include <limits.h>
#include <sys/syscall.h>
#include <minipal/utils.h>

Expand All @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions src/coreclr/inc/clrconfignocache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 1 addition & 5 deletions src/coreclr/pal/inc/mbusafecrt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
28 changes: 20 additions & 8 deletions src/coreclr/pal/inc/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -4023,12 +4021,10 @@ 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
#define _flushall PAL__flushall
#define strnlen PAL_strnlen

#ifdef HOST_AMD64
#define _mm_getcsr PAL__mm_getcsr
Expand Down Expand Up @@ -4073,7 +4069,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 *);
Expand All @@ -4083,11 +4079,13 @@ 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 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 **);
PALIMPORT size_t strnlen(const char *, size_t);
PALIMPORT int __cdecl isprint(int);
PALIMPORT int __cdecl isspace(int);
PALIMPORT int __cdecl isalpha(int);
Expand All @@ -4114,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*);
Expand Down Expand Up @@ -4144,6 +4142,21 @@ 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);
}

inline char* _strdup(const char* a)
{
return strdup(a);
}

#ifdef __cplusplus
extern "C++" {
inline WCHAR *PAL_wcschr(WCHAR* S, WCHAR C)
Expand Down Expand Up @@ -4297,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
Expand Down
26 changes: 0 additions & 26 deletions src/coreclr/pal/inc/rt/safecrt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/pal/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -183,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
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/pal/src/cruntime/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
9 changes: 0 additions & 9 deletions src/coreclr/pal/src/cruntime/malloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,3 @@ CorUnix::InternalMalloc(
pvMem = (void*)malloc(szSize);
return pvMem;
}

char *
__cdecl
PAL__strdup(
const char *c_szStr
)
{
return strdup(c_szStr);
}
Loading