[Bug libstdc++/101965] New: check in charconv is vacuously true
barry.revzin at gmail dot com
gcc-bugzilla@gcc.gnu.org
Wed Aug 18 18:19:52 GMT 2021
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101965
Bug ID: 101965
Summary: check in charconv is vacuously true
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: barry.revzin at gmail dot com
Target Milestone: ---
When investigating PVS-Studio in our codebase, it flagged this check in
charconv:
322 template<typename _Tp>
323 __detail::__integer_to_chars_result_type<_Tp>
324 __to_chars_i(char* __first, char* __last, _Tp __value, int __base =
10)
325 {
326 __glibcxx_assert(2 <= __base && __base <= 36);
327
328 using _Up = __detail::__unsigned_least_t<_Tp>;
329 _Up __unsigned_val = __value;
330
331 if (__first == __last) [[__unlikely__]]
332 return { __last, errc::value_too_large };
333
334 if (__value == 0)
335 {
336 *__first = '0';
337 return { __first + 1, errc{} };
338 }
339
340 if _GLIBCXX17_CONSTEXPR (std::is_signed<_Tp>::value)
341 if (__value < 0)
342 {
343 if (__builtin_expect(__first != __last, 1))
344 *__first++ = '-';
345 __unsigned_val = _Up(~__value) + _Up(1);
346 }
347
348 switch (__base)
349 {
350 case 16:
On line 343, __first is never equal to __last. If it were, we would've returned
on line 332.
More information about the Gcc-bugs
mailing list