Edmund GRIMLEY EVANS wrote on 2001-05-26 13:19 UTC:
> I admit I haven't checked the latest glibc from CVS, and I haven't
> investigated any databases of bug reports, so I apologise if this is
> already well known.
> 
> With glibc-2.2.3, mbrtowc(&wc, "", 0, &ps) seems to return 0 instead
> of (size_t)(-2). I think this is a bug.

It is a bug in your software. You should never call mbrtowc with 0 as
the number n of bytes that mbrtowc is allowed to examine at most. Such a
call seems useless, and the standard does not define the behaviour of
mbrtowc in that case.

One could argue - and I probably would agree - that (size_t)(-2) might
be an aesthetically more pleasing return value in that situation, but
that is not really a requirement of ISO/IEC 9899:1999(E), �7.24.6.3.2 on
page 388.

Perhaps someone should write a tutorial on common pitfalls with the
restartable multi-byte functions. The other common one is that people
try to initialize an mb_state variable with a call to
mbrtowc(NULL, "", 1, &ps). Instead, the correct (though at first glance
ugly) initialization is memset(&ps, 0, sizeof(ps)).

Markus

-- 
Markus G. Kuhn, Computer Laboratory, University of Cambridge, UK
Email: mkuhn at acm.org,  WWW: <http://www.cl.cam.ac.uk/~mgk25/>

-
Linux-UTF8:   i18n of Linux on all levels
Archive:      http://mail.nl.linux.org/linux-utf8/

Reply via email to