XPath: If exceptions are enabled, std::bad_alloc is thrown for all out of memory situation (instead of xpath_exception)
git-svn-id: http://pugixml.googlecode.com/svn/trunk@759 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
parent
0afd63bc32
commit
a6c756b8bc
@ -8196,11 +8196,20 @@ namespace pugi
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void throw_error_oom()
|
||||||
|
{
|
||||||
|
#ifdef PUGIXML_NO_EXCEPTIONS
|
||||||
|
throw_error("Out of memory");
|
||||||
|
#else
|
||||||
|
throw std::bad_alloc();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void* alloc_node()
|
void* alloc_node()
|
||||||
{
|
{
|
||||||
void* result = _alloc->allocate_nothrow(sizeof(xpath_ast_node));
|
void* result = _alloc->allocate_nothrow(sizeof(xpath_ast_node));
|
||||||
|
|
||||||
if (!result) throw_error("Out of memory");
|
if (!result) throw_error_oom();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -8212,7 +8221,7 @@ namespace pugi
|
|||||||
size_t length = static_cast<size_t>(value.end - value.begin);
|
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)));
|
char_t* c = static_cast<char_t*>(_alloc->allocate_nothrow((length + 1) * sizeof(char_t)));
|
||||||
if (!c) throw_error("Out of memory");
|
if (!c) throw_error_oom();
|
||||||
|
|
||||||
memcpy(c, value.begin, length * sizeof(char_t));
|
memcpy(c, value.begin, length * sizeof(char_t));
|
||||||
c[length] = 0;
|
c[length] = 0;
|
||||||
@ -8489,7 +8498,7 @@ namespace pugi
|
|||||||
double value = 0;
|
double value = 0;
|
||||||
|
|
||||||
if (!convert_string_to_number(_lexer.contents().begin, _lexer.contents().end, &value))
|
if (!convert_string_to_number(_lexer.contents().begin, _lexer.contents().end, &value))
|
||||||
throw_error("Out of memory");
|
throw_error_oom();
|
||||||
|
|
||||||
xpath_ast_node* n = new (alloc_node()) xpath_ast_node(ast_number_constant, xpath_type_number, value);
|
xpath_ast_node* n = new (alloc_node()) xpath_ast_node(ast_number_constant, xpath_type_number, value);
|
||||||
_lexer.next();
|
_lexer.next();
|
||||||
@ -9224,10 +9233,10 @@ namespace pugi
|
|||||||
|
|
||||||
if (!alloc)
|
if (!alloc)
|
||||||
{
|
{
|
||||||
|
#ifdef PUGIXML_NO_EXCEPTIONS
|
||||||
_result.error = "Out of memory";
|
_result.error = "Out of memory";
|
||||||
|
#else
|
||||||
#ifndef PUGIXML_NO_EXCEPTIONS
|
throw std::bad_alloc();
|
||||||
throw xpath_exception(_result);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user