fix -Wzero-as-null-pointer-constant warnings

This commit is contained in:
Daniel Ottiger 2021-02-21 15:55:52 +01:00
parent 95683943bb
commit e1cb6ccc3c
13 changed files with 288 additions and 276 deletions

View File

@ -17,6 +17,10 @@ RELEASE=$(filter-out scripts/archive.py docs/%.adoc,$(shell git ls-files docs sc
CXXFLAGS=-g -Wall -Wextra -Werror -pedantic -Wundef -Wshadow -Wcast-align -Wcast-qual -Wold-style-cast -Wdouble-promotion CXXFLAGS=-g -Wall -Wextra -Werror -pedantic -Wundef -Wshadow -Wcast-align -Wcast-qual -Wold-style-cast -Wdouble-promotion
LDFLAGS= LDFLAGS=
ifneq ($(cxxstd),c++98)
CXXFLAGS+=-Wzero-as-null-pointer-constant
endif
ifeq ($(config),release) ifeq ($(config),release)
CXXFLAGS+=-O3 -DNDEBUG CXXFLAGS+=-O3 -DNDEBUG
endif endif

File diff suppressed because it is too large Load Diff

View File

@ -15,6 +15,15 @@
# endif # endif
#endif #endif
// If C++ is 2011 or higher, use 'nullptr'
#ifndef PUGIXML_NULL
# if __cplusplus >= 201103
# define PUGIXML_NULL nullptr
# else
# define PUGIXML_NULL 0
# endif
#endif
// Low-level allocation functions // Low-level allocation functions
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
# ifdef __MWERKS__ # ifdef __MWERKS__
@ -93,7 +102,6 @@ namespace
void* allocate_page_aligned(size_t size) void* allocate_page_aligned(size_t size)
{ {
void* result = malloc(size + page_size); void* result = malloc(size + page_size);
return reinterpret_cast<void*>(align_to_page(reinterpret_cast<size_t>(result))); return reinterpret_cast<void*>(align_to_page(reinterpret_cast<size_t>(result)));
} }
@ -102,7 +110,7 @@ namespace
size_t aligned_size = align_to_page(size); size_t aligned_size = align_to_page(size);
void* ptr = allocate_page_aligned(aligned_size + page_size); void* ptr = allocate_page_aligned(aligned_size + page_size);
if (!ptr) return 0; if (!ptr) return PUGIXML_NULL;
char* end = static_cast<char*>(ptr) + aligned_size; char* end = static_cast<char*>(ptr) + aligned_size;
@ -147,7 +155,7 @@ const size_t memory_alignment = sizeof(double) > sizeof(void*) ? sizeof(double)
void* memory_allocate(size_t size) void* memory_allocate(size_t size)
{ {
void* result = allocate(size + memory_alignment); void* result = allocate(size + memory_alignment);
if (!result) return 0; if (!result) return PUGIXML_NULL;
memcpy(result, &size, sizeof(size_t)); memcpy(result, &size, sizeof(size_t));

View File

@ -18,7 +18,7 @@
# include <windows.h> # include <windows.h>
#endif #endif
test_runner* test_runner::_tests = 0; test_runner* test_runner::_tests = PUGIXML_NULL;
size_t test_runner::_memory_fail_threshold = 0; size_t test_runner::_memory_fail_threshold = 0;
bool test_runner::_memory_fail_triggered = false; bool test_runner::_memory_fail_triggered = false;
jmp_buf test_runner::_failure_buffer; jmp_buf test_runner::_failure_buffer;
@ -36,12 +36,12 @@ static void* custom_allocate(size_t size)
g_memory_fail_triggered = true; g_memory_fail_triggered = true;
test_runner::_memory_fail_triggered = true; test_runner::_memory_fail_triggered = true;
return 0; return PUGIXML_NULL;
} }
else else
{ {
void* ptr = memory_allocate(size); void* ptr = memory_allocate(size);
if (!ptr) return 0; if (!ptr) return PUGIXML_NULL;
g_memory_total_size += memory_size(ptr); g_memory_total_size += memory_size(ptr);
g_memory_total_count++; g_memory_total_count++;
@ -183,7 +183,7 @@ int main(int, char** argv)
unsigned int total = 0; unsigned int total = 0;
unsigned int passed = 0; unsigned int passed = 0;
test_runner* test = 0; // gcc3 "variable might be used uninitialized in this function" bug workaround test_runner* test = PUGIXML_NULL; // gcc3 "variable might be used uninitialized in this function" bug workaround
for (test = test_runner::_tests; test; test = test->_next) for (test = test_runner::_tests; test; test = test->_next)
{ {

View File

@ -164,7 +164,7 @@ xpath_node_set_tester::xpath_node_set_tester(const pugi::xpath_node_set& set, co
if (result.empty()) if (result.empty())
{ {
document_order = 0; document_order = PUGIXML_NULL;
document_size = 0; document_size = 0;
} }
else else

View File

@ -138,12 +138,12 @@ struct dummy_fixture {};
#define CHECK_XPATH_NODESET_VAR(node, query, variables) xpath_node_set_tester(pugi::xpath_query(query, variables).evaluate_node_set(node), CHECK_JOIN2(STRINGIZE(query) " does not evaluate to expected set in context " STRINGIZE(node), __FILE__, __LINE__)) #define CHECK_XPATH_NODESET_VAR(node, query, variables) xpath_node_set_tester(pugi::xpath_query(query, variables).evaluate_node_set(node), CHECK_JOIN2(STRINGIZE(query) " does not evaluate to expected set in context " STRINGIZE(node), __FILE__, __LINE__))
#define CHECK_XPATH_FAIL_VAR(query, variables) CHECK_TEXT(test_xpath_fail_compile(query, variables), STRINGIZE(query) " should not compile") #define CHECK_XPATH_FAIL_VAR(query, variables) CHECK_TEXT(test_xpath_fail_compile(query, variables), STRINGIZE(query) " should not compile")
#define CHECK_XPATH_STRING(node, query, expected) CHECK_XPATH_STRING_VAR(node, query, 0, expected) #define CHECK_XPATH_STRING(node, query, expected) CHECK_XPATH_STRING_VAR(node, query, PUGIXML_NULL, expected)
#define CHECK_XPATH_BOOLEAN(node, query, expected) CHECK_XPATH_BOOLEAN_VAR(node, query, 0, expected) #define CHECK_XPATH_BOOLEAN(node, query, expected) CHECK_XPATH_BOOLEAN_VAR(node, query, PUGIXML_NULL, expected)
#define CHECK_XPATH_NUMBER(node, query, expected) CHECK_XPATH_NUMBER_VAR(node, query, 0, expected) #define CHECK_XPATH_NUMBER(node, query, expected) CHECK_XPATH_NUMBER_VAR(node, query, PUGIXML_NULL, expected)
#define CHECK_XPATH_NUMBER_NAN(node, query) CHECK_XPATH_NUMBER_NAN_VAR(node, query, 0) #define CHECK_XPATH_NUMBER_NAN(node, query) CHECK_XPATH_NUMBER_NAN_VAR(node, query, PUGIXML_NULL)
#define CHECK_XPATH_NODESET(node, query) CHECK_XPATH_NODESET_VAR(node, query, 0) #define CHECK_XPATH_NODESET(node, query) CHECK_XPATH_NODESET_VAR(node, query, PUGIXML_NULL)
#define CHECK_XPATH_FAIL(query) CHECK_XPATH_FAIL_VAR(query, 0) #define CHECK_XPATH_FAIL(query) CHECK_XPATH_FAIL_VAR(query, PUGIXML_NULL)
#endif #endif
#ifdef PUGIXML_NO_EXCEPTIONS #ifdef PUGIXML_NO_EXCEPTIONS

View File

@ -889,7 +889,7 @@ TEST(document_parse_result_description)
{ {
result.status = static_cast<xml_parse_status>(i); result.status = static_cast<xml_parse_status>(i);
CHECK(result.description() != 0); CHECK(result.description() != PUGIXML_NULL);
CHECK(result.description()[0] != 0); CHECK(result.description()[0] != 0);
} }
} }
@ -1098,11 +1098,11 @@ TEST(document_contents_preserve)
{ {
file_data_t files[] = file_data_t files[] =
{ {
{"tests/data/utftest_utf16_be_clean.xml", encoding_utf16_be, 0, 0}, {"tests/data/utftest_utf16_be_clean.xml", encoding_utf16_be, PUGIXML_NULL, 0},
{"tests/data/utftest_utf16_le_clean.xml", encoding_utf16_le, 0, 0}, {"tests/data/utftest_utf16_le_clean.xml", encoding_utf16_le, PUGIXML_NULL, 0},
{"tests/data/utftest_utf32_be_clean.xml", encoding_utf32_be, 0, 0}, {"tests/data/utftest_utf32_be_clean.xml", encoding_utf32_be, PUGIXML_NULL, 0},
{"tests/data/utftest_utf32_le_clean.xml", encoding_utf32_le, 0, 0}, {"tests/data/utftest_utf32_le_clean.xml", encoding_utf32_le, PUGIXML_NULL, 0},
{"tests/data/utftest_utf8_clean.xml", encoding_utf8, 0, 0} {"tests/data/utftest_utf8_clean.xml", encoding_utf8, PUGIXML_NULL, 0}
}; };
// load files in memory // load files in memory
@ -1136,8 +1136,8 @@ TEST(document_contents_preserve_latin1)
{ {
file_data_t files[] = file_data_t files[] =
{ {
{"tests/data/latintest_utf8.xml", encoding_utf8, 0, 0}, {"tests/data/latintest_utf8.xml", encoding_utf8, PUGIXML_NULL, 0},
{"tests/data/latintest_latin1.xml", encoding_latin1, 0, 0} {"tests/data/latintest_latin1.xml", encoding_latin1, PUGIXML_NULL, 0}
}; };
// load files in memory // load files in memory
@ -1239,15 +1239,15 @@ TEST(document_load_buffer_empty)
xml_document doc; xml_document doc;
CHECK(doc.load_buffer(buffer, 0, parse_default, encoding).status == status_no_document_element && !doc.first_child()); CHECK(doc.load_buffer(buffer, 0, parse_default, encoding).status == status_no_document_element && !doc.first_child());
CHECK(doc.load_buffer(0, 0, parse_default, encoding).status == status_no_document_element && !doc.first_child()); CHECK(doc.load_buffer(PUGIXML_NULL, 0, parse_default, encoding).status == status_no_document_element && !doc.first_child());
CHECK(doc.load_buffer_inplace(buffer, 0, parse_default, encoding).status == status_no_document_element && !doc.first_child()); CHECK(doc.load_buffer_inplace(buffer, 0, parse_default, encoding).status == status_no_document_element && !doc.first_child());
CHECK(doc.load_buffer_inplace(0, 0, parse_default, encoding).status == status_no_document_element && !doc.first_child()); CHECK(doc.load_buffer_inplace(PUGIXML_NULL, 0, parse_default, encoding).status == status_no_document_element && !doc.first_child());
void* own_buffer = get_memory_allocation_function()(1); void* own_buffer = get_memory_allocation_function()(1);
CHECK(doc.load_buffer_inplace_own(own_buffer, 0, parse_default, encoding).status == status_no_document_element && !doc.first_child()); CHECK(doc.load_buffer_inplace_own(own_buffer, 0, parse_default, encoding).status == status_no_document_element && !doc.first_child());
CHECK(doc.load_buffer_inplace_own(0, 0, parse_default, encoding).status == status_no_document_element && !doc.first_child()); CHECK(doc.load_buffer_inplace_own(PUGIXML_NULL, 0, parse_default, encoding).status == status_no_document_element && !doc.first_child());
} }
} }
@ -1275,15 +1275,15 @@ TEST(document_load_buffer_empty_fragment)
xml_document doc; xml_document doc;
CHECK(doc.load_buffer(buffer, 0, parse_fragment, encoding) && !doc.first_child()); CHECK(doc.load_buffer(buffer, 0, parse_fragment, encoding) && !doc.first_child());
CHECK(doc.load_buffer(0, 0, parse_fragment, encoding) && !doc.first_child()); CHECK(doc.load_buffer(PUGIXML_NULL, 0, parse_fragment, encoding) && !doc.first_child());
CHECK(doc.load_buffer_inplace(buffer, 0, parse_fragment, encoding) && !doc.first_child()); CHECK(doc.load_buffer_inplace(buffer, 0, parse_fragment, encoding) && !doc.first_child());
CHECK(doc.load_buffer_inplace(0, 0, parse_fragment, encoding) && !doc.first_child()); CHECK(doc.load_buffer_inplace(PUGIXML_NULL, 0, parse_fragment, encoding) && !doc.first_child());
void* own_buffer = get_memory_allocation_function()(1); void* own_buffer = get_memory_allocation_function()(1);
CHECK(doc.load_buffer_inplace_own(own_buffer, 0, parse_fragment, encoding) && !doc.first_child()); CHECK(doc.load_buffer_inplace_own(own_buffer, 0, parse_fragment, encoding) && !doc.first_child());
CHECK(doc.load_buffer_inplace_own(0, 0, parse_fragment, encoding) && !doc.first_child()); CHECK(doc.load_buffer_inplace_own(PUGIXML_NULL, 0, parse_fragment, encoding) && !doc.first_child());
} }
} }
@ -1291,11 +1291,11 @@ TEST(document_load_buffer_null)
{ {
xml_document doc; xml_document doc;
CHECK(doc.load_buffer(0, 12).status == status_io_error && !doc.first_child()); CHECK(doc.load_buffer(PUGIXML_NULL, 12).status == status_io_error && !doc.first_child());
CHECK(doc.load_buffer(0, 12, parse_fragment).status == status_io_error && !doc.first_child()); CHECK(doc.load_buffer(PUGIXML_NULL, 12, parse_fragment).status == status_io_error && !doc.first_child());
CHECK(doc.load_buffer_inplace(0, 12).status == status_io_error && !doc.first_child()); CHECK(doc.load_buffer_inplace(PUGIXML_NULL, 12).status == status_io_error && !doc.first_child());
CHECK(doc.load_buffer_inplace_own(0, 12).status == status_io_error && !doc.first_child()); CHECK(doc.load_buffer_inplace_own(PUGIXML_NULL, 12).status == status_io_error && !doc.first_child());
} }
TEST(document_progressive_truncation) TEST(document_progressive_truncation)
@ -1350,7 +1350,7 @@ TEST(document_load_buffer_short)
CHECK(doc.load_buffer(data + 2, 2).status == status_no_document_element); CHECK(doc.load_buffer(data + 2, 2).status == status_no_document_element);
CHECK(doc.load_buffer(data + 3, 1).status == status_no_document_element); CHECK(doc.load_buffer(data + 3, 1).status == status_no_document_element);
CHECK(doc.load_buffer(data + 4, 0).status == status_no_document_element); CHECK(doc.load_buffer(data + 4, 0).status == status_no_document_element);
CHECK(doc.load_buffer(0, 0).status == status_no_document_element); CHECK(doc.load_buffer(PUGIXML_NULL, 0).status == status_no_document_element);
delete[] data; delete[] data;
} }
@ -1367,7 +1367,7 @@ TEST(document_load_buffer_short_fragment)
CHECK(doc.load_buffer(data + 2, 2, parse_fragment) && test_string_equal(doc.text().get(), STR("cd"))); CHECK(doc.load_buffer(data + 2, 2, parse_fragment) && test_string_equal(doc.text().get(), STR("cd")));
CHECK(doc.load_buffer(data + 3, 1, parse_fragment) && test_string_equal(doc.text().get(), STR("d"))); CHECK(doc.load_buffer(data + 3, 1, parse_fragment) && test_string_equal(doc.text().get(), STR("d")));
CHECK(doc.load_buffer(data + 4, 0, parse_fragment) && !doc.first_child()); CHECK(doc.load_buffer(data + 4, 0, parse_fragment) && !doc.first_child());
CHECK(doc.load_buffer(0, 0, parse_fragment) && !doc.first_child()); CHECK(doc.load_buffer(PUGIXML_NULL, 0, parse_fragment) && !doc.first_child());
delete[] data; delete[] data;
} }
@ -1384,7 +1384,7 @@ TEST(document_load_buffer_inplace_short)
CHECK(doc.load_buffer_inplace(data + 2, 2).status == status_no_document_element); CHECK(doc.load_buffer_inplace(data + 2, 2).status == status_no_document_element);
CHECK(doc.load_buffer_inplace(data + 3, 1).status == status_no_document_element); CHECK(doc.load_buffer_inplace(data + 3, 1).status == status_no_document_element);
CHECK(doc.load_buffer_inplace(data + 4, 0).status == status_no_document_element); CHECK(doc.load_buffer_inplace(data + 4, 0).status == status_no_document_element);
CHECK(doc.load_buffer_inplace(0, 0).status == status_no_document_element); CHECK(doc.load_buffer_inplace(PUGIXML_NULL, 0).status == status_no_document_element);
delete[] data; delete[] data;
} }
@ -1597,12 +1597,12 @@ TEST(document_convert_out_of_memory)
{ {
file_data_t files[] = file_data_t files[] =
{ {
{"tests/data/utftest_utf16_be_clean.xml", encoding_utf16_be, 0, 0}, {"tests/data/utftest_utf16_be_clean.xml", encoding_utf16_be, PUGIXML_NULL, 0},
{"tests/data/utftest_utf16_le_clean.xml", encoding_utf16_le, 0, 0}, {"tests/data/utftest_utf16_le_clean.xml", encoding_utf16_le, PUGIXML_NULL, 0},
{"tests/data/utftest_utf32_be_clean.xml", encoding_utf32_be, 0, 0}, {"tests/data/utftest_utf32_be_clean.xml", encoding_utf32_be, PUGIXML_NULL, 0},
{"tests/data/utftest_utf32_le_clean.xml", encoding_utf32_le, 0, 0}, {"tests/data/utftest_utf32_le_clean.xml", encoding_utf32_le, PUGIXML_NULL, 0},
{"tests/data/utftest_utf8_clean.xml", encoding_utf8, 0, 0}, {"tests/data/utftest_utf8_clean.xml", encoding_utf8, PUGIXML_NULL, 0},
{"tests/data/latintest_latin1.xml", encoding_latin1, 0, 0} {"tests/data/latintest_latin1.xml", encoding_latin1, PUGIXML_NULL, 0}
}; };
// load files in memory // load files in memory

View File

@ -1345,8 +1345,8 @@ TEST_XML(dom_node_append_buffer_empty, "<node />")
CHECK(node.append_buffer("", 0).status == status_no_document_element); CHECK(node.append_buffer("", 0).status == status_no_document_element);
CHECK(node.append_buffer("", 0, parse_fragment).status == status_ok); CHECK(node.append_buffer("", 0, parse_fragment).status == status_ok);
CHECK(node.append_buffer(0, 0).status == status_no_document_element); CHECK(node.append_buffer(PUGIXML_NULL, 0).status == status_no_document_element);
CHECK(node.append_buffer(0, 0, parse_fragment).status == status_ok); CHECK(node.append_buffer(PUGIXML_NULL, 0, parse_fragment).status == status_ok);
CHECK_NODE(doc, STR("<node/>")); CHECK_NODE(doc, STR("<node/>"));
} }

