aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2015-11-23 12:19:22 +0100
committerMarc André Tanner <mat@brain-dump.org>2015-11-23 14:18:27 +0100
commitfafecaec125938b656ae873d7efa80858ebd2dcf (patch)
tree396ed2ebe382dd733110ace42fdc5bc9dab8b28c
parentc1584693cbb2d9ea2f2cfb4fc528da30b2554a91 (diff)
downloadvis-fafecaec125938b656ae873d7efa80858ebd2dcf.tar.gz
vis-fafecaec125938b656ae873d7efa80858ebd2dcf.tar.xz
Cast argument to ctype.h is* functions to unsigned char
The signedness of char is implemenation defined, calling the is* type of functions with negative values leads to undefined behaviour.
-rw-r--r--text-motions.c54
-rw-r--r--text-objects.c20
2 files changed, 37 insertions, 37 deletions
diff --git a/text-motions.c b/text-motions.c
index 16e448d..8d49122 100644
--- a/text-motions.c
+++ b/text-motions.c
@@ -146,7 +146,7 @@ size_t text_line_begin(Text *txt, size_t pos) {
size_t text_line_start(Text *txt, size_t pos) {
char c;
Iterator it = text_iterator_get(txt, text_line_begin(txt, pos));
- while (text_iterator_byte_get(&it, &c) && c != '\n' && isspace(c))
+ while (text_iterator_byte_get(&it, &c) && c != '\n' && isspace((unsigned char)c))
text_iterator_byte_next(&it, NULL);
return it.pos;
}
@@ -155,7 +155,7 @@ size_t text_line_finish(Text *txt, size_t pos) {
char c;
Iterator it = text_iterator_get(txt, text_line_end(txt, pos));
do text_iterator_char_prev(&it, NULL);
- while (text_iterator_byte_get(&it, &c) && c != '\n' && isspace(c));
+ while (text_iterator_byte_get(&it, &c) && c != '\n' && isspace((unsigned char)c));
return it.pos;
}
@@ -281,33 +281,33 @@ static size_t text_customword_start_next(Text *txt, size_t pos, int (*isboundry)
Iterator it = text_iterator_get(txt, pos);
if (!text_iterator_byte_get(&it, &c))
return pos;
- if (isboundry(c))
- while (isboundry(c) && !isspace(c) && text_iterator_char_next(&it, &c));
+ if (isboundry((unsigned char)c))
+ while (isboundry((unsigned char)c) && !isspace((unsigned char)c) && text_iterator_char_next(&it, &c));
else
- while (!isboundry(c) && text_iterator_char_next(&it, &c));
- while (isspace(c) && text_iterator_char_next(&it, &c));
+ while (!isboundry((unsigned char)c) && text_iterator_char_next(&it, &c));
+ while (isspace((unsigned char)c) && text_iterator_char_next(&it, &c));
return it.pos;
}
static size_t text_customword_start_prev(Text *txt, size_t pos, int (*isboundry)(int)) {
char c;
Iterator it = text_iterator_get(txt, pos);
- while (text_iterator_char_prev(&it, &c) && isspace(c));
- if (isboundry(c))
- do pos = it.pos; while (text_iterator_char_prev(&it, &c) && isboundry(c) && !isspace(c));
+ while (text_iterator_char_prev(&it, &c) && isspace((unsigned char)c));
+ if (isboundry((unsigned char)c))
+ do pos = it.pos; while (text_iterator_char_prev(&it, &c) && isboundry((unsigned char)c) && !isspace((unsigned char)c));
else
- do pos = it.pos; while (text_iterator_char_prev(&it, &c) && !isboundry(c));
+ do pos = it.pos; while (text_iterator_char_prev(&it, &c) && !isboundry((unsigned char)c));
return pos;
}
static size_t text_customword_end_next(Text *txt, size_t pos, int (*isboundry)(int)) {
char c;
Iterator it = text_iterator_get(txt, pos);
- while (text_iterator_char_next(&it, &c) && isspace(c));
- if (isboundry(c))
- do pos = it.pos; while (text_iterator_char_next(&it, &c) && isboundry(c) && !isspace(c));
+ while (text_iterator_char_next(&it, &c) && isspace((unsigned char)c));
+ if (isboundry((unsigned char)c))
+ do pos = it.pos; while (text_iterator_char_next(&it, &c) && isboundry((unsigned char)c) && !isspace((unsigned char)c));
else
- do pos = it.pos; while (text_iterator_char_next(&it, &c) && !isboundry(c));
+ do pos = it.pos; while (text_iterator_char_next(&it, &c) && !isboundry((unsigned char)c));
return pos;
}
@@ -316,11 +316,11 @@ static size_t text_customword_end_prev(Text *txt, size_t pos, int (*isboundry)(i
Iterator it = text_iterator_get(txt, pos);
if (!text_iterator_byte_get(&it, &c))
return pos;
- if (isboundry(c))
- while (isboundry(c) && !isspace(c) && text_iterator_char_prev(&it, &c));
+ if (isboundry((unsigned char)c))
+ while (isboundry((unsigned char)c) && !isspace((unsigned char)c) && text_iterator_char_prev(&it, &c));
else
- while (!isboundry(c) && text_iterator_char_prev(&it, &c));
- while (isspace(c) && text_iterator_char_prev(&it, &c));
+ while (!isboundry((unsigned char)c) && text_iterator_char_prev(&it, &c));
+ while (isspace((unsigned char)c) && text_iterator_char_prev(&it, &c));
return it.pos;
}
@@ -361,8 +361,8 @@ static size_t text_paragraph_sentence_next(Text *txt, size_t pos, bool sentence)
bool content = false, paragraph = false;
Iterator it = text_iterator_get(txt, pos);
while (text_iterator_byte_next(&it, &c)) {
- content |= !isspace(c);
- if (sentence && (c == '.' || c == '?' || c == '!') && text_iterator_byte_next(&it, &c) && isspace(c)) {
+ content |= !isspace((unsigned char)c);
+ if (sentence && (c == '.' || c == '?' || c == '!') && text_iterator_byte_next(&it, &c) && isspace((unsigned char)c)) {
if (c == '\n' && text_iterator_byte_next(&it, &c)) {
if (c == '\r')
text_iterator_byte_next(&it, &c);
@@ -375,7 +375,7 @@ static size_t text_paragraph_sentence_next(Text *txt, size_t pos, bool sentence)
if (c == '\n' && text_iterator_byte_next(&it, &c)) {
if (c == '\r')
text_iterator_byte_next(&it, &c);
- content |= !isspace(c);
+ content |= !isspace((unsigned char)c);
if (c == '\n')
paragraph = true;
}
@@ -394,30 +394,30 @@ static size_t text_paragraph_sentence_prev(Text *txt, size_t pos, bool sentence)
return pos;
while (text_iterator_byte_prev(&it, &c)) {
- content |= !isspace(c) && c != '.' && c != '?' && c != '!';
- if (sentence && content && (c == '.' || c == '?' || c == '!') && isspace(prev)) {
+ content |= !isspace((unsigned char)c) && c != '.' && c != '?' && c != '!';
+ if (sentence && content && (c == '.' || c == '?' || c == '!') && isspace((unsigned char)prev)) {
do text_iterator_byte_next(&it, NULL);
- while (text_iterator_byte_get(&it, &c) && isspace(c));
+ while (text_iterator_byte_get(&it, &c) && isspace((unsigned char)c));
break;
}
if (c == '\r')
text_iterator_byte_prev(&it, &c);
if (c == '\n' && text_iterator_byte_prev(&it, &c)) {
- content |= !isspace(c);
+ content |= !isspace((unsigned char)c);
if (c == '\r')
text_iterator_byte_prev(&it, &c);
if (c == '\n') {
paragraph = true;
if (content) {
do text_iterator_byte_next(&it, NULL);
- while (text_iterator_byte_get(&it, &c) && isspace(c));
+ while (text_iterator_byte_get(&it, &c) && isspace((unsigned char)c));
break;
}
}
}
if (content && paragraph) {
do text_iterator_byte_next(&it, NULL);
- while (text_iterator_byte_get(&it, &c) && !isspace(c));
+ while (text_iterator_byte_get(&it, &c) && !isspace((unsigned char)c));
break;
}
prev = c;
diff --git a/text-objects.c b/text-objects.c
index d786a2d..a85d70f 100644
--- a/text-objects.c
+++ b/text-objects.c
@@ -50,19 +50,19 @@ Filerange text_object_longword(Text *txt, size_t pos) {
if (text_iterator_byte_prev(&it, &prev))
text_iterator_byte_next(&it, NULL);
text_iterator_byte_next(&it, &next);
- if (isspace(c)) {
+ if (isspace((unsigned char)c)) {
/* middle of two words */
r.start = text_char_next(txt, text_longword_end_prev(txt, pos));
r.end = text_longword_start_next(txt, pos);
- } else if (isspace(prev) && isspace(next)) {
+ } else if (isspace((unsigned char)prev) && isspace((unsigned char)next)) {
/* on a single character */
r.start = pos;
r.end = text_char_next(txt, pos);
- } else if (isspace(prev)) {
+ } else if (isspace((unsigned char)prev)) {
/* at start of a word */
r.start = pos;
r.end = text_char_next(txt, text_longword_end_next(txt, pos));
- } else if (isspace(next)) {
+ } else if (isspace((unsigned char)next)) {
/* at end of a word */
r.start = text_longword_start_prev(txt, pos);
r.end = text_char_next(txt, pos);
@@ -83,19 +83,19 @@ Filerange text_object_longword_outer(Text *txt, size_t pos) {
if (text_iterator_byte_prev(&it, &prev))
text_iterator_byte_next(&it, NULL);
text_iterator_byte_next(&it, &next);
- if (isspace(c)) {
+ if (isspace((unsigned char)c)) {
/* middle of two words, include leading white space */
r.start = text_char_next(txt, text_longword_end_prev(txt, pos));
r.end = text_char_next(txt, text_longword_end_next(txt, pos));
- } else if (isspace(prev) && isspace(next)) {
+ } else if (isspace((unsigned char)prev) && isspace((unsigned char)next)) {
/* on a single character */
r.start = pos;
r.end = text_longword_start_next(txt, pos);
- } else if (isspace(prev)) {
+ } else if (isspace((unsigned char)prev)) {
/* at start of a word */
r.start = pos;
r.end = text_longword_start_next(txt, text_longword_end_next(txt, pos));
- } else if (isspace(next)) {
+ } else if (isspace((unsigned char)next)) {
/* at end of a word */
r.start = text_longword_start_prev(txt, pos);
r.end = text_longword_start_next(txt, pos);
@@ -116,7 +116,7 @@ Filerange text_object_word(Text *txt, size_t pos) {
if (text_iterator_byte_prev(&it, &prev))
text_iterator_byte_next(&it, NULL);
text_iterator_byte_next(&it, &next);
- if (isspace(c)) {
+ if (isspace((unsigned char)c)) {
r.start = text_char_next(txt, text_word_end_prev(txt, pos));
r.end = text_word_start_next(txt, pos);
} else if (isboundry(prev) && isboundry(next)) {
@@ -154,7 +154,7 @@ Filerange text_object_word_outer(Text *txt, size_t pos) {
if (text_iterator_byte_prev(&it, &prev))
text_iterator_byte_next(&it, NULL);
text_iterator_byte_next(&it, &next);
- if (isspace(c)) {
+ if (isspace((unsigned char)c)) {
/* middle of two words, include leading white space */
r.start = text_char_next(txt, text_word_end_prev(txt, pos));
r.end = text_word_end_next(txt, pos);