diff --git a/sed/compile.c b/sed/compile.c index 891f4fc..088bcc6 100644 --- a/sed/compile.c +++ b/sed/compile.c @@ -41,9 +41,9 @@ struct prog_info { to the current character in the string, and 'prog.end' points to the end of the string. This allows us to compile script strings that contain nulls. */ - const unsigned char *base; - const unsigned char *cur; - const unsigned char *end; + char const *base; + char const *cur; + char const *end; }; /* Information used to give out useful and informative error messages. */ @@ -149,7 +149,7 @@ bad_prog_notranslate (const char *why, ...) static int inchar (void) { - int ch = prog.cur < prog.end ? *prog.cur++ : EOF; + int ch = prog.cur < prog.end ? (unsigned char) {*prog.cur++} : EOF; if (ch == '\n') ++cur_input.line; return ch; @@ -163,7 +163,7 @@ savchar (int ch) return; if (ch == '\n' && cur_input.line > 0) --cur_input.line; - if (prog.cur <= prog.base || *--prog.cur != ch) + if (prog.cur <= prog.base || (unsigned char) {*--prog.cur} != ch) panic ("Called savchar with unexpected pushback (%x)", (unsigned int) ch); } @@ -1231,17 +1231,19 @@ compile_program (struct vector *vector) } else { - unsigned char *translate = obstack_alloc (&obs, UCHAR_MAX + 1); - unsigned char *ustring = (unsigned char *)src_buf; + char *translate = obstack_alloc (&obs, UCHAR_MAX + 1); + char *ustring = src_buf; if (len != dest_len) bad_prog ("'y' command strings have different lengths"); - for (len = 0; len < UCHAR_MAX + 1; len++) - translate[len] = len; + /* The default translation of a character is itself. + Don't trap on debugging platforms if char is signed. */ + for (idx_t i = 0; i < UCHAR_MAX + 1; i++) + translate[i] = i <= CHAR_MAX ? i : i - (UCHAR_MAX + 1); while (dest_len--) - translate[*ustring++] = (unsigned char)*dest_buf++; + translate[(unsigned char) {*ustring++}] = *dest_buf++; cur_cmd->x.translate.sb = translate; } @@ -1398,7 +1400,7 @@ compile_string (struct vector *cur_program, char *str, idx_t len) static int string_expr_count; struct vector *ret; - prog.base = (unsigned char *)str; + prog.base = str; prog.cur = prog.base; prog.end = prog.cur + len; @@ -1430,7 +1432,7 @@ compile_file (struct vector *cur_program, const char *cmdfile) if (!str) panic (_("couldn't read file %s: %s"), quotef (cmdfile), strerror (errno)); - prog.base = (unsigned char *) str; + prog.base = str; prog.cur = prog.base; prog.end = prog.cur + len; diff --git a/sed/debug.c b/sed/debug.c index 1738a04..2810d1c 100644 --- a/sed/debug.c +++ b/sed/debug.c @@ -273,11 +273,11 @@ debug_print_translation (const struct sed_cmd *sc) /* unibyte translation */ putchar ('/'); for (idx_t i = 0; i < UCHAR_MAX + 1; ++i) - if (sc->x.translate.sb[i] != i) + if (i != (unsigned char) {sc->x.translate.sb[i]}) putchar (i); putchar ('/'); for (idx_t i = 0; i < UCHAR_MAX + 1; ++i) - if (sc->x.translate.sb[i] != i) + if (i != (unsigned char) {sc->x.translate.sb[i]}) putchar (sc->x.translate.sb[i]); putchar ('/'); } diff --git a/sed/execute.c b/sed/execute.c index e46ebdb..068d7d2 100644 --- a/sed/execute.c +++ b/sed/execute.c @@ -1606,10 +1606,9 @@ execute_program (struct vector *vec, struct input *input) cur_cmd->x.translate.mb.pair); else { - unsigned char *p, *e; - p = (unsigned char *)line.active; - for (e=p+line.length; px.translate.sb[*p]; + char *e = line.active + line.length; + for (char *p = line.active; p < e; p++) + *p = cur_cmd->x.translate.sb[(unsigned char) {*p}]; } if (debug) debug_print_line (&line); diff --git a/sed/sed.h b/sed/sed.h index 9904e36..7e3a326 100644 --- a/sed/sed.h +++ b/sed/sed.h @@ -185,8 +185,9 @@ struct sed_cmd { /* This is used for the y command. */ union { - /* An array of UCHAR_MAX + 1 bytes. sb[I] is the translation of I. */ - unsigned char *sb; + /* An array of UCHAR_MAX + 1 bytes. sb[(unsigned char) {I}] + is the translation of I. */ + char *sb; /* The number of translation pairs, and an array of pairs. For 0 <= I < 2 * npairs, pair[I + 1] is the translation of pair[I]