]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: More fixes for null pointers used with std::char_traits
authorJonathan Wakely <jwakely@redhat.com>
Tue, 28 Mar 2023 10:12:58 +0000 (11:12 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 28 Mar 2023 20:12:18 +0000 (21:12 +0100)
commitcb6f663f9d79d7134ae6ecaff9a25342c40aeb5d
tree7a187ca513f93f6dc064e062b94e0a2c57430558
parentbf78b43873b0b7e8f9a430df38749b8b61f9c9b8
libstdc++: More fixes for null pointers used with std::char_traits

The std::char_traits member functions require that [p,p+n) is a valid
range, which is true for p==nullptr iff n==0. But we must not call
memcpy, memset etc, in that case, as they require non-null pointers even
when n==0.

This std::char_traits<char> and std::char_traits<wchar_t> explicit
specializations are already correct, but the primary template has some
bugs.

libstdc++-v3/ChangeLog:

* include/bits/char_traits.h (char_traits::copy): Return without
using memcpy if n==0.
(char_traits::assign): Likewise for memset.
libstdc++-v3/include/bits/char_traits.h