From 388c40d9c66983d9aa48dc9a69d6dcca441d3587 Mon Sep 17 00:00:00 2001 From: David Neto Date: Wed, 16 Sep 2015 16:42:56 -0400 Subject: [PATCH] Generalize spvOperandTableNameLookup to take string length. This is preparation for parsing mask expressions. --- source/operand.cpp | 8 ++++---- source/operand.h | 2 ++ source/text.cpp | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/source/operand.cpp b/source/operand.cpp index 819f591..f58b8c3 100644 --- a/source/operand.cpp +++ b/source/operand.cpp @@ -1456,12 +1456,12 @@ spv_result_t spvOperandTableGet(spv_operand_table *pOperandTable) { spv_result_t spvOperandTableNameLookup(const spv_operand_table table, const spv_operand_type_t type, - const char *name, - spv_operand_desc *pEntry) { + const char* name, + const size_t nameLength, + spv_operand_desc* pEntry) { if (!table) return SPV_ERROR_INVALID_TABLE; if (!name || !pEntry) return SPV_ERROR_INVALID_POINTER; - const uint64_t nameLength = strlen(name); for (uint64_t typeIndex = 0; typeIndex < table->count; ++typeIndex) { if (type == table->types[typeIndex].type) { for (uint64_t operandIndex = 0; @@ -1469,7 +1469,7 @@ spv_result_t spvOperandTableNameLookup(const spv_operand_table table, if (nameLength == strlen(table->types[typeIndex].entries[operandIndex].name) && !strncmp(table->types[typeIndex].entries[operandIndex].name, name, - strlen(name))) { + nameLength)) { *pEntry = &table->types[typeIndex].entries[operandIndex]; return SPV_SUCCESS; } diff --git a/source/operand.h b/source/operand.h index b1bd8b9..f73c770 100644 --- a/source/operand.h +++ b/source/operand.h @@ -45,12 +45,14 @@ using spv_operand_pattern_t = std::deque; /// @param[in] table to lookup /// @param[in] type the operand group's type /// @param[in] name of the operand to find +/// @param[in] nameLength number of bytes of name to compare /// @param[out] pEntry returned operand table entry /// /// @return result code spv_result_t spvOperandTableNameLookup(const spv_operand_table table, const spv_operand_type_t type, const char *name, + const size_t nameLength, spv_operand_desc *pEntry); /// @brief Find the operand with value in the table diff --git a/source/text.cpp b/source/text.cpp index 9d04f1c..5776b1b 100644 --- a/source/text.cpp +++ b/source/text.cpp @@ -539,7 +539,8 @@ spv_result_t spvTextEncodeOperand( // NOTE: All non literal operands are handled here using the operand // table. spv_operand_desc entry; - if (spvOperandTableNameLookup(operandTable, type, textValue, &entry)) { + if (spvOperandTableNameLookup(operandTable, type, textValue, + strlen(textValue), &entry)) { DIAGNOSTIC << "Invalid " << spvOperandTypeStr(type) << " '" << textValue << "'."; return SPV_ERROR_INVALID_TEXT; -- 2.7.4