summaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-08-27 11:07:04 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2020-08-27 11:07:04 +0000
commit744f11fe8b6f2c480b23699adeb452a5de39add0 (patch)
tree84b67909a964306e902d7d86241e4575ddf39163 /document
parent0a5c13aa1ab2117cfb5d70e13313426eb7f1a695 (diff)
Avoid using alloca and use a fixed buffer instead.
Diffstat (limited to 'document')
-rw-r--r--document/src/vespa/document/datatype/structureddatatype.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/document/src/vespa/document/datatype/structureddatatype.cpp b/document/src/vespa/document/datatype/structureddatatype.cpp
index 1b98d912819..59584ff3b01 100644
--- a/document/src/vespa/document/datatype/structureddatatype.cpp
+++ b/document/src/vespa/document/datatype/structureddatatype.cpp
@@ -48,11 +48,18 @@ int32_t StructuredDataType::createId(vespalib::stringref name)
// ASCII characters. Probably screwed up otherwise, but generated ids
// should only be used in testing anyways. In production this will be
// set from the document manager config.
- char *bufOnStack = static_cast<char *>(alloca(name.size() + 2));
- memcpy(bufOnStack, name.data(), name.size());
- bufOnStack[name.size()] = '.';
- bufOnStack[name.size() + 1] = '0';
- return crappyJavaStringHash(vespalib::stringref(bufOnStack, name.size() + 2));
+ constexpr size_t BUFFER_SIZE = 1024;
+ if ((name.size() + 2) < BUFFER_SIZE) {
+ char buf[BUFFER_SIZE];
+ memcpy(buf, name.data(), name.size());
+ buf[name.size()] = '.';
+ buf[name.size() + 1] = '0';
+ return crappyJavaStringHash(vespalib::stringref(buf, name.size() + 2));
+ } else {
+ vespalib::asciistream ost;
+ ost << name << ".0"; // Hardcode version 0 (version is not supported).
+ return crappyJavaStringHash(ost.str());
+ }
}
void