summaryrefslogtreecommitdiffstats
path: root/fnet
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@yahooinc.com>2022-03-25 15:04:33 +0000
committerTor Brede Vekterli <vekterli@yahooinc.com>2022-03-25 15:04:33 +0000
commit58a4eae6c716a3f43231172721d4adccd8f60bd0 (patch)
tree81bd715748265ccdcad783b70bacb35ab3a3b7aa /fnet
parent11f510e66e439d008ecab87deecaeb63b70d5cab (diff)
Avoid undefined behavior for zero-sized memcpy with nullptr argument
It's technically undefined behavior if either src or dest to `memcpy` is `nullptr`, even if the size to copy is zero.
Diffstat (limited to 'fnet')
-rw-r--r--fnet/src/vespa/fnet/frt/values.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/fnet/src/vespa/fnet/frt/values.cpp b/fnet/src/vespa/fnet/frt/values.cpp
index d550e37af5c..dedefd64323 100644
--- a/fnet/src/vespa/fnet/frt/values.cpp
+++ b/fnet/src/vespa/fnet/frt/values.cpp
@@ -129,10 +129,16 @@ FRT_Values::EnsureFree(uint32_t need)
cnt = 16;
char *types = (char *) _stash.alloc(cnt + 1);
- memcpy(types, _typeString, _numValues);
+ if (_numValues > 0) {
+ assert(_typeString != nullptr);
+ memcpy(types, _typeString, _numValues);
+ }
memset(types + _numValues, FRT_VALUE_NONE, cnt + 1 - _numValues);
FRT_Value *values = (FRT_Value *) (void *)_stash.alloc(cnt * sizeof(FRT_Value));
- memcpy(values, _values, _numValues * sizeof(FRT_Value));
+ if (_numValues > 0) {
+ assert(_values != nullptr);
+ memcpy(values, _values, _numValues * sizeof(FRT_Value));
+ }
_maxValues = cnt;
_typeString = types;
_values = values;