View File

@ -981,14 +981,14 @@ TEST_XML(dom_internal_object, "<node attr='value'>value</node>")
xml_attribute attr = node.first_attribute(); xml_attribute attr = node.first_attribute();
xml_node value = node.first_child(); xml_node value = node.first_child();
CHECK(xml_node().internal_object() == 0); CHECK(xml_node().internal_object() == PUGIXML_NULL);
CHECK(xml_attribute().internal_object() == 0); CHECK(xml_attribute().internal_object() == PUGIXML_NULL);
CHECK(node.internal_object() != 0); CHECK(node.internal_object() != PUGIXML_NULL);
CHECK(value.internal_object() != 0); CHECK(value.internal_object() != PUGIXML_NULL);
CHECK(node.internal_object() != value.internal_object()); CHECK(node.internal_object() != value.internal_object());
CHECK(attr.internal_object() != 0); CHECK(attr.internal_object() != PUGIXML_NULL);
xml_node node_copy = node; xml_node node_copy = node;
CHECK(node_copy.internal_object() == node.internal_object()); CHECK(node_copy.internal_object() == node.internal_object());
@ -1100,24 +1100,24 @@ TEST_XML(dom_unspecified_bool_coverage, "<node attr='value'>text</node>")
xml_node node = doc.first_child(); xml_node node = doc.first_child();
CHECK(node); CHECK(node);
static_cast<void (*)(xml_node***)>(node)(0); static_cast<void (*)(xml_node***)>(node)(PUGIXML_NULL);
CHECK(node.first_attribute()); CHECK(node.first_attribute());
static_cast<void (*)(xml_attribute***)>(node.first_attribute())(0); static_cast<void (*)(xml_attribute***)>(node.first_attribute())(PUGIXML_NULL);
CHECK(node.text()); CHECK(node.text());
static_cast<void (*)(xml_text***)>(node.text())(0); static_cast<void (*)(xml_text***)>(node.text())(PUGIXML_NULL);
#ifndef PUGIXML_NO_XPATH #ifndef PUGIXML_NO_XPATH
xpath_query q(STR("/node")); xpath_query q(STR("/node"));
CHECK(q); CHECK(q);
static_cast<void (*)(xpath_query***)>(q)(0); static_cast<void (*)(xpath_query***)>(q)(PUGIXML_NULL);
xpath_node qn = q.evaluate_node(doc); xpath_node qn = q.evaluate_node(doc);
CHECK(qn); CHECK(qn);
static_cast<void (*)(xpath_node***)>(qn)(0); static_cast<void (*)(xpath_node***)>(qn)(PUGIXML_NULL);
#endif #endif
} }

