From owner-freebsd-current Tue Mar 20 1:15:56 2001 Delivered-To: freebsd-current@freebsd.org Received: from fw.wintelcom.net (ns1.wintelcom.net [209.1.153.20]) by hub.freebsd.org (Postfix) with ESMTP id 2235F37B719 for ; Tue, 20 Mar 2001 01:15:53 -0800 (PST) (envelope-from bright@fw.wintelcom.net) Received: (from bright@localhost) by fw.wintelcom.net (8.10.0/8.10.0) id f2K9Ck126982; Tue, 20 Mar 2001 01:12:46 -0800 (PST) Date: Tue, 20 Mar 2001 01:12:46 -0800 From: Alfred Perlstein To: thinker Cc: freebsd-current@FreeBSD.ORG Subject: Re: patch /bin/ls again, for mb supporting. Message-ID: <20010320011246.O29888@fw.wintelcom.net> References: <20010320164901.A14424@hell.branda.to> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20010320164901.A14424@hell.branda.to>; from thinker@branda.to on Tue, Mar 20, 2001 at 04:49:01PM +0000 X-all-your-base: are belong to us. Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG * thinker [010320 00:48] wrote: > Hi, > There are some disscuss about patch file of /bin/ls. You guys > give me some suggestion, and I make a new patch file for /bin/ls to > meet people's wish. Following is patch for /bin/ls, plz review again. > I had change from rune to mb* & wc* ways. > ------------- begin --------- > --- util.c.orig Sun Mar 18 16:35:12 2001 > +++ util.c Tue Mar 20 16:11:37 2001 > @@ -60,15 +60,37 @@ > prn_printable(s) > const char *s; > { > - unsigned char c; > - int n; > + const char *p; > + char *r, *ri; > + int len, dc; > + size_t sz; > + wchar_t c; C has allowed for identifiers larger than 6 characters for quite some time, any chance on you making use of this feature? Or at least adding a comment here and there? > + p = s; > + dc = len = strlen(s); > + ri = r = (char *)malloc(len + 1); Where is the check for malloc failing? > + while (dc) { > + sz = mbtowc(&c, p, dc); > + if (sz < 0) { > + p++; > + dc--; > + *ri++ = '?'; > + } else { > + dc -= sz; > + if (isprint(c)) { > + while(sz--) > + *ri++ = *p++; > + } else { > + p += sz; > + while(sz--) > + *ri++ = '?'; Why didn't you use strlcpy/memcpy as suggested? > + } > + } > + } > + *ri = 0; *ri = '\0'; > + printf("%s", r); > + free(r); > + return len; return (len); > } -- -Alfred Perlstein - [bright@wintelcom.net|alfred@freebsd.org] To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message