Repository: lucy-charmonizer
Updated Branches:
refs/heads/master 38166d425 -> 4fd8d9ceb
Avoid undefined behavior in ctype.h functions
>From the C89 spec:
The header <ctype.h> declares several functions useful for testing
and mapping characters. In all cases the argument is an int, the
value of which shall be representable as an unsigned char or shall
equal the value of the macro EOF. If the argument has any other
value, the behavior is undefined.
Project: http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/commit/36094970
Tree: http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/tree/36094970
Diff: http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/diff/36094970
Branch: refs/heads/master
Commit: 3609497016d55d4d550eaf81b826649061ba68ec
Parents: 38166d4
Author: Nick Wellnhofer <[email protected]>
Authored: Wed Apr 6 12:34:36 2016 +0200
Committer: Nick Wellnhofer <[email protected]>
Committed: Wed Apr 6 12:34:36 2016 +0200
----------------------------------------------------------------------
src/Charmonizer/Core/CLI.c | 5 +++--
src/Charmonizer/Core/ConfWriterC.c | 4 ++--
src/Charmonizer/Core/Make.c | 2 +-
src/Charmonizer/Core/OperatingSystem.c | 4 ++--
src/Charmonizer/Probe.c | 4 ++--
src/Charmonizer/Probe/Headers.c | 4 ++--
6 files changed, 12 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/36094970/src/Charmonizer/Core/CLI.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Core/CLI.c b/src/Charmonizer/Core/CLI.c
index 4ce20c3..1994b79 100644
--- a/src/Charmonizer/Core/CLI.c
+++ b/src/Charmonizer/Core/CLI.c
@@ -112,7 +112,8 @@ S_chaz_CLI_rebuild_help(chaz_CLI *self) {
}
self->help[current_len++] = '=';
for (j = 0; opt->name[j]; j++) {
- self->help[current_len++] = toupper(opt->name[j]);
+ unsigned char c = (unsigned char)opt->name[j];
+ self->help[current_len++] = toupper(c);
}
if (opt->flags & CHAZ_CLI_ARG_OPTIONAL) {
self->help[current_len++] = ']';
@@ -330,7 +331,7 @@ chaz_CLI_parse(chaz_CLI *self, int argc, const char
*argv[]) {
/* Extract the name of the argument, look for a potential value. */
while (1) {
char c = arg[name_len + 2];
- if (isalnum(c) || c == '-' || c == '_') {
+ if (isalnum((unsigned char)c) || c == '-' || c == '_') {
name_len++;
}
else if (c == '\0') {
http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/36094970/src/Charmonizer/Core/ConfWriterC.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Core/ConfWriterC.c
b/src/Charmonizer/Core/ConfWriterC.c
index 1b0b7c4..0a9c20d 100644
--- a/src/Charmonizer/Core/ConfWriterC.c
+++ b/src/Charmonizer/Core/ConfWriterC.c
@@ -142,7 +142,7 @@ chaz_ConfWriterC_vappend_conf(const char *fmt, va_list
args) {
static int
chaz_ConfWriterC_sym_is_uppercase(const char *sym) {
- return isupper(sym[0]);
+ return isupper((unsigned char)sym[0]);
}
static char*
@@ -150,7 +150,7 @@ chaz_ConfWriterC_uppercase_string(const char *src) {
char *retval = chaz_Util_strdup(src);
size_t i;
for (i = 0; retval[i]; ++i) {
- retval[i] = toupper(retval[i]);
+ retval[i] = toupper((unsigned char)retval[i]);
}
return retval;
}
http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/36094970/src/Charmonizer/Core/Make.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Core/Make.c b/src/Charmonizer/Core/Make.c
index abc9a74..c9ef7bb 100644
--- a/src/Charmonizer/Core/Make.c
+++ b/src/Charmonizer/Core/Make.c
@@ -861,7 +861,7 @@ chaz_Make_list_files(const char *dir, const char *ext,
/* Strip whitespace from end of output. */
for (prefix_len = output_len; prefix_len > 0; --prefix_len) {
- if (!isspace(output[prefix_len-1])) { break; }
+ if (!isspace((unsigned char)output[prefix_len-1])) { break; }
}
prefix = (char*)malloc(prefix_len + 2);
memcpy(prefix, output, prefix_len);
http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/36094970/src/Charmonizer/Core/OperatingSystem.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Core/OperatingSystem.c
b/src/Charmonizer/Core/OperatingSystem.c
index 513ce44..c872b68 100644
--- a/src/Charmonizer/Core/OperatingSystem.c
+++ b/src/Charmonizer/Core/OperatingSystem.c
@@ -74,8 +74,8 @@ chaz_OS_init(void) {
uname = chaz_OS_run_and_capture("uname", &uname_len);
for (i = 0; i < CHAZ_OS_NAME_MAX && i < uname_len; i++) {
char c = uname[i];
- if (!c || isspace(c)) { break; }
- chaz_OS.name[i] = tolower(c);
+ if (!c || isspace((unsigned char)c)) { break; }
+ chaz_OS.name[i] = tolower((unsigned char)c);
}
if (i > 0) { chaz_OS.name[i] = '\0'; }
else { strcpy(chaz_OS.name, "unknown_unix"); }
http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/36094970/src/Charmonizer/Probe.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Probe.c b/src/Charmonizer/Probe.c
index d282b08..1a574af 100644
--- a/src/Charmonizer/Probe.c
+++ b/src/Charmonizer/Probe.c
@@ -82,10 +82,10 @@ chaz_Probe_parse_cli_args(int argc, const char *argv[],
chaz_CLI *cli) {
size_t r = len;
size_t trimmed_len;
- while (isspace(arg[l])) {
+ while (isspace((unsigned char)arg[l])) {
++l;
}
- while (r > l && isspace(arg[r-1])) {
+ while (r > l && isspace((unsigned char)arg[r-1])) {
--r;
}
http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/36094970/src/Charmonizer/Probe/Headers.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Probe/Headers.c b/src/Charmonizer/Probe/Headers.c
index 0a69464..b17ab97 100644
--- a/src/Charmonizer/Probe/Headers.c
+++ b/src/Charmonizer/Probe/Headers.c
@@ -114,8 +114,8 @@ chaz_Headers_encode_affirmation(const char *header_name,
char *buffer, size_t bu
*buf = '\0';
break;
}
- else if (isalnum(*header_name)) {
- *buf = toupper(*header_name);
+ else if (isalnum((unsigned char)*header_name)) {
+ *buf = toupper((unsigned char)*header_name);
}
else {
*buf = '_';