View File

@ -416,7 +416,7 @@ TEST_XML(xpath_out_of_memory_evaluate, "<n/>")
CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(doc).empty())); CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(doc).empty()));
#endif #endif
CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(0, 0, doc) == 1)); CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(PUGIXML_NULL, 0, doc) == 1));
CHECK_ALLOC_FAIL(CHECK(q.evaluate_node(doc) == xpath_node())); CHECK_ALLOC_FAIL(CHECK(q.evaluate_node(doc) == xpath_node()));
CHECK_ALLOC_FAIL(CHECK(q.evaluate_node_set(doc).empty())); CHECK_ALLOC_FAIL(CHECK(q.evaluate_node_set(doc).empty()));
} }
@ -432,7 +432,7 @@ TEST(xpath_out_of_memory_evaluate_concat)
xpath_query q(query.c_str()); xpath_query q(query.c_str());
CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(0, 0, xml_node()) == 1)); CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(PUGIXML_NULL, 0, xml_node()) == 1));
} }
TEST(xpath_out_of_memory_evaluate_concat_list) TEST(xpath_out_of_memory_evaluate_concat_list)
@ -448,7 +448,7 @@ TEST(xpath_out_of_memory_evaluate_concat_list)
test_runner::_memory_fail_threshold = 1; test_runner::_memory_fail_threshold = 1;
CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(0, 0, xml_node()) == 1)); CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(PUGIXML_NULL, 0, xml_node()) == 1));
} }
TEST(xpath_out_of_memory_evaluate_substring) TEST(xpath_out_of_memory_evaluate_substring)
@ -462,7 +462,7 @@ TEST(xpath_out_of_memory_evaluate_substring)
xpath_query q(query.c_str()); xpath_query q(query.c_str());
CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(0, 0, xml_node()) == 1)); CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(PUGIXML_NULL, 0, xml_node()) == 1));
} }
TEST_XML(xpath_out_of_memory_evaluate_union, "<node />") TEST_XML(xpath_out_of_memory_evaluate_union, "<node />")
@ -516,7 +516,7 @@ TEST_XML(xpath_out_of_memory_evaluate_normalize_space_0, "<node> a b c d e f g h
xpath_query q(STR("concat(normalize-space(), normalize-space(), normalize-space(), normalize-space(), normalize-space(), normalize-space(), normalize-space(), normalize-space())")); xpath_query q(STR("concat(normalize-space(), normalize-space(), normalize-space(), normalize-space(), normalize-space(), normalize-space(), normalize-space(), normalize-space())"));
CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(0, 0, doc.first_child()) == 1)); CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(PUGIXML_NULL, 0, doc.first_child()) == 1));
} }
TEST_XML(xpath_out_of_memory_evaluate_normalize_space_1, "<node> a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z </node>") TEST_XML(xpath_out_of_memory_evaluate_normalize_space_1, "<node> a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z </node>")
@ -525,7 +525,7 @@ TEST_XML(xpath_out_of_memory_evaluate_normalize_space_1, "<node> a b c d e f g h
xpath_query q(STR("concat(normalize-space(node), normalize-space(node), normalize-space(node), normalize-space(node), normalize-space(node), normalize-space(node), normalize-space(node), normalize-space(node))")); xpath_query q(STR("concat(normalize-space(node), normalize-space(node), normalize-space(node), normalize-space(node), normalize-space(node), normalize-space(node), normalize-space(node), normalize-space(node))"));
CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(0, 0, doc) == 1)); CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(PUGIXML_NULL, 0, doc) == 1));
} }
TEST_XML(xpath_out_of_memory_evaluate_translate, "<node> a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z </node>") TEST_XML(xpath_out_of_memory_evaluate_translate, "<node> a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z </node>")
@ -534,7 +534,7 @@ TEST_XML(xpath_out_of_memory_evaluate_translate, "<node> a b c d e f g h i j k l
xpath_query q(STR("concat(translate(node, 'a', '\xe9'), translate(node, 'a', '\xe9'), translate(node, 'a', '\xe9'), translate(node, 'a', '\xe9'), translate(node, 'a', '\xe9'), translate(node, 'a', '\xe9'), translate(node, 'a', '\xe9'), translate(node, 'a', '\xe9'))")); xpath_query q(STR("concat(translate(node, 'a', '\xe9'), translate(node, 'a', '\xe9'), translate(node, 'a', '\xe9'), translate(node, 'a', '\xe9'), translate(node, 'a', '\xe9'), translate(node, 'a', '\xe9'), translate(node, 'a', '\xe9'), translate(node, 'a', '\xe9'))"));
CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(0, 0, doc) == 1)); CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(PUGIXML_NULL, 0, doc) == 1));
} }
TEST_XML(xpath_out_of_memory_evaluate_translate_table, "<node> a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z </node>") TEST_XML(xpath_out_of_memory_evaluate_translate_table, "<node> a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z </node>")
@ -543,7 +543,7 @@ TEST_XML(xpath_out_of_memory_evaluate_translate_table, "<node> a b c d e f g h i
xpath_query q(STR("concat(translate(node, 'a', 'A'), translate(node, 'a', 'A'), translate(node, 'a', 'A'), translate(node, 'a', 'A'), translate(node, 'a', 'A'), translate(node, 'a', 'A'), translate(node, 'a', 'A'), translate(node, 'a', 'A'))")); xpath_query q(STR("concat(translate(node, 'a', 'A'), translate(node, 'a', 'A'), translate(node, 'a', 'A'), translate(node, 'a', 'A'), translate(node, 'a', 'A'), translate(node, 'a', 'A'), translate(node, 'a', 'A'), translate(node, 'a', 'A'))"));
CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(0, 0, doc) == 1)); CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(PUGIXML_NULL, 0, doc) == 1));
} }
TEST(xpath_out_of_memory_evaluate_string_append) TEST(xpath_out_of_memory_evaluate_string_append)
@ -563,7 +563,7 @@ TEST(xpath_out_of_memory_evaluate_string_append)
xpath_query q(STR("string(n)")); xpath_query q(STR("string(n)"));
CHECK(q); CHECK(q);
CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(0, 0, doc) == 1)); CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(PUGIXML_NULL, 0, doc) == 1));
} }
TEST(xpath_out_of_memory_evaluate_number_to_string) TEST(xpath_out_of_memory_evaluate_number_to_string)
@ -575,7 +575,7 @@ TEST(xpath_out_of_memory_evaluate_number_to_string)
xpath_query q(STR("concat($x, $x, $x, $x, $x, $x, $x, $x, $x, $x, $x, $x, $x, $x, $x, $x, $x)"), &vars); xpath_query q(STR("concat($x, $x, $x, $x, $x, $x, $x, $x, $x, $x, $x, $x, $x, $x, $x, $x, $x)"), &vars);
CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(0, 0, xml_node()) == 1)); CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(PUGIXML_NULL, 0, xml_node()) == 1));
} }
TEST(xpath_memory_concat_massive) TEST(xpath_memory_concat_massive)
@ -587,7 +587,7 @@ TEST(xpath_memory_concat_massive)
node.append_child(STR("c")).text().set(i % 10); node.append_child(STR("c")).text().set(i % 10);
xpath_query q(STR("/")); xpath_query q(STR("/"));
size_t size = q.evaluate_string(0, 0, node); size_t size = q.evaluate_string(PUGIXML_NULL, 0, node);
CHECK(size == 5001); CHECK(size == 5001);
} }

