[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] mbrlen, mbrtowc: fix bug with empty input

From: Paul Eggert
Subject: Re: [PATCH] mbrlen, mbrtowc: fix bug with empty input
Date: Fri, 16 May 2014 17:23:58 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0

Pádraig Brady wrote:
To me, mbrtowc returning 0 for empty input is not surprising.
Also POSIX says for mbr{len,towc} that they shall return 0
"If the next n or fewer bytes complete the character that corresponds to the 
null wide character

At least 1 byte is needed to represent a null wide character. Therefore, zero bytes cannot possibly complete a null wide character, which means mbrtowc on empty input cannot return 0 if it wants to conform to POSIX and/or C11.

A similar argument shows why mbrtowc can't return (size_t) -1 on empty input: it's because you need at least 1 byte to represent an encoding error.

Thanks for the typo fix, by the way.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]