From 744f11fe8b6f2c480b23699adeb452a5de39add0 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Thu, 27 Aug 2020 11:07:04 +0000 Subject: Avoid using alloca and use a fixed buffer instead. --- .../src/vespa/document/datatype/structureddatatype.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'document') 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(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 -- cgit v1.2.3