View File

@ -198,7 +198,7 @@ TEST_XML(xpath_api_evaluate_fail, "<node attr='3'/>")
CHECK(q.evaluate_boolean(doc) == false); CHECK(q.evaluate_boolean(doc) == false);
CHECK_DOUBLE_NAN(q.evaluate_number(doc)); CHECK_DOUBLE_NAN(q.evaluate_number(doc));
CHECK(q.evaluate_string(0, 0, doc) == 1); // null terminator CHECK(q.evaluate_string(PUGIXML_NULL, 0, doc) == 1); // null terminator
#ifndef PUGIXML_NO_STL #ifndef PUGIXML_NO_STL
CHECK(q.evaluate_string(doc).empty()); CHECK(q.evaluate_string(doc).empty());
@ -277,7 +277,7 @@ TEST(xpath_api_evaluate_string)
// test for empty buffer // test for empty buffer
std::basic_string<char_t> s5 = base; std::basic_string<char_t> s5 = base;
CHECK(q.evaluate_string(&s5[0], 0, xml_node()) == 11 && memcmp(&s5[0], STR("xxxxxxxxxxxxxxxx"), 16 * sizeof(char_t)) == 0); CHECK(q.evaluate_string(&s5[0], 0, xml_node()) == 11 && memcmp(&s5[0], STR("xxxxxxxxxxxxxxxx"), 16 * sizeof(char_t)) == 0);
CHECK(q.evaluate_string(0, 0, xml_node()) == 11); CHECK(q.evaluate_string(PUGIXML_NULL, 0, xml_node()) == 11);
} }
TEST(xpath_api_return_type) TEST(xpath_api_return_type)
@ -315,7 +315,7 @@ TEST(xpath_api_query_result)
xpath_query q(STR("node")); xpath_query q(STR("node"));
CHECK(q.result()); CHECK(q.result());
CHECK(q.result().error == 0); CHECK(q.result().error == PUGIXML_NULL);
CHECK(q.result().offset == 0); CHECK(q.result().offset == 0);
CHECK(strcmp(q.result().description(), "No error") == 0); CHECK(strcmp(q.result().description(), "No error") == 0);
} }
@ -337,7 +337,7 @@ TEST(xpath_api_query_result_fail)
xpath_parse_result result = q.result(); xpath_parse_result result = q.result();
CHECK(!result); CHECK(!result);
CHECK(result.error != 0 && result.error[0] != 0); CHECK(result.error != PUGIXML_NULL && result.error[0] != 0);
CHECK(result.description() == result.error); CHECK(result.description() == result.error);
CHECK(result.offset == 13); CHECK(result.offset == 13);

