folly: ubsan: fix "reference binding to null pointer of type 'char'"
authorLucian Grijincu <lucian@fb.com>
Tue, 10 May 2016 00:50:08 +0000 (17:50 -0700)
committerFacebook Github Bot 4 <facebook-github-bot-4-bot@fb.com>
Tue, 10 May 2016 01:05:26 +0000 (18:05 -0700)
Summary:
third-party-buck/build/libgcc/include/c++/4.9.x/bits/stl_vector.h:866:9: runtime error: reference binding to null pointer of type 'char'

```
Breakpoint 2, 0x0000000000494894 in __ubsan_handle_type_mismatch_abort ()
(gdb) bt
```

Reviewed By: meyering, yfeldblum

Differential Revision: D3279234

fbshipit-source-id: 63a761587e5b3f79ece09fc99b9a593da0e44b75

folly/test/FBStringTest.cpp

index 34858238839fd65eac72dfffdc81be893d7addf9..3d39b7733e7c54dee5a8961697e2c2eedccff81d 100644 (file)
@@ -574,10 +574,10 @@ template <class String> void clause11_21_4_6_6(String & test) {
 template <class String> void clause11_21_4_6_7(String & test) {
   std::vector<typename String::value_type>
     vec(random(0, maxString));
-  test.copy(
-    &vec[0],
-    vec.size(),
-    random(0, test.size()));
+  if (vec.empty()) {
+    return;
+  }
+  test.copy(vec.data(), vec.size(), random(0, test.size()));
 }
 
 template <class String> void clause11_21_4_6_8(String & test) {