Skip to content

Commit 8256846

Browse files
authored
Avoid using strcasecmp and unroll the comparison to 'snan' instead (swiftlang#39182)
1 parent cffc1b2 commit 8256846

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

stdlib/public/stubs/Stubs.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,16 +265,19 @@ swift_stdlib_readLine_stdin(unsigned char **LinePtr) {
265265
#endif
266266
}
267267

268-
#if defined(__CYGWIN__) || defined(_WIN32)
269-
#define strcasecmp _stricmp
270-
#endif
271-
272268
static bool swift_stringIsSignalingNaN(const char *nptr) {
273269
if (nptr[0] == '+' || nptr[0] == '-') {
274270
++nptr;
275271
}
276272

277-
return strcasecmp(nptr, "snan") == 0;
273+
if ((nptr[0] == 's' || nptr[0] == 'S') &&
274+
(nptr[1] == 'n' || nptr[1] == 'N') &&
275+
(nptr[2] == 'a' || nptr[2] == 'A') &&
276+
(nptr[3] == 'n' || nptr[3] == 'N') && (nptr[4] == '\0')) {
277+
return true;
278+
}
279+
280+
return false;
278281
}
279282

280283
// This implementation should only be used on platforms without the

0 commit comments

Comments
 (0)