Skip to content

Commit

Permalink
always pass unsigned char to functions in <ctype.h>
Browse files Browse the repository at this point in the history
passing a signed char is not really portable,
and NetBSD is sensitive about this problem.
  • Loading branch information
n-soda committed Aug 3, 2017
1 parent df9a096 commit cdc55ec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,12 @@ static jv f_strptime(jq_state *jq, jv a, jv b) {
const char *fmt = jv_string_value(b);
const char *end = strptime(input, fmt, &tm);

if (end == NULL || (*end != '\0' && !isspace(*end))) {
/*
* "*end" may be a signed char, and passing a value which is less than -1
* to isspace() violates the C standard, thus, casting to (unsigned char *)
* is necessary.
*/
if (end == NULL || (*end != '\0' && !isspace(*(unsigned char *)end))) {
jv e = jv_invalid_with_msg(jv_string_fmt("date \"%s\" does not match format \"%s\"", input, fmt));
jv_free(a);
jv_free(b);
Expand Down
7 changes: 6 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,13 @@ static void die() {



/*
* "text[1]" may be a signed char, and passing a value which is less than -1
* to isalpha() violates the C standard, thus, casting to (unsigned char *)
* is necessary.
*/
static int isoptish(const char* text) {
return text[0] == '-' && (text[1] == '-' || isalpha(text[1]));
return text[0] == '-' && (text[1] == '-' || isalpha(((const unsigned char *)text)[1]));
}

static int isoption(const char* text, char shortopt, const char* longopt, size_t *short_opts) {
Expand Down

0 comments on commit cdc55ec

Please sign in to comment.