Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 24 Jun 2008 09:30:43 -0700
From:      Tim Kientzle <kientzle@freebsd.org>
To:        Gabor Kovesdan <gabor@freebsd.org>
Cc:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   Re: PERFORCE change 144026 for review
Message-ID:  <48612133.5060309@freebsd.org>
In-Reply-To: <200806241616.m5OGGCEr096087@repoman.freebsd.org>
References:  <200806241616.m5OGGCEr096087@repoman.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Gabor,

Unrelated, but I noticed that you have an unchecked
call to mbstowcs() here.  mbstowcs() can fail; I
recently went through a couple months of pain reworking
chunks of libarchive to correctly handle such failures.
I ended up falling back on mbtowc() to convert one
character at a time.

You'll see conversion failures, for example, if
someone is using a multi-character locale such
as UTF-8 and runs grep over a file encoded in ISO-8859-1.
(People often use "grep -R <symbol> /usr/src" for example,
and a lot of C source files have people's names
in ISO-8859-1.)

Throwing out the entire file (or even entire line)
because of a single character that can't be
interpreted is probably not going to be feasible.

Tim

Gabor Kovesdan wrote:
> http://perforce.freebsd.org/chv.cgi?CH=144026
> 
> Change 144026 by gabor@gabor_server on 2008/06/24 16:15:17
> 
> 	- Cleanup: use grep_malloc instead of malloc
> 
> Affected files ...
> 
> .. //depot/projects/soc2008/gabor_textproc/grep/binary.c#10 edit
> .. //depot/projects/soc2008/gabor_textproc/grep/grep.c#42 edit
> .. //depot/projects/soc2008/gabor_textproc/grep/util.c#37 edit
> 
> Differences ...
> 
> ==== //depot/projects/soc2008/gabor_textproc/grep/binary.c#10 (text+ko) ====
> 
> @@ -77,8 +77,7 @@
>  	if ((s = mbstowcs(NULL, f->base, 0)) == -1)
>  		return (0);
>  
> -	if ((wbuf = malloc((s + 1) * sizeof(wchar_t))) == NULL)
> -		err(2, NULL);
> +	wbuf = grep_malloc((s + 1) * sizeof(wchar_t));
>  
>  	mbstowcs(wbuf, f->base, s);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?48612133.5060309>