https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103233

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2021-11-14
     Ever confirmed|0                           |1

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Alejandro Colomar from comment #0)
> There are two problems here:
> 
> One is a dereference of a NULL pointer in the standard C++ library code
> (at least that's what -fanalyzer reports).

The analyzer doesn't support C++ properly yet, and is completely wrong here.
See below.



> Another is that I'm seeing the error while compiling user code (my library):
> <https://github.com/alejandro-colomar/libalx>

What error? Please provide the code to reproduce the problem, not just a URL,
see https://gcc.gnu.org/bugs


>     |/usr/include/c++/11/bits/stl_vector.h:346:25:
>     |  346 |         return __n != 0 ? _Tr::allocate(_M_impl, __n) :
> pointer();
>     |      |               
> ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>     |      |                         |
>     |      |                         (7) following 'false' branch...

This cannot happen. The length is this->size() + 1 and we already checked for
overflow, so it is guaranteed to be a positive integer.


>            |......
>            |  127 |         return static_cast<_Tp*>(::operator new(__n *
> sizeof(_Tp)));
>            |      |                                 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>            |      |                                                |
>            |      |                                                (12)
> ...to here
>            |      |                                                (13) this
> call could return NULL


This is nonsense, operator new(size_t) cannot return null.

Reply via email to