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

<cctype>: do not defend against isalnum/etc. macros #2147

Merged
merged 1 commit into from
Aug 27, 2021

Conversation

fsb4000
Copy link
Contributor

@fsb4000 fsb4000 commented Aug 22, 2021

Fixes #259

C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\ctype.h

#if defined _CRT_DISABLE_PERFCRIT_LOCKS && !defined _DLL && !defined __cplusplus
        #define isalpha(c)  (MB_CUR_MAX > 1 ? _isctype(c, _ALPHA) : __chvalidchk(c, _ALPHA))
        #define isupper(c)  (MB_CUR_MAX > 1 ? _isctype(c, _UPPER) : __chvalidchk(c, _UPPER))
        #define islower(c)  (MB_CUR_MAX > 1 ? _isctype(c, _LOWER) : __chvalidchk(c, _LOWER))
        #define isdigit(c)  (MB_CUR_MAX > 1 ? _isctype(c, _DIGIT) : __chvalidchk(c, _DIGIT))
        #define isxdigit(c) (MB_CUR_MAX > 1 ? _isctype(c, _HEX)   : __chvalidchk(c, _HEX))
        #define isspace(c)  (MB_CUR_MAX > 1 ? _isctype(c, _SPACE) : __chvalidchk(c, _SPACE))
        #define ispunct(c)  (MB_CUR_MAX > 1 ? _isctype(c, _PUNCT) : __chvalidchk(c, _PUNCT))
        #define isblank(c)  (MB_CUR_MAX > 1 ? (((c) == '\t') ? _BLANK : _isctype(c, _BLANK)) : (((c) == '\t') ? _BLANK : __chvalidchk(c, _BLANK)))
        #define isalnum(c)  (MB_CUR_MAX > 1 ? _isctype(c, _ALPHA | _DIGIT) : __chvalidchk(c, (_ALPHA | _DIGIT)))
        #define isprint(c)  (MB_CUR_MAX > 1 ? _isctype(c, _BLANK | _PUNCT | _ALPHA | _DIGIT) : __chvalidchk(c, (_BLANK | _PUNCT | _ALPHA | _DIGIT)))
        #define isgraph(c)  (MB_CUR_MAX > 1 ? _isctype(c, _PUNCT | _ALPHA | _DIGIT) : __chvalidchk(c, (_PUNCT | _ALPHA | _DIGIT)))
        #define iscntrl(c)  (MB_CUR_MAX > 1 ? _isctype(c, _CONTROL) : __chvalidchk(c, _CONTROL))
    #endif

also

_Check_return_ _CRT_JIT_INTRINSIC _ACRTIMP int __cdecl isalpha(_In_ int _C);
_Check_return_ _CRT_JIT_INTRINSIC _ACRTIMP int __cdecl isupper(_In_ int _C);
_Check_return_ _CRT_JIT_INTRINSIC _ACRTIMP int __cdecl islower(_In_ int _C);
...
_Check_return_ _ACRTIMP int __cdecl iscntrl(_In_ int _C);

So non macro versions exist and the macros guarded with !defined __cplusplus

@fsb4000 fsb4000 requested a review from a team as a code owner August 22, 2021 05:07
@fsb4000 fsb4000 changed the title do not defend against isalnum/etc. macros <cctype>: do not defend against isalnum/etc. macros Aug 22, 2021
@AlexGuteniev
Copy link
Contributor

But what if older SDK is used?

@fsb4000
Copy link
Contributor Author

fsb4000 commented Aug 22, 2021

I opened my oldest VS installed: 2005 with Windows 2003 SDK. (the last SDK and VS which support Windows 98)

<cctype> has

// remove any (improper) macro overrides
#undef isalnum
#undef isalpha
#undef isblank
#undef iscntrl
#undef isdigit
#undef isgraph
#undef islower
#undef isprint
#undef ispunct
#undef isspace
#undef isupper
#undef isxdigit
#undef tolower
#undef toupper

But it seems that is not necessary even for the Windows 2003 SDK

Some screenshots: https://imgur.com/a/GApNpBX

@CaseyCarter CaseyCarter added the enhancement Something can be improved label Aug 23, 2021
Copy link
Member

@StephanTLavavej StephanTLavavej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the archaeological investigation here!

@StephanTLavavej StephanTLavavej self-assigned this Aug 26, 2021
@StephanTLavavej
Copy link
Member

I'm mirroring this to an MSVC-internal PR. Please notify me if any further changes are pushed.

@StephanTLavavej StephanTLavavej merged commit f58b899 into microsoft:main Aug 27, 2021
@StephanTLavavej
Copy link
Member

#define isalnum ThanksForRemovingThisUnnecessaryCode!

@fsb4000 fsb4000 deleted the fix259 branch August 27, 2021 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Something can be improved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

<cctype>: Do we still need to defend against isalnum/etc. macros?
4 participants