Don't memcpy from an empty ArrayRef; the base pointer could be null, and
authorRichard Smith <richard@metafoo.co.uk>
Tue, 15 Dec 2020 22:29:22 +0000 (14:29 -0800)
committerRichard Smith <richard@metafoo.co.uk>
Tue, 15 Dec 2020 22:37:52 +0000 (14:37 -0800)
the C rules say memcpy can't accept a null pointer.

This should fix a test failure with the ubsan buildbots.

clang/lib/AST/APValue.cpp

index 5b340e6..c18f885 100644 (file)
@@ -952,8 +952,10 @@ void APValue::setLValue(LValueBase B, const CharUnits &O,
                         bool IsNullPtr) {
   MutableArrayRef<APValue::LValuePathEntry> InternalPath =
       setLValueUninit(B, O, Path.size(), IsOnePastTheEnd, IsNullPtr);
-  memcpy(InternalPath.data(), Path.data(),
-         Path.size() * sizeof(LValuePathEntry));
+  if (Path.size()) {
+    memcpy(InternalPath.data(), Path.data(),
+           Path.size() * sizeof(LValuePathEntry));
+  }
 }
 
 void APValue::setUnion(const FieldDecl *Field, const APValue &Value) {