XPath: alloc_string no longer returns NULL

NULL return value will be reserved for the OOM error indicator.
This commit is contained in:
Arseny Kapoulkine 2017-01-29 20:00:44 -08:00
parent d3b9e4e1e8
commit f11c4d6847

View File

@ -10953,20 +10953,19 @@ PUGI__NS_BEGIN
const char_t* alloc_string(const xpath_lexer_string& value) const char_t* alloc_string(const xpath_lexer_string& value)
{ {
if (value.begin) if (!value.begin)
{ return PUGIXML_TEXT("");
size_t length = static_cast<size_t>(value.end - value.begin);
char_t* c = static_cast<char_t*>(_alloc->allocate_nothrow((length + 1) * sizeof(char_t))); size_t length = static_cast<size_t>(value.end - value.begin);
if (!c) throw_error_oom();
assert(c); // workaround for clang static analysis
memcpy(c, value.begin, length * sizeof(char_t)); char_t* c = static_cast<char_t*>(_alloc->allocate_nothrow((length + 1) * sizeof(char_t)));
c[length] = 0; if (!c) throw_error_oom();
assert(c); // workaround for clang static analysis
return c; memcpy(c, value.begin, length * sizeof(char_t));
} c[length] = 0;
else return 0;
return c;
} }
xpath_ast_node* parse_function_helper(ast_type_t type0, ast_type_t type1, size_t argc, xpath_ast_node* args[2]) xpath_ast_node* parse_function_helper(ast_type_t type0, ast_type_t type1, size_t argc, xpath_ast_node* args[2])