[libcxx-commits] [libcxx] b95379d - [libc++][NFC] Add assertions before calling memmove

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Mon Nov 28 08:10:22 PST 2022


Author: Louis Dionne
Date: 2022-11-28T11:10:04-05:00
New Revision: b95379d20e0493d4ca073fbaa2f878344568425b

URL: https://github.com/llvm/llvm-project/commit/b95379d20e0493d4ca073fbaa2f878344568425b
DIFF: https://github.com/llvm/llvm-project/commit/b95379d20e0493d4ca073fbaa2f878344568425b.diff

LOG: [libc++][NFC] Add assertions before calling memmove

Since we're checking preconditions for calling memmove, we might
as well do that properly.

Differential Revision: https://reviews.llvm.org/D138798

Added: 
    

Modified: 
    libcxx/include/fstream
    libcxx/include/locale

Removed: 
    


################################################################################
diff  --git a/libcxx/include/fstream b/libcxx/include/fstream
index 65b22a4db70a..62c6f53e9fe7 100644
--- a/libcxx/include/fstream
+++ b/libcxx/include/fstream
@@ -754,7 +754,8 @@ basic_filebuf<_CharT, _Traits>::underflow()
         else
         {
             if (__extbufend_ != __extbufnext_) {
-                _LIBCPP_ASSERT(__extbufnext_ != nullptr, "underflow moving from NULL" );
+                _LIBCPP_ASSERT(__extbufnext_ != nullptr, "underflow moving from nullptr");
+                _LIBCPP_ASSERT(__extbuf_ != nullptr, "underflow moving into nullptr");
                 _VSTD::memmove(__extbuf_, __extbufnext_, __extbufend_ - __extbufnext_);
             }
             __extbufnext_ = __extbuf_ + (__extbufend_ - __extbufnext_);

diff  --git a/libcxx/include/locale b/libcxx/include/locale
index c00b1dfc9375..311e866a8910 100644
--- a/libcxx/include/locale
+++ b/libcxx/include/locale
@@ -4014,7 +4014,8 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
         else
         {
              if (__extbufend_ != __extbufnext_) {
-                _LIBCPP_ASSERT(__extbufnext_ != NULL, "underflow moving from NULL" );
+                _LIBCPP_ASSERT(__extbufnext_ != nullptr, "underflow moving from nullptr");
+                _LIBCPP_ASSERT(__extbuf_ != nullptr, "underflow moving into nullptr");
                 _VSTD::memmove(__extbuf_, __extbufnext_, __extbufend_ - __extbufnext_);
              }
             __extbufnext_ = __extbuf_ + (__extbufend_ - __extbufnext_);


        


More information about the libcxx-commits mailing list