summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/3p/chibicc/tokenize.c28
-rw-r--r--src/build/codegen.c12
2 files changed, 11 insertions, 29 deletions
diff --git a/src/3p/chibicc/tokenize.c b/src/3p/chibicc/tokenize.c
index 3b15df9..b13edd5 100644
--- a/src/3p/chibicc/tokenize.c
+++ b/src/3p/chibicc/tokenize.c
@@ -330,9 +330,11 @@ static Token *read_char_literal(char *start, char *quote, Type *ty) {
else
c = decode_utf8(&p, p);
- char *end = strchr(p, '\'');
- if (!end)
- error_at(p, "unclosed char literal");
+ char *end = p;
+ for (; *end != '\''; ++end) {
+ if (!*end || *end == '\n')
+ error_at(p, "unclosed char literal");
+ }
Token *tok = new_token(TK_NUM, start, end + 1);
tok->val = c;
@@ -691,25 +693,6 @@ File *new_file(char *name, int file_no, char *contents) {
return file;
}
-// Replaces \r or \r\n with \n.
-static void canonicalize_newline(char *p) {
- int i = 0, j = 0;
-
- while (p[i]) {
- if (p[i] == '\r' && p[i + 1] == '\n') {
- i += 2;
- p[j++] = '\n';
- } else if (p[i] == '\r') {
- i++;
- p[j++] = '\n';
- } else {
- p[j++] = p[i++];
- }
- }
-
- p[j] = '\0';
-}
-
// Removes backslashes followed by a newline.
static void remove_backslash_newline(char *p) {
int i = 0, j = 0;
@@ -781,7 +764,6 @@ static void convert_universal_chars(char *p) {
// NOTE modified API from upstream
Token *tokenize_buf(const char *name, char *p) {
- canonicalize_newline(p);
remove_backslash_newline(p);
convert_universal_chars(p);
diff --git a/src/build/codegen.c b/src/build/codegen.c
index bf3ae1e..e24a096 100644
--- a/src/build/codegen.c
+++ b/src/build/codegen.c
@@ -81,14 +81,14 @@ static inline int cmp_feature(struct feature *e, const char *s) {
}
static inline int cmp_feature_bydesc(struct feature *e, const char *s) {
for (const char *p = e->desc; ; ++p, ++s) {
- // longer string first
- if (!*s) return !!*p; else if (!*p) return -1;
+ // shortest string first
+ if (!*p) return !!*s; if (!*s) return -1;
// case insensitive sort where possible
- if (tolower(*p) > tolower(*s)) return 1;
- if (tolower(*p) < tolower(*s)) return -1;
+ if (tolower((uchar)*p) > tolower((uchar)*s)) return 1;
+ if (tolower((uchar)*p) < tolower((uchar)*s)) return -1;
// prioritise upper-case if same letter
- if (isupper(*p) && islower(*s)) return 1;
- if (islower(*p) && isupper(*s)) return -1;
+ if (isupper((uchar)*p) && islower((uchar)*s)) return 1;
+ if (islower((uchar)*p) && isupper((uchar)*s)) return -1;
}
return 0;
}