[libcxx-commits] [PATCH] D115598: [libc++][NFC] Remove goto from std::string

Arthur O'Dwyer via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Dec 13 08:55:02 PST 2021


Quuxplusone accepted this revision.
Quuxplusone added inline comments.


================
Comment at: libcxx/include/string:3020
         traits_type::move(__p + __pos, __s, __n2);
-__finish:
-// __sz += __n2 - __n1; in this and the below function below can cause unsigned
-// integer overflow, but this is a safe operation, so we disable the check.
-        __sz += __n2 - __n1;
-        __set_size(__sz);
-        __invalidate_iterators_past(__sz);
-        traits_type::assign(__p[__sz], value_type());
+        return __null_terminate_at(__p, __sz + __n2 - __n1);
     }
----------------
ldionne wrote:
> 
Or "match line 3023" should also work, I think: `__sz - __n1 + __n2`
The important thing is not to let `__sz + __n2` be a subexpression, because it might wrap around, triggering that UBSan checker.


================
Comment at: libcxx/include/string:3001
                     traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
-                    goto __finish;
+                    return __null_terminate_at(__p, __n2 - __n1);
                 }
----------------
Quuxplusone wrote:
> Here and below: `__sz + __n2 - __n1`, right? I hope this caused some test failures! :)
Same issue as line 3020: either `__sz + (__n2 - __n1)` or `__sz - __n1 + __n2`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115598/new/

https://reviews.llvm.org/D115598



More information about the libcxx-commits mailing list