mbstowcs(3) may not return -1
Hello, While reading the manpage of mbstowcs I noticed an error in the RETURN VALUES : The mbstowcs() function returns the number of wide characters converted, not counting any terminating null wide character, or -1 if an invalid multibyte character was encountered. Since size_t is unsigned, it can't returns -1. Cheers, -- David Demelier ___ freebsd-current@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-current To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org
Re: mbstowcs(3) may not return -1
On 21 June 2012 16:38, David Demelier demelier.da...@gmail.com wrote: Hello, While reading the manpage of mbstowcs I noticed an error in the RETURN VALUES : The mbstowcs() function returns the number of wide characters converted, not counting any terminating null wide character, or -1 if an invalid multibyte character was encountered. Since size_t is unsigned, it can't returns -1. It returns (size_t)(-1). I don't know how is it correct, but this conforms to C spec. -- wbr, pluknet ___ freebsd-current@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-current To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org
Re: mbstowcs(3) may not return -1
On 21/06/2012 14:55, Sergey Kandaurov wrote: On 21 June 2012 16:38, David Demelierdemelier.da...@gmail.com wrote: Hello, While reading the manpage of mbstowcs I noticed an error in the RETURN VALUES : The mbstowcs() function returns the number of wide characters converted, not counting any terminating null wide character, or -1 if an invalid multibyte character was encountered. Since size_t is unsigned, it can't returns -1. It returns (size_t)(-1). I don't know how is it correct, but this conforms to C spec. Mm, if I understand well, since it is cast to size_t, I think the return value will be SIZE_MAX - 1 then, right? -- David Demelier ___ freebsd-current@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-current To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org
Re: mbstowcs(3) may not return -1
On 21 June 2012 19:42, David Demelier demelier.da...@gmail.com wrote: On 21/06/2012 14:55, Sergey Kandaurov wrote: On 21 June 2012 16:38, David Demelierdemelier.da...@gmail.com wrote: Hello, While reading the manpage of mbstowcs I noticed an error in the RETURN VALUES : The mbstowcs() function returns the number of wide characters converted, not counting any terminating null wide character, or -1 if an invalid multibyte character was encountered. Since size_t is unsigned, it can't returns -1. It returns (size_t)(-1). I don't know how is it correct, but this conforms to C spec. Mm, if I understand well, since it is cast to size_t, I think the return value will be SIZE_MAX - 1 then, right? No, just SIZE_MAX. There is also remarkable SIZE_T_MAX. It came with 4.4BSD Lite sources under !defined(_POSIX_SOURCE). Later it was converted to be under __POSIX_VISIBLE = 200112 || __XSI_VISIBLE. I hasn't found anything relative in any POSIX editions. I think this was a typo/misunderstanding. Other BSD has put this macro under its corresponding if XBSD_VISIBLE. Therefore I think SIZE_T_MAX should be avoided. -- wbr, pluknet ___ freebsd-current@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-current To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org
Re: mbstowcs(3) may not return -1
On 21/06/2012 14:55, Sergey Kandaurov wrote: On 21 June 2012 16:38, David Demelierdemelier.da...@gmail.com wrote: Hello, While reading the manpage of mbstowcs I noticed an error in the RETURN VALUES : The mbstowcs() function returns the number of wide characters converted, not counting any terminating null wide character, or -1 if an invalid multibyte character was encountered. Since size_t is unsigned, it can't returns -1. It returns (size_t)(-1). I don't know how is it correct, but this conforms to C spec. Yes that is very strange, iconv(3) do it too. -- David Demelier ___ freebsd-current@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-current To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org
Re: mbstowcs(3) may not return -1
In article 4fe340ff.80...@gmail.com, demelier.da...@gmail.com writes: On 21/06/2012 14:55, Sergey Kandaurov wrote: It returns (size_t)(-1). I don't know how is it correct, but this conforms to C spec. Mm, if I understand well, since it is cast to size_t, I think the return value will be SIZE_MAX - 1 then, right? No. C does not make any such equivalence. (size_t)-1 is the one correct spelling of this value (modulo redundant additional parentheses), and that's how the standard writes it. -GAWollman ___ freebsd-current@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-current To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org