[PATCH] Ensure std::getline always 0-terminates string.
Reimar Döffinger via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 20 16:33:56 PST 2017
On 20 November 2017 22:19:04 CET, Volodymyr Sapsai <vsapsai at apple.com> wrote:
>On Nov 20, 2017, at 11:32, Reimar Döffinger <Reimar.Doeffinger at gmx.de>
>wrote:
>>
>> On Mon, Nov 20, 2017 at 11:02:13AM -0800, Volodymyr Sapsai wrote:
>>>> catch (...)
>>>> {
>>>> + if (__n > 0)
>>>> + *__s = char_type();
>>>> this->__set_badbit_and_consider_rethrow();
>>>> }
>>>
>>> or maybe something else?
>>
>> That one (note that the __set_badbit_and_consider_rethrow
>> will never re-throw in this case).
>
>But by #define _LIBCPP_NO_EXCEPTIONS 1 you exclude this block at
>preprocessing step
>
>> #ifndef _LIBCPP_NO_EXCEPTIONS
>> }
>> catch (...)
>> {
>> + if (__n > 0)
>> + *__s = char_type();
>> this->__set_badbit_and_consider_rethrow();
>> }
>> #endif // _LIBCPP_NO_EXCEPTIONS
>
>And looks like getline_pointer_size_exception.pass.cpp doesn’t execute
>this code.
Yes, that was complete nonsense, I somehow always read #ifdef where there was an #ifndef...
Not sure then if that 0 termination should be there (and be tested) or better to not have it in the exception case at all (I haven't checked if the exception is always re-thrown or not, which might be relevant).
I am a bit unclear about that whole code there that catches exceptions and sets the bad bit and how it maps to the specification.
More information about the cfe-commits
mailing list