summaryrefslogtreecommitdiffstats
path: root/flang/runtime/temporary-stack.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'flang/runtime/temporary-stack.cpp')
-rw-r--r--flang/runtime/temporary-stack.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/flang/runtime/temporary-stack.cpp b/flang/runtime/temporary-stack.cpp
index b4d7c6064457..667b10e04dbd 100644
--- a/flang/runtime/temporary-stack.cpp
+++ b/flang/runtime/temporary-stack.cpp
@@ -93,8 +93,13 @@ void DescriptorStorage<COPY_VALUES>::resize(size_type newCapacity) {
}
Descriptor **newData =
static_cast<Descriptor **>(AllocateMemoryOrCrash(terminator_, bytes));
- memcpy(newData, data_, capacity_ * sizeof(Descriptor *));
- FreeMemory(data_);
+ // "memcpy" in glibc has a "nonnull" attribute on the source pointer.
+ // Avoid passing a null pointer, since it would result in an undefined
+ // behavior.
+ if (data_ != nullptr) {
+ memcpy(newData, data_, capacity_ * sizeof(Descriptor *));
+ FreeMemory(data_);
+ }
data_ = newData;
capacity_ = newCapacity;
}