View File

@ -332,7 +332,7 @@ TEST(xpath_parse_result_default)
xpath_parse_result result; xpath_parse_result result;
CHECK(!result); CHECK(!result);
CHECK(result.error != 0); CHECK(result.error != PUGIXML_NULL);
CHECK(result.offset == 0); CHECK(result.offset == 0);
} }

View File

@ -135,15 +135,15 @@ TEST(xpath_variables_set_operations)
CHECK(set.add(STR("var1"), xpath_type_number) == v1); CHECK(set.add(STR("var1"), xpath_type_number) == v1);
CHECK(set.add(STR("var2"), xpath_type_string) == v2); CHECK(set.add(STR("var2"), xpath_type_string) == v2);
CHECK(set.add(STR("var2"), xpath_type_node_set) == 0); CHECK(set.add(STR("var2"), xpath_type_node_set) == PUGIXML_NULL);
CHECK(set.get(STR("var1")) == v1); CHECK(set.get(STR("var1")) == v1);
CHECK(set.get(STR("var2")) == v2); CHECK(set.get(STR("var2")) == v2);
CHECK(set.get(STR("var")) == 0); CHECK(set.get(STR("var")) == PUGIXML_NULL);
CHECK(set.get(STR("var11")) == 0); CHECK(set.get(STR("var11")) == PUGIXML_NULL);
CHECK(static_cast<const xpath_variable_set&>(set).get(STR("var1")) == v1); CHECK(static_cast<const xpath_variable_set&>(set).get(STR("var1")) == v1);
CHECK(static_cast<const xpath_variable_set&>(set).get(STR("var3")) == 0); CHECK(static_cast<const xpath_variable_set&>(set).get(STR("var3")) == PUGIXML_NULL);
} }
TEST_XML(xpath_variables_set_operations_set, "<node/>") TEST_XML(xpath_variables_set_operations_set, "<node/>")
@ -179,7 +179,7 @@ TEST(xpath_variables_set_out_of_memory)
xpath_variable_set set; xpath_variable_set set;
xpath_variable* var = 0; xpath_variable* var = PUGIXML_NULL;
CHECK_ALLOC_FAIL(var = set.add(STR("target"), xpath_type_number)); CHECK_ALLOC_FAIL(var = set.add(STR("target"), xpath_type_number));
CHECK(!var); CHECK(!var);
} }