Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!ginosko!uunet!mcsun!sunic!tut!tukki!tarvaine From: tarvaine@tukki.jyu.fi (Tapani Tarvainen) Newsgroups: gnu.utils.bug Subject: Re: SED bug Summary: another bug: signed chars Message-ID: <1313@tukki.jyu.fi> Date: 17 Sep 89 23:20:33 GMT References: <8909121817.AA11159@gem> <1309@tukki.jyu.fi> <1311@tukki.jyu.fi> <1312@tukki.jyu.fi> Reply-To: tarvaine@tukki.jyu.fi (Tapani Tarvainen) Distribution: gnu Organization: University of Jyvaskyla, Finland Lines: 58 I just found yet abother bug in the y-command of Gnu SED 1.02: characters >127 won't get translated properly. This depends on the compiler, though; the offending line is cur_cmd->x.translate[*string++]=ch; and the problem is that string is declared as char *, and if chars are signed and *string is negative, the ANSI promotion rules keep it negative when converted to an int. The easiest fix (or first that I could think of) is to declare string as unsigned char*; lint &c will complain about mixing pointers to signed and unsigned chars, but who cares (if you do, throw in a few casts or declare all chars as unsigned). At least it seems to work. Anyway, here's the diff (this includes the earlier patch): *** sed.old Sun Sep 17 22:28:15 1989 --- sed.c Mon Sep 18 01:58:58 1989 *************** *** 412,418 **** int ch; int slash; VOID *b; ! char *string; int num; FILE *compile_filename(); --- 412,418 ---- int ch; int slash; VOID *b; ! unsigned char *string; int num; FILE *compile_filename(); *************** *** 704,710 **** cur_cmd->x.translate[*string++]=ch; } flush_buffer(b); ! if(inchar()!=slash || inchar()!='\n') bad_prog(LINE_JUNK); break; --- 704,710 ---- cur_cmd->x.translate[*string++]=ch; } flush_buffer(b); ! if(inchar()!=slash || ((ch=inchar())!='\n' && ch!=EOF)) bad_prog(LINE_JUNK); break; -- Tapani Tarvainen (tarvaine@tukki.jyu.fi, tarvainen@finjyu.bitnet)