From 1a47ee108c7a5565ce692f2dc139244a08cc0206 Mon Sep 17 00:00:00 2001 From: Hostile Fork Date: Tue, 14 Jul 2015 17:49:59 -0400 Subject: [PATCH] Make host_args.c obey REBCHR sizing I'm not exactly sure how the Windows build worked when the argument processing wasn't obeying the rules for REBCHR being a wide character. This makes sure the comparisons being done are on the wchar_t type in the Win32 build. As a reminder: I think REBCHR is indicative of a design problem, so I don't feel great about adding another OS_STRxxx wrapper. But at least it is "quarantined". --- src/core/n-strings.c | 18 +++++++++++++++++- src/os/host-args.c | 36 ++++++++++++++++++------------------ 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/core/n-strings.c b/src/core/n-strings.c index 5bcac992f1..50eeda85dc 100644 --- a/src/core/n-strings.c +++ b/src/core/n-strings.c @@ -946,6 +946,22 @@ static struct digest { } +/*********************************************************************** +** +*/ int OS_STRNCMP_(const REBCHR *lhs, const REBCHR *rhs, size_t max) +/* +** Debug-only REBCHR-checked substitute for OS_STRNCMP macro +** +***********************************************************************/ +{ +#ifdef OS_WIDE_CHAR + return wcsncmp(cast(const wchar_t*, lhs), cast(const wchar_t*, rhs), max); +#else + return strncmp(cast(const char*, lhs), cast (const char*, rhs), max); +#endif +} + + /*********************************************************************** ** */ size_t OS_STRLEN_(const REBCHR *str) @@ -971,7 +987,7 @@ static struct digest { ***********************************************************************/ { #ifdef OS_WIDE_CHAR - return wcschr(cast(const wchar_t*, str), ch); + return cast(REBCHR*, wcschr(cast(const wchar_t*, str), ch)); #else // We have to m_cast because C++ actually has a separate overload of // strchr which will return a const pointer if the in pointer was const diff --git a/src/os/host-args.c b/src/os/host-args.c index 81a9edc65a..19d3b29384 100644 --- a/src/os/host-args.c +++ b/src/os/host-args.c @@ -47,23 +47,23 @@ // REBOL Option --Words: -const struct {const char *word; const int flag;} arg_words[] = { +const struct {REBCHR *word; const int flag;} arg_words[] = { // Keep in Alpha order! - {"args", RO_ARGS | RO_EXT}, - {"boot", RO_BOOT | RO_EXT}, - {"cgi", RO_CGI | RO_QUIET}, - {"debug", RO_DEBUG | RO_EXT}, - {"do", RO_DO | RO_EXT}, - {"halt", RO_HALT}, - {"help", RO_HELP}, - {"import", RO_IMPORT | RO_EXT}, - {"quiet", RO_QUIET}, - {"script", RO_SCRIPT | RO_EXT}, - {"secure", RO_SECURE | RO_EXT}, - {"trace", RO_TRACE}, - {"verbose", RO_VERBOSE}, - {"version", RO_VERSION | RO_EXT}, - {"", 0}, + {OS_STR_LIT("args"), RO_ARGS | RO_EXT}, + {OS_STR_LIT("boot"), RO_BOOT | RO_EXT}, + {OS_STR_LIT("cgi"), RO_CGI | RO_QUIET}, + {OS_STR_LIT("debug"), RO_DEBUG | RO_EXT}, + {OS_STR_LIT("do"), RO_DO | RO_EXT}, + {OS_STR_LIT("halt"), RO_HALT}, + {OS_STR_LIT("help"), RO_HELP}, + {OS_STR_LIT("import"), RO_IMPORT | RO_EXT}, + {OS_STR_LIT("quiet"), RO_QUIET}, + {OS_STR_LIT("script"), RO_SCRIPT | RO_EXT}, + {OS_STR_LIT("secure"), RO_SECURE | RO_EXT}, + {OS_STR_LIT("trace"), RO_TRACE}, + {OS_STR_LIT("verbose"), RO_VERBOSE}, + {OS_STR_LIT("version"), RO_VERSION | RO_EXT}, + {OS_STR_LIT(""), 0}, }; // REBOL Option -Characters (in alpha sorted order): @@ -100,7 +100,7 @@ const struct arg_chr arg_chars2[] = { { int n; int i; - char buf[16]; + REBCHR buf[16]; // Some shells will pass us the line terminator. Ignore it. if (word[0] == '\r' || word[0] == '\n') return RO_IGNORE; @@ -108,7 +108,7 @@ const struct arg_chr arg_chars2[] = { OS_STRNCPY(buf, word, 15); for (i = 0; arg_words[i].flag; i++) { - n = strncmp(buf, arg_words[i].word, 15); // correct (bytes) + n = OS_STRNCMP(buf, arg_words[i].word, 15); if (n < 0) break; if (n == 0) return arg_words[i].flag; }