diff options
author | Peter Breitenlohner <peb@mppmu.mpg.de> | 2014-06-19 11:14:35 +0000 |
---|---|---|
committer | Peter Breitenlohner <peb@mppmu.mpg.de> | 2014-06-19 11:14:35 +0000 |
commit | e5b8a1a0369901d3d73384cf553619d9351679aa (patch) | |
tree | a0b0d02bb0421b6f6f1dce118d40dfe6e91147b6 /Build/source/utils/t1utils | |
parent | a7803f3483864a647563ebda46f5fa39a92bb205 (diff) |
texk/*/, utils/*/: Avoid undefined behaviour when char is signed
git-svn-id: svn://tug.org/texlive/trunk@34310 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/utils/t1utils')
6 files changed, 186 insertions, 21 deletions
diff --git a/Build/source/utils/t1utils/t1utils-1.38-PATCHES/ChangeLog b/Build/source/utils/t1utils/t1utils-1.38-PATCHES/ChangeLog index 3201d5690f9..5c3a503064b 100644 --- a/Build/source/utils/t1utils/t1utils-1.38-PATCHES/ChangeLog +++ b/Build/source/utils/t1utils/t1utils-1.38-PATCHES/ChangeLog @@ -1,3 +1,7 @@ +2014-06-19 Peter Breitenlohner <peb@mppmu.mpg.de> + + * patch-06-unsigned (new): Avoid undefined behaviour. + 2013-11-22 Peter Breitenlohner <peb@mppmu.mpg.de> * patch-05-getopt (new): Drop '#include <getopt.h>'. diff --git a/Build/source/utils/t1utils/t1utils-1.38-PATCHES/patch-06-unsigned b/Build/source/utils/t1utils/t1utils-1.38-PATCHES/patch-06-unsigned new file mode 100644 index 00000000000..c355deb6c60 --- /dev/null +++ b/Build/source/utils/t1utils/t1utils-1.38-PATCHES/patch-06-unsigned @@ -0,0 +1,161 @@ + Avoid undefined behaviour when char is signed. + +diff -ur t1utils-1.38.orig/t1asm.c t1utils-1.38/t1asm.c +--- t1utils-1.38.orig/t1asm.c 2013-09-29 15:23:22.000000000 +0200 ++++ t1utils-1.38/t1asm.c 2014-06-19 13:08:40.000000000 +0200 +@@ -273,7 +273,7 @@ + static int check_line_charstring(void) + { + char *p = line; +- while (isspace(*p)) ++ while (isspace((unsigned char)*p)) + p++; + return (*p == '/' || (p[0] == 'd' && p[1] == 'u' && p[2] == 'p')); + } +@@ -359,8 +359,8 @@ + + static int is_integer(char *string) + { +- if (isdigit(string[0]) || string[0] == '-' || string[0] == '+') { +- while (*++string && isdigit(*string)) ++ if (isdigit((unsigned char)string[0]) || string[0] == '-' || string[0] == '+') { ++ while (*++string && isdigit((unsigned char)*string)) + ; /* deliberately empty */ + if (!*string) + return 1; +@@ -738,11 +738,11 @@ + t1utils_getline(); + + if (!ever_active) { +- if (strncmp(line, "currentfile eexec", 17) == 0 && isspace(line[17])) { ++ if (strncmp(line, "currentfile eexec", 17) == 0 && isspace((unsigned char)line[17])) { + /* Allow arbitrary whitespace after "currentfile eexec". + Thanks to Tom Kacvinsky <tjk@ams.org> for reporting this. + Note: strlen("currentfile eexec") == 17. */ +- for (p = line + 18; isspace(*p); p++) ++ for (p = line + 18; isspace((unsigned char)*p); p++) + ; + eexec_start(p); + continue; +@@ -756,7 +756,7 @@ + if (q) { + r = cs_start; + ++q; +- while (!isspace(*q) && *q != '{') ++ while (!isspace((unsigned char)*q) && *q != '{') + *r++ = *q++; + *r = '\0'; + } +@@ -765,9 +765,9 @@ + } + + if (!active) { +- if ((p = strstr(line, "/Subrs")) && isdigit(p[7])) ++ if ((p = strstr(line, "/Subrs")) && isdigit((unsigned char)p[7])) + ever_active = active = 1; +- else if ((p = strstr(line, "/CharStrings")) && isdigit(p[13])) ++ else if ((p = strstr(line, "/CharStrings")) && isdigit((unsigned char)p[13])) + ever_active = active = 1; + } + if ((p = strstr(line, "currentfile closefile"))) { +@@ -776,7 +776,7 @@ + /* 1/3/2002 -- happy new year! -- Luc Devroye reports a failure with + some printers when `currentfile closefile' is followed by space */ + p += sizeof("currentfile closefile") - 1; +- for (q = p; isspace(*q) && *q != '\n'; q++) ++ for (q = p; isspace((unsigned char)*q) && *q != '\n'; q++) + /* nada */; + if (q == p && !*q) + error("warning: `currentfile closefile' line too long"); +diff -ur t1utils-1.38.orig/t1disasm.c t1utils-1.38/t1disasm.c +--- t1utils-1.38.orig/t1disasm.c 2013-10-03 14:02:25.000000000 +0200 ++++ t1utils-1.38/t1disasm.c 2014-06-19 13:08:40.000000000 +0200 +@@ -100,7 +100,7 @@ + char *p = strstr(line, "/lenIV "); + + /* Allow lenIV to be negative. Thanks to Tom Kacvinsky <tjk@ams.org> */ +- if (p && (isdigit(p[7]) || p[7] == '+' || p[7] == '-')) { ++ if (p && (isdigit((unsigned char)p[7]) || p[7] == '+' || p[7] == '-')) { + lenIV = atoi(p + 7); + } + } +@@ -120,7 +120,7 @@ + if (q) { + r = cs_start; + ++q; +- while (!isspace(*q) && *q != '{') ++ while (!isspace((unsigned char)*q) && *q != '{') + *r++ = *q++; + *r = '\0'; + } +diff -ur t1utils-1.38.orig/t1lib.c t1utils-1.38/t1lib.c +--- t1utils-1.38.orig/t1lib.c 2013-09-29 15:23:22.000000000 +0200 ++++ t1utils-1.38/t1lib.c 2014-06-19 13:08:40.000000000 +0200 +@@ -59,7 +59,7 @@ + char *start = s; + char *t = s; + for (; *s; s++) { +- if (isspace(*s)) ++ if (isspace((unsigned char)*s)) + continue; + if (c1) { + *t++ = (hexval(c1) << 4) + hexval(*s); +@@ -136,10 +136,10 @@ + + /* now that we have the line, handle it */ + if (blocktyp == PFA_ASCII) { +- if (strncmp(line, "currentfile eexec", 17) == 0 && isspace(line[17])) { ++ if (strncmp(line, "currentfile eexec", 17) == 0 && isspace((unsigned char)line[17])) { + char saved_p; + /* assert(line == buffer); */ +- for (line += 18; isspace(*line); line++) ++ for (line += 18; isspace((unsigned char)*line); line++) + /* nada */; + saved_p = *line; + *line = 0; +@@ -158,12 +158,12 @@ + if (blocktyp == PFA_EEXEC_TEST) { + /* 8.Feb.2004: fix bug if first character in a binary eexec block + is 0, reported by Werner Lemberg */ +- for (; line < last && isspace(*line); line++) ++ for (; line < last && isspace((unsigned char)*line); line++) + /* nada */; + if (line == last) + continue; +- else if (last >= line + 4 && isxdigit(line[0]) && isxdigit(line[1]) +- && isxdigit(line[2]) && isxdigit(line[3])) ++ else if (last >= line + 4 && isxdigit((unsigned char)line[0]) && isxdigit((unsigned char)line[1]) ++ && isxdigit((unsigned char)line[2]) && isxdigit((unsigned char)line[3])) + blocktyp = PFA_HEX; + else + blocktyp = PFA_BINARY; +diff -ur t1utils-1.38.orig/t1mac.c t1utils-1.38/t1mac.c +--- t1utils-1.38.orig/t1mac.c 2013-09-29 15:23:22.000000000 +0200 ++++ t1utils-1.38/t1mac.c 2014-06-19 13:08:40.000000000 +0200 +@@ -370,10 +370,10 @@ + s[len-1] = '\r'; + t1mac_output_data((byte *)s, len); + if (strncmp(s, "/FontName", 9) == 0) { +- for (s += 9; isspace(*s); s++) ; ++ for (s += 9; isspace((unsigned char)*s); s++) ; + if (*s == '/') { + const char *t = ++s; +- while (*t && !isspace(*t)) t++; ++ while (*t && !isspace((unsigned char)*t)) t++; + free(font_name); + font_name = (char *)malloc(t - s + 1); + memcpy(font_name, s, t - s); +@@ -992,11 +992,11 @@ + int part = 0, len = 0; + char *x, *s; + for (x = s = font_name; *s; s++) +- if (isupper(*s) || isdigit(*s)) { ++ if (isupper((unsigned char)*s) || isdigit((unsigned char)*s)) { + *x++ = *s; + part++; + len = 1; +- } else if (islower(*s)) { ++ } else if (islower((unsigned char)*s)) { + if (len < (part <= 1 ? 5 : 3)) + *x++ = *s; + len++; diff --git a/Build/source/utils/t1utils/t1utils-1.38/t1asm.c b/Build/source/utils/t1utils/t1utils-1.38/t1asm.c index b29ecb486f5..27f45f27b23 100644 --- a/Build/source/utils/t1utils/t1utils-1.38/t1asm.c +++ b/Build/source/utils/t1utils/t1utils-1.38/t1asm.c @@ -273,7 +273,7 @@ static void eexec_start(char *string) static int check_line_charstring(void) { char *p = line; - while (isspace(*p)) + while (isspace((unsigned char)*p)) p++; return (*p == '/' || (p[0] == 'd' && p[1] == 'u' && p[2] == 'p')); } @@ -359,8 +359,8 @@ static int CDECL command_compare(const void *key, const void *item) static int is_integer(char *string) { - if (isdigit(string[0]) || string[0] == '-' || string[0] == '+') { - while (*++string && isdigit(*string)) + if (isdigit((unsigned char)string[0]) || string[0] == '-' || string[0] == '+') { + while (*++string && isdigit((unsigned char)*string)) ; /* deliberately empty */ if (!*string) return 1; @@ -738,11 +738,11 @@ particular purpose.\n"); t1utils_getline(); if (!ever_active) { - if (strncmp(line, "currentfile eexec", 17) == 0 && isspace(line[17])) { + if (strncmp(line, "currentfile eexec", 17) == 0 && isspace((unsigned char)line[17])) { /* Allow arbitrary whitespace after "currentfile eexec". Thanks to Tom Kacvinsky <tjk@ams.org> for reporting this. Note: strlen("currentfile eexec") == 17. */ - for (p = line + 18; isspace(*p); p++) + for (p = line + 18; isspace((unsigned char)*p); p++) ; eexec_start(p); continue; @@ -756,7 +756,7 @@ particular purpose.\n"); if (q) { r = cs_start; ++q; - while (!isspace(*q) && *q != '{') + while (!isspace((unsigned char)*q) && *q != '{') *r++ = *q++; *r = '\0'; } @@ -765,9 +765,9 @@ particular purpose.\n"); } if (!active) { - if ((p = strstr(line, "/Subrs")) && isdigit(p[7])) + if ((p = strstr(line, "/Subrs")) && isdigit((unsigned char)p[7])) ever_active = active = 1; - else if ((p = strstr(line, "/CharStrings")) && isdigit(p[13])) + else if ((p = strstr(line, "/CharStrings")) && isdigit((unsigned char)p[13])) ever_active = active = 1; } if ((p = strstr(line, "currentfile closefile"))) { @@ -776,7 +776,7 @@ particular purpose.\n"); /* 1/3/2002 -- happy new year! -- Luc Devroye reports a failure with some printers when `currentfile closefile' is followed by space */ p += sizeof("currentfile closefile") - 1; - for (q = p; isspace(*q) && *q != '\n'; q++) + for (q = p; isspace((unsigned char)*q) && *q != '\n'; q++) /* nada */; if (q == p && !*q) error("warning: `currentfile closefile' line too long"); diff --git a/Build/source/utils/t1utils/t1utils-1.38/t1disasm.c b/Build/source/utils/t1utils/t1utils-1.38/t1disasm.c index dcec63f5f80..40161a7fae5 100644 --- a/Build/source/utils/t1utils/t1utils-1.38/t1disasm.c +++ b/Build/source/utils/t1utils/t1utils-1.38/t1disasm.c @@ -100,7 +100,7 @@ set_lenIV(char *line) char *p = strstr(line, "/lenIV "); /* Allow lenIV to be negative. Thanks to Tom Kacvinsky <tjk@ams.org> */ - if (p && (isdigit(p[7]) || p[7] == '+' || p[7] == '-')) { + if (p && (isdigit((unsigned char)p[7]) || p[7] == '+' || p[7] == '-')) { lenIV = atoi(p + 7); } } @@ -120,7 +120,7 @@ set_cs_start(char *line) if (q) { r = cs_start; ++q; - while (!isspace(*q) && *q != '{') + while (!isspace((unsigned char)*q) && *q != '{') *r++ = *q++; *r = '\0'; } diff --git a/Build/source/utils/t1utils/t1utils-1.38/t1lib.c b/Build/source/utils/t1utils/t1utils-1.38/t1lib.c index 6b49a196561..f3e5fa7e245 100644 --- a/Build/source/utils/t1utils/t1utils-1.38/t1lib.c +++ b/Build/source/utils/t1utils/t1utils-1.38/t1lib.c @@ -59,7 +59,7 @@ translate_hex_string(char *s, char *saved_orphan) char *start = s; char *t = s; for (; *s; s++) { - if (isspace(*s)) + if (isspace((unsigned char)*s)) continue; if (c1) { *t++ = (hexval(c1) << 4) + hexval(*s); @@ -136,10 +136,10 @@ process_pfa(FILE *ifp, const char *ifp_filename, struct font_reader *fr) /* now that we have the line, handle it */ if (blocktyp == PFA_ASCII) { - if (strncmp(line, "currentfile eexec", 17) == 0 && isspace(line[17])) { + if (strncmp(line, "currentfile eexec", 17) == 0 && isspace((unsigned char)line[17])) { char saved_p; /* assert(line == buffer); */ - for (line += 18; isspace(*line); line++) + for (line += 18; isspace((unsigned char)*line); line++) /* nada */; saved_p = *line; *line = 0; @@ -158,12 +158,12 @@ process_pfa(FILE *ifp, const char *ifp_filename, struct font_reader *fr) if (blocktyp == PFA_EEXEC_TEST) { /* 8.Feb.2004: fix bug if first character in a binary eexec block is 0, reported by Werner Lemberg */ - for (; line < last && isspace(*line); line++) + for (; line < last && isspace((unsigned char)*line); line++) /* nada */; if (line == last) continue; - else if (last >= line + 4 && isxdigit(line[0]) && isxdigit(line[1]) - && isxdigit(line[2]) && isxdigit(line[3])) + else if (last >= line + 4 && isxdigit((unsigned char)line[0]) && isxdigit((unsigned char)line[1]) + && isxdigit((unsigned char)line[2]) && isxdigit((unsigned char)line[3])) blocktyp = PFA_HEX; else blocktyp = PFA_BINARY; diff --git a/Build/source/utils/t1utils/t1utils-1.38/t1mac.c b/Build/source/utils/t1utils/t1utils-1.38/t1mac.c index 007e5802a2f..9411a89a70d 100644 --- a/Build/source/utils/t1utils/t1utils-1.38/t1mac.c +++ b/Build/source/utils/t1utils/t1utils-1.38/t1mac.c @@ -370,10 +370,10 @@ t1mac_output_ascii(char *s, int len) s[len-1] = '\r'; t1mac_output_data((byte *)s, len); if (strncmp(s, "/FontName", 9) == 0) { - for (s += 9; isspace(*s); s++) ; + for (s += 9; isspace((unsigned char)*s); s++) ; if (*s == '/') { const char *t = ++s; - while (*t && !isspace(*t)) t++; + while (*t && !isspace((unsigned char)*t)) t++; free(font_name); font_name = (char *)malloc(t - s + 1); memcpy(font_name, s, t - s); @@ -992,11 +992,11 @@ particular purpose.\n"); int part = 0, len = 0; char *x, *s; for (x = s = font_name; *s; s++) - if (isupper(*s) || isdigit(*s)) { + if (isupper((unsigned char)*s) || isdigit((unsigned char)*s)) { *x++ = *s; part++; len = 1; - } else if (islower(*s)) { + } else if (islower((unsigned char)*s)) { if (len < (part <= 1 ? 5 : 3)) *x++ = *s; len++; |