From a1eb95233236d49be4ea22a599f8057942b3b41d Mon Sep 17 00:00:00 2001 From: Andrew Hutchings Date: Wed, 26 Oct 2016 17:07:15 +0100 Subject: [PATCH] MCOL-352 Fix VARCHAR with no NUL It is possible to have a VARCHAR column that isn't NUL terminated, an example of this is a union of two CHAR columns. So the length should always act as a terminator when there is no NUL. --- utils/rowgroup/rowgroup.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/utils/rowgroup/rowgroup.h b/utils/rowgroup/rowgroup.h index fe5952db4..ef218b225 100644 --- a/utils/rowgroup/rowgroup.h +++ b/utils/rowgroup/rowgroup.h @@ -581,12 +581,9 @@ inline std::string Row::getStringField(uint32_t colIndex) const if (inStringTable(colIndex)) return strings->getString(*((uint32_t *) &data[offsets[colIndex]]), *((uint32_t *) &data[offsets[colIndex] + 4])); - if (types[colIndex] == execplan::CalpontSystemCatalog::VARCHAR) - return std::string((char *) &data[offsets[colIndex]]); - else // types where we can't rely on NULL termination... - return std::string((char *) &data[offsets[colIndex]], - strnlen((char *) &data[offsets[colIndex]], getColumnWidth(colIndex))); -// return std::string((char *) &data[offsets[colIndex]], getColumnWidth(colIndex)); + // Not all CHAR/VARCHAR are NUL terminated so use length + return std::string((char *) &data[offsets[colIndex]], + strnlen((char *) &data[offsets[colIndex]], getColumnWidth(colIndex))); } inline std::string Row::getVarBinaryStringField(uint32_t colIndex) const