Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a04f75c

Browse files
Remove more PAL exports for wprintf wscanf funcs (#76771)
* Remove more PAL exports for wprintf funcs * Remove tests for fwprintf * Remove swscanf tests * Remove wprintf tests
1 parent f156fb9 commit a04f75c

File tree

54 files changed

+144
-4616
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+144
-4616
lines changed

src/coreclr/dlls/mscordac/mscordac_unixexports.src

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ nativeStringResourceTable_mscorrc
2828
#PAL_fflush
2929
#PAL__flushall
3030
#PAL_free
31-
#PAL_fwprintf
3231
#PAL_GetLogicalCpuCountFromOS
3332
#PAL_GetTotalCpuCount
3433
#PAL_GetNumaProcessorNode

src/coreclr/ilasm/main.cpp

Lines changed: 67 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,40 @@
1616

1717
WCHAR* EqualOrColon(_In_ __nullterminated WCHAR* szArg)
1818
{
19-
WCHAR* pchE = wcschr(szArg,L'=');
20-
WCHAR* pchC = wcschr(szArg,L':');
19+
WCHAR* pchE = wcschr(szArg,W('='));
20+
WCHAR* pchC = wcschr(szArg,W(':'));
2121
WCHAR* ret;
2222
if(pchE == NULL) ret = pchC;
2323
else if(pchC == NULL) ret = pchE;
2424
else ret = (pchE < pchC)? pchE : pchC;
2525
return ret;
2626
}
2727

28+
// When converting a string for number parsing it is
29+
// possible to simply cast a WCHAR to a char with no
30+
// loss of data.
31+
class NarrowForNumberParsing final
32+
{
33+
char* _buffer;
34+
public:
35+
NarrowForNumberParsing(const WCHAR* str)
36+
{
37+
size_t len = wcslen(str);
38+
_buffer = (char*)malloc(len + 1);
39+
for (size_t i = 0; i < len; ++i)
40+
_buffer[i] = (char)str[i];
41+
_buffer[len] = '\0';
42+
}
43+
~NarrowForNumberParsing()
44+
{
45+
free(_buffer);
46+
}
47+
operator const char*() const
48+
{
49+
return _buffer;
50+
}
51+
};
52+
2853
static DWORD g_dwSubsystem=(DWORD)-1,g_dwComImageFlags=(DWORD)-1,g_dwFileAlignment=0,g_dwTestRepeat=0;
2954
static ULONGLONG g_stBaseAddress=0;
3055
static size_t g_stSizeOfStackReserve=0;
@@ -214,9 +239,9 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv)
214239
for (i = 1; i < argc; i++)
215240
{
216241
#ifdef TARGET_UNIX
217-
if(argv[i][0] == L'-')
242+
if(argv[i][0] == W('-'))
218243
#else
219-
if((argv[i][0] == L'/') || (argv[i][0] == L'-'))
244+
if((argv[i][0] == W('/')) || (argv[i][0] == W('-')))
220245
#endif
221246
{
222247
char szOpt[3 + 1] = { 0 };
@@ -247,7 +272,7 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv)
247272
WCHAR *pStr = EqualOrColon(argv[i]);
248273
if(pStr != NULL)
249274
{
250-
for(pStr++; *pStr == L' '; pStr++); //skip the blanks
275+
for(pStr++; *pStr == W(' '); pStr++); //skip the blanks
251276
if(wcslen(pStr)==0) goto InvalidOption; //if no suboption
252277
else
253278
{
@@ -260,9 +285,10 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv)
260285
pAsm->m_dwIncludeDebugInfo = 0x103;
261286
else
262287
{
263-
const WCHAR *pFmt =((*pStr == '0')&&(*(pStr+1) == 'x'))? W("%lx") : W("%ld");
264-
if(swscanf_s(pStr,pFmt,&(pAsm->m_dwIncludeDebugInfo))!=1)
265-
goto InvalidOption; // bad subooption
288+
const CHAR *pFmt =((*pStr == '0')&&(*(pStr+1) == 'x'))? "%x" : "%d";
289+
NarrowForNumberParsing str{pStr};
290+
if(sscanf_s(str,pFmt,&(pAsm->m_dwIncludeDebugInfo))!=1)
291+
goto InvalidOption; // bad subooption
266292
}
267293
}
268294
}
@@ -360,7 +386,7 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv)
360386
{
361387
WCHAR *pStr = EqualOrColon(argv[i]);
362388
if(pStr == NULL) goto ErrorExit;
363-
for(pStr++; *pStr == L' '; pStr++); //skip the blanks
389+
for(pStr++; *pStr == W(' '); pStr++); //skip the blanks
364390
if(wcslen(pStr)==0) goto InvalidOption; //if no file name
365391
pAsm->m_wzResourceFile = pStr;
366392
}
@@ -371,23 +397,23 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv)
371397
{
372398
WCHAR *pStr = EqualOrColon(argv[i]);
373399
if(pStr == NULL) goto InvalidOption;
374-
for(pStr++; *pStr == L' '; pStr++); //skip the blanks
400+
for(pStr++; *pStr == W(' '); pStr++); //skip the blanks
375401
if(wcslen(pStr)==0) goto InvalidOption; //if no file name
376402
pAsm->m_wzKeySourceName = pStr;
377403
}
378404
else if (!_stricmp(szOpt, "INC"))
379405
{
380406
WCHAR *pStr = EqualOrColon(argv[i]);
381407
if(pStr == NULL) goto InvalidOption;
382-
for(pStr++; *pStr == L' '; pStr++); //skip the blanks
408+
for(pStr++; *pStr == W(' '); pStr++); //skip the blanks
383409
if(wcslen(pStr)==0) goto InvalidOption; //if no file name
384410
wzIncludePath = pStr;
385411
}
386412
else if (!_stricmp(szOpt, "OUT"))
387413
{
388414
WCHAR *pStr = EqualOrColon(argv[i]);
389415
if(pStr == NULL) goto InvalidOption;
390-
for(pStr++; *pStr == L' '; pStr++); //skip the blanks
416+
for(pStr++; *pStr == W(' '); pStr++); //skip the blanks
391417
if(wcslen(pStr)==0) goto InvalidOption; //if no file name
392418
if(wcslen(pStr) >= MAX_FILENAME_LENGTH)
393419
{
@@ -400,19 +426,20 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv)
400426
{
401427
WCHAR *pStr = EqualOrColon(argv[i]);
402428
if(pStr == NULL) goto InvalidOption;
403-
for(pStr++; *pStr == L' '; pStr++); //skip the blanks
429+
for(pStr++; *pStr == W(' '); pStr++); //skip the blanks
404430
if(wcslen(pStr)==0) goto InvalidOption; //if no version string
405431
pAsm->m_wzMetadataVersion = pStr;
406432
}
407433
else if (!_stricmp(szOpt, "MSV"))
408434
{
409435
WCHAR *pStr = EqualOrColon(argv[i]);
410436
if(pStr == NULL) goto InvalidOption;
411-
for(pStr++; *pStr == L' '; pStr++); //skip the blanks
437+
for(pStr++; *pStr == W(' '); pStr++); //skip the blanks
412438
if(wcslen(pStr)==0) goto InvalidOption; //if no version
413439
{
414440
int major=-1,minor=-1;
415-
if(swscanf_s(pStr,W("%d.%d"),&major, &minor)==2)
441+
NarrowForNumberParsing str{pStr};
442+
if(sscanf_s(str,"%d.%d",&major, &minor)==2)
416443
{
417444
if((major >= 0)&&(major < 0xFF))
418445
pAsm->m_wMSVmajor = (WORD)major;
@@ -426,18 +453,20 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv)
426453
WCHAR *pStr = EqualOrColon(argv[i]);
427454
if(pStr == NULL) goto InvalidOption;
428455
pStr++;
429-
const WCHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? W("%lx") : W("%ld");
430-
if(swscanf_s(pStr,pFmt,&g_dwSubsystem)!=1) goto InvalidOption;
456+
const CHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? "%x" : "%d";
457+
NarrowForNumberParsing str{pStr};
458+
if(sscanf_s(str,pFmt,&g_dwSubsystem)!=1) goto InvalidOption;
431459
}
432460
else if (!_stricmp(szOpt, "SSV"))
433461
{
434462
WCHAR *pStr = EqualOrColon(argv[i]);
435463
if(pStr == NULL) goto InvalidOption;
436-
for(pStr++; *pStr == L' '; pStr++); //skip the blanks
464+
for(pStr++; *pStr == W(' '); pStr++); //skip the blanks
437465
if(wcslen(pStr)==0) goto InvalidOption; //if no version
438466
{
439467
int major=-1,minor=-1;
440-
if(swscanf_s(pStr,W("%d.%d"),&major, &minor)==2)
468+
NarrowForNumberParsing str{pStr};
469+
if(sscanf_s(str,"%d.%d",&major, &minor)==2)
441470
{
442471
if((major >= 0)&&(major < 0xFFFF))
443472
pAsm->m_wSSVersionMajor = (WORD)major;
@@ -452,8 +481,9 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv)
452481
WCHAR *pStr = EqualOrColon(argv[i]);
453482
if(pStr == NULL) goto InvalidOption;
454483
pStr++;
455-
const WCHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? W("%lx") : W("%ld");
456-
if(swscanf_s(pStr,pFmt,&g_dwFileAlignment)!=1) goto InvalidOption;
484+
const CHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? "%x" : "%d";
485+
NarrowForNumberParsing str{pStr};
486+
if(sscanf_s(str,pFmt,&g_dwFileAlignment)!=1) goto InvalidOption;
457487
if((g_dwFileAlignment & (g_dwFileAlignment-1))
458488
|| (g_dwFileAlignment < 0x200) || (g_dwFileAlignment > 0x10000))
459489
{
@@ -466,16 +496,18 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv)
466496
WCHAR *pStr = EqualOrColon(argv[i]);
467497
if(pStr == NULL) goto InvalidOption;
468498
pStr++;
469-
const WCHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? W("%lx") : W("%ld");
470-
if(swscanf_s(pStr,pFmt,&g_dwComImageFlags)!=1) goto InvalidOption;
499+
const CHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? "%x" : "%d";
500+
NarrowForNumberParsing str{pStr};
501+
if(sscanf_s(str,pFmt,&g_dwComImageFlags)!=1) goto InvalidOption;
471502
}
472503
else if (!_stricmp(szOpt, "BAS"))
473504
{
474505
WCHAR *pStr = EqualOrColon(argv[i]);
475506
if(pStr == NULL) goto InvalidOption;
476507
pStr++;
477-
const WCHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? W("%I64x") : W("%I64d");
478-
if(swscanf_s(pStr,pFmt,&g_stBaseAddress)!=1) goto InvalidOption;
508+
const CHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? "%llx" : "%lld";
509+
NarrowForNumberParsing str{pStr};
510+
if(sscanf_s(str,pFmt,&g_stBaseAddress)!=1) goto InvalidOption;
479511
if(g_stBaseAddress & 0xFFFF)
480512
{
481513
fprintf(stderr,"\nBase address must be 0x10000-aligned\n");
@@ -487,17 +519,19 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv)
487519
WCHAR *pStr = EqualOrColon(argv[i]);
488520
if(pStr == NULL) goto InvalidOption;
489521
pStr++;
490-
const WCHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? W("%lx") : W("%ld");
491-
if(swscanf_s(pStr,pFmt,&g_stSizeOfStackReserve)!=1) goto InvalidOption;
522+
const CHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? "%x" : "%d";
523+
NarrowForNumberParsing str{pStr};
524+
if(sscanf_s(str,pFmt,&g_stSizeOfStackReserve)!=1) goto InvalidOption;
492525
}
493526
#ifdef _SPECIAL_INTERNAL_USE_ONLY
494527
else if (!_stricmp(szOpt, "TES"))
495528
{
496529
WCHAR *pStr = EqualOrColon(argv[i]);
497530
if(pStr == NULL) goto InvalidOption;
498531
pStr++;
499-
WCHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? L"%lx" : L"%ld";
500-
if(swscanf_s(pStr,pFmt,&g_dwTestRepeat)!=1) goto InvalidOption;
532+
const CHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? "%x" : "%d";
533+
NarrowForNumberParsing str{pStr};
534+
if(sscanf_s(str,pFmt,&g_dwTestRepeat)!=1) goto InvalidOption;
501535
}
502536
#endif
503537
else
@@ -592,7 +626,7 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv)
592626
do
593627
{
594628
j--;
595-
if(wzOutputFilename[j] == L'.')
629+
if(wzOutputFilename[j] == W('.'))
596630
{
597631
wzOutputFilename[j] = 0;
598632
break;
@@ -604,7 +638,7 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv)
604638
if (pAsm->m_fGeneratePDB)
605639
{
606640
wcscpy_s(wzPdbFilename, MAX_FILENAME_LENGTH, wzOutputFilename);
607-
WCHAR* extPos = wcsrchr(wzPdbFilename, L'.');
641+
WCHAR* extPos = wcsrchr(wzPdbFilename, W('.'));
608642
if (extPos != NULL)
609643
*extPos = 0;
610644
wcscat_s(wzPdbFilename, MAX_FILENAME_LENGTH, W(".pdb"));
@@ -805,11 +839,11 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv)
805839
if (exitval || !bGeneratePdb)
806840
{
807841
// PE file was not created, or no debug info required. Kill PDB if any
808-
WCHAR* pc = wcsrchr(wzOutputFilename,L'.');
842+
WCHAR* pc = wcsrchr(wzOutputFilename,W('.'));
809843
if(pc==NULL)
810844
{
811845
pc = &wzOutputFilename[wcslen(wzOutputFilename)];
812-
*pc = L'.';
846+
*pc = W('.');
813847
}
814848
wcscpy_s(pc+1,4,W("PDB"));
815849
#undef DeleteFileW

src/coreclr/pal/inc/pal.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4059,7 +4059,6 @@ PAL_GetCurrentThreadAffinitySet(SIZE_T size, UINT_PTR* data);
40594059
#define exit PAL_exit
40604060
#define printf PAL_printf
40614061
#define vprintf PAL_vprintf
4062-
#define wprintf PAL_wprintf
40634062
#define wcstod PAL_wcstod
40644063
#define wcstoul PAL_wcstoul
40654064
#define wcscat PAL_wcscat
@@ -4069,7 +4068,6 @@ PAL_GetCurrentThreadAffinitySet(SIZE_T size, UINT_PTR* data);
40694068
#define wcschr PAL_wcschr
40704069
#define wcsrchr PAL_wcsrchr
40714070
#define wcsstr PAL_wcsstr
4072-
#define swscanf PAL_swscanf
40734071
#define wcspbrk PAL_wcspbrk
40744072
#define wcscmp PAL_wcscmp
40754073
#define wcsncpy PAL_wcsncpy
@@ -4079,9 +4077,7 @@ PAL_GetCurrentThreadAffinitySet(SIZE_T size, UINT_PTR* data);
40794077
#define strtoul PAL_strtoul
40804078
#define strtoull PAL_strtoull
40814079
#define fprintf PAL_fprintf
4082-
#define fwprintf PAL_fwprintf
40834080
#define vfprintf PAL_vfprintf
4084-
#define vfwprintf PAL_vfwprintf
40854081
#define rand PAL_rand
40864082
#define time PAL_time
40874083
#define getenv PAL_getenv
@@ -4258,9 +4254,6 @@ PALIMPORT DLLEXPORT const WCHAR * __cdecl PAL_wcschr(const WCHAR *, WCHAR);
42584254
PALIMPORT DLLEXPORT const WCHAR * __cdecl PAL_wcsrchr(const WCHAR *, WCHAR);
42594255
PALIMPORT WCHAR _WConst_return * __cdecl PAL_wcspbrk(const WCHAR *, const WCHAR *);
42604256
PALIMPORT DLLEXPORT WCHAR _WConst_return * __cdecl PAL_wcsstr(const WCHAR *, const WCHAR *);
4261-
PALIMPORT int __cdecl PAL_swprintf(WCHAR *, const WCHAR *, ...);
4262-
PALIMPORT int __cdecl PAL_vswprintf(WCHAR *, const WCHAR *, va_list);
4263-
PALIMPORT int __cdecl PAL_swscanf(const WCHAR *, const WCHAR *, ...);
42644257
PALIMPORT DLLEXPORT ULONG __cdecl PAL_wcstoul(const WCHAR *, WCHAR **, int);
42654258
PALIMPORT double __cdecl PAL_wcstod(const WCHAR *, WCHAR **);
42664259

@@ -4494,9 +4487,6 @@ PALIMPORT LONG __cdecl PAL_ftell(PAL_FILE *);
44944487
PALIMPORT int __cdecl PAL_ferror(PAL_FILE *);
44954488
PALIMPORT PAL_FILE * __cdecl PAL_fopen(const char *, const char *);
44964489
PALIMPORT int __cdecl PAL_setvbuf(PAL_FILE *stream, char *, int, size_t);
4497-
PALIMPORT DLLEXPORT int __cdecl PAL_fwprintf(PAL_FILE *, const WCHAR *, ...);
4498-
PALIMPORT int __cdecl PAL_vfwprintf(PAL_FILE *, const WCHAR *, va_list);
4499-
PALIMPORT int __cdecl PAL_wprintf(const WCHAR*, ...);
45004490

45014491
PALIMPORT int __cdecl _getw(PAL_FILE *);
45024492
PALIMPORT int __cdecl _putw(int, PAL_FILE *);

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,8 +672,6 @@ The wrappers below are simple implementations that may not be as robust as compl
672672
Remember to fix the errcode definition in safecrt.h.
673673
*/
674674

675-
#define swscanf_s swscanf
676-
677675
#define _wfopen_s _wfopen_unsafe
678676
#define fopen_s _fopen_unsafe
679677

0 commit comments

Comments
 (0)