diff --git a/Makefile b/Makefile index 028641b..e190e97 100644 --- a/Makefile +++ b/Makefile @@ -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 LDFLAGS= +ifneq ($(cxxstd),c++98) + CXXFLAGS+=-Wzero-as-null-pointer-constant +endif + ifeq ($(config),release) CXXFLAGS+=-O3 -DNDEBUG endif diff --git a/src/pugixml.cpp b/src/pugixml.cpp index ee8a666..c4f021b 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -282,7 +282,7 @@ PUGI__NS_BEGIN T* release() { T* result = data; - data = 0; + data = PUGIXML_NULL; return result; } }; @@ -293,7 +293,7 @@ PUGI__NS_BEGIN class compact_hash_table { public: - compact_hash_table(): _items(0), _capacity(0), _count(0) + compact_hash_table(): _items(PUGIXML_NULL), _capacity(0), _count(0) { } @@ -302,7 +302,7 @@ PUGI__NS_BEGIN if (_items) { xml_memory::deallocate(_items); - _items = 0; + _items = PUGIXML_NULL; _capacity = 0; _count = 0; } @@ -310,11 +310,11 @@ PUGI__NS_BEGIN void* find(const void* key) { - if (_capacity == 0) return 0; + if (_capacity == 0) return PUGIXML_NULL; item_t* item = get_item(key); assert(item); - assert(item->key == key || (item->key == 0 && item->value == 0)); + assert(item->key == key || (item->key == PUGIXML_NULL && item->value == PUGIXML_NULL)); return item->value; } @@ -326,7 +326,7 @@ PUGI__NS_BEGIN item_t* item = get_item(key); assert(item); - if (item->key == 0) + if (item->key == PUGIXML_NULL) { _count++; item->key = key; @@ -369,7 +369,7 @@ PUGI__NS_BEGIN { item_t& probe_item = _items[bucket]; - if (probe_item.key == key || probe_item.key == 0) + if (probe_item.key == key || probe_item.key == PUGIXML_NULL) return &probe_item; // hash collision, quadratic probing @@ -377,7 +377,7 @@ PUGI__NS_BEGIN } assert(false && "Hash table is full"); // unreachable - return 0; + return PUGIXML_NULL; } static PUGI__UNSIGNED_OVERFLOW unsigned int hash(const void* key) @@ -465,16 +465,16 @@ PUGI__NS_BEGIN { xml_memory_page* result = static_cast(memory); - result->allocator = 0; - result->prev = 0; - result->next = 0; + result->allocator = PUGIXML_NULL; + result->prev = PUGIXML_NULL; + result->next = PUGIXML_NULL; result->busy_size = 0; result->freed_size = 0; #ifdef PUGIXML_COMPACT - result->compact_string_base = 0; - result->compact_shared_parent = 0; - result->compact_page_marker = 0; + result->compact_string_base = PUGIXML_NULL; + result->compact_shared_parent = PUGIXML_NULL; + result->compact_page_marker = PUGIXML_NULL; #endif return result; @@ -514,7 +514,7 @@ PUGI__NS_BEGIN xml_allocator(xml_memory_page* root): _root(root), _busy_size(root->busy_size) { #ifdef PUGIXML_COMPACT - _hash = 0; + _hash = PUGIXML_NULL; #endif } @@ -524,7 +524,7 @@ PUGI__NS_BEGIN // allocate block with some alignment, leaving memory for worst-case padding void* memory = xml_memory::allocate(size); - if (!memory) return 0; + if (!memory) return PUGIXML_NULL; // prepare page structure xml_memory_page* page = xml_memory_page::construct(memory); @@ -561,7 +561,7 @@ PUGI__NS_BEGIN void* allocate_object(size_t size, xml_memory_page*& out_page) { void* result = allocate_memory(size + sizeof(uint32_t), out_page); - if (!result) return 0; + if (!result) return PUGIXML_NULL; // adjust for marker ptrdiff_t offset = static_cast(result) - reinterpret_cast(out_page->compact_page_marker); @@ -607,7 +607,7 @@ PUGI__NS_BEGIN if (page->freed_size == page->busy_size) { - if (page->next == 0) + if (page->next == PUGIXML_NULL) { assert(_root == page); @@ -617,9 +617,9 @@ PUGI__NS_BEGIN #ifdef PUGIXML_COMPACT // reset compact state to maximize efficiency - page->compact_string_base = 0; - page->compact_shared_parent = 0; - page->compact_page_marker = 0; + page->compact_string_base = PUGIXML_NULL; + page->compact_shared_parent = PUGIXML_NULL; + page->compact_page_marker = PUGIXML_NULL; #endif _busy_size = 0; @@ -654,7 +654,7 @@ PUGI__NS_BEGIN xml_memory_page* page; xml_memory_string_header* header = static_cast(allocate_memory(full_size, page)); - if (!header) return 0; + if (!header) return PUGIXML_NULL; // setup header ptrdiff_t page_offset = reinterpret_cast(header) - reinterpret_cast(page) - sizeof(xml_memory_page); @@ -716,7 +716,7 @@ PUGI__NS_BEGIN xml_memory_page* page = allocate_page(size <= large_allocation_threshold ? xml_memory_page_size : size); out_page = page; - if (!page) return 0; + if (!page) return PUGIXML_NULL; if (size <= large_allocation_threshold) { @@ -863,7 +863,7 @@ PUGI__NS_BEGIN return compact_get_value(this); } else - return 0; + return PUGIXML_NULL; } T* operator->() const @@ -906,7 +906,7 @@ PUGI__NS_BEGIN { xml_memory_page* page = compact_get_page(this, header_offset); - if (PUGI__UNLIKELY(page->compact_shared_parent == 0)) + if (PUGI__UNLIKELY(page->compact_shared_parent == PUGIXML_NULL)) page->compact_shared_parent = value; if (page->compact_shared_parent == value) @@ -943,7 +943,7 @@ PUGI__NS_BEGIN return compact_get_value(this); } else - return 0; + return PUGIXML_NULL; } T* operator->() const @@ -973,7 +973,7 @@ PUGI__NS_BEGIN { xml_memory_page* page = compact_get_page(this, header_offset); - if (PUGI__UNLIKELY(page->compact_string_base == 0)) + if (PUGI__UNLIKELY(page->compact_string_base == PUGIXML_NULL)) page->compact_string_base = value; ptrdiff_t offset = value - page->compact_string_base; @@ -1039,7 +1039,7 @@ PUGI__NS_BEGIN } } else - return 0; + return PUGIXML_NULL; } private: @@ -1098,7 +1098,7 @@ namespace pugi { struct xml_attribute_struct { - xml_attribute_struct(impl::xml_memory_page* page): name(0), value(0), prev_attribute_c(0), next_attribute(0) + xml_attribute_struct(impl::xml_memory_page* page): name(PUGIXML_NULL), value(PUGIXML_NULL), prev_attribute_c(PUGIXML_NULL), next_attribute(PUGIXML_NULL) { header = PUGI__GETHEADER_IMPL(this, page, 0); } @@ -1114,7 +1114,7 @@ namespace pugi struct xml_node_struct { - xml_node_struct(impl::xml_memory_page* page, xml_node_type type): name(0), value(0), parent(0), first_child(0), prev_sibling_c(0), next_sibling(0), first_attribute(0) + xml_node_struct(impl::xml_memory_page* page, xml_node_type type): name(PUGIXML_NULL), value(PUGIXML_NULL), parent(PUGIXML_NULL), first_child(PUGIXML_NULL), prev_sibling_c(PUGIXML_NULL), next_sibling(PUGIXML_NULL), first_attribute(PUGIXML_NULL) { header = PUGI__GETHEADER_IMPL(this, page, type); } @@ -1145,7 +1145,7 @@ PUGI__NS_BEGIN struct xml_document_struct: public xml_node_struct, public xml_allocator { - xml_document_struct(xml_memory_page* page): xml_node_struct(page, node_document), xml_allocator(page), buffer(0), extra_buffers(0) + xml_document_struct(xml_memory_page* page): xml_node_struct(page, node_document), xml_allocator(page), buffer(PUGIXML_NULL), extra_buffers(PUGIXML_NULL) { } @@ -1179,7 +1179,7 @@ PUGI__NS_BEGIN { xml_memory_page* page; void* memory = alloc.allocate_object(sizeof(xml_attribute_struct), page); - if (!memory) return 0; + if (!memory) return PUGIXML_NULL; return new (memory) xml_attribute_struct(page); } @@ -1188,7 +1188,7 @@ PUGI__NS_BEGIN { xml_memory_page* page; void* memory = alloc.allocate_object(sizeof(xml_node_struct), page); - if (!memory) return 0; + if (!memory) return PUGIXML_NULL; return new (memory) xml_node_struct(page, type); } @@ -1327,9 +1327,9 @@ PUGI__NS_BEGIN else parent->first_child = next; - node->parent = 0; - node->prev_sibling_c = 0; - node->next_sibling = 0; + node->parent = PUGIXML_NULL; + node->prev_sibling_c = PUGIXML_NULL; + node->next_sibling = PUGIXML_NULL; } inline void append_attribute(xml_attribute_struct* attr, xml_node_struct* node) @@ -1410,16 +1410,16 @@ PUGI__NS_BEGIN else node->first_attribute = next; - attr->prev_attribute_c = 0; - attr->next_attribute = 0; + attr->prev_attribute_c = PUGIXML_NULL; + attr->next_attribute = PUGIXML_NULL; } PUGI__FN_NO_INLINE xml_node_struct* append_new_node(xml_node_struct* node, xml_allocator& alloc, xml_node_type type = node_element) { - if (!alloc.reserve()) return 0; + if (!alloc.reserve()) return PUGIXML_NULL; xml_node_struct* child = allocate_node(alloc, type); - if (!child) return 0; + if (!child) return PUGIXML_NULL; append_node(child, node); @@ -1428,10 +1428,10 @@ PUGI__NS_BEGIN PUGI__FN_NO_INLINE xml_attribute_struct* append_new_attribute(xml_node_struct* node, xml_allocator& alloc) { - if (!alloc.reserve()) return 0; + if (!alloc.reserve()) return PUGIXML_NULL; xml_attribute_struct* attr = allocate_attribute(alloc); - if (!attr) return 0; + if (!attr) return PUGIXML_NULL; append_attribute(attr, node); @@ -2013,7 +2013,7 @@ PUGI__NS_BEGIN if (d0 == 0x3c && d1 == 0) return encoding_utf16_le; // no known BOM detected; parse declaration - const uint8_t* enc = 0; + const uint8_t* enc = PUGIXML_NULL; size_t enc_length = 0; if (d0 == 0x3c && d1 == 0x3f && d2 == 0x78 && d3 == 0x6d && parse_declaration_encoding(data, size, enc, enc_length)) @@ -2382,7 +2382,7 @@ PUGI__NS_BEGIN if (header & header_mask) alloc->deallocate_string(dest); // mark the string as not allocated - dest = 0; + dest = PUGIXML_NULL; header &= ~header_mask; return true; @@ -2425,7 +2425,7 @@ PUGI__NS_BEGIN char_t* end; size_t size; - gap(): end(0), size(0) + gap(): end(PUGIXML_NULL), size(0) { } @@ -2612,7 +2612,7 @@ PUGI__NS_BEGIN #define PUGI__SCANWHILE(X) { while (X) ++s; } #define PUGI__SCANWHILE_UNROLL(X) { for (;;) { char_t ss = s[0]; if (PUGI__UNLIKELY(!(X))) { break; } ss = s[1]; if (PUGI__UNLIKELY(!(X))) { s += 1; break; } ss = s[2]; if (PUGI__UNLIKELY(!(X))) { s += 2; break; } ss = s[3]; if (PUGI__UNLIKELY(!(X))) { s += 3; break; } s += 4; } } #define PUGI__ENDSEG() { ch = *s; *s = 0; ++s; } - #define PUGI__THROW_ERROR(err, m) return error_offset = m, error_status = err, static_cast(0) + #define PUGI__THROW_ERROR(err, m) return error_offset = m, error_status = err, static_cast(PUGIXML_NULL) #define PUGI__CHECK_ERROR(err, m) { if (*s == 0) PUGI__THROW_ERROR(err, m); } PUGI__FN char_t* strconv_comment(char_t* s, char_t endch) @@ -2637,7 +2637,7 @@ PUGI__NS_BEGIN } else if (*s == 0) { - return 0; + return PUGIXML_NULL; } else ++s; } @@ -2665,7 +2665,7 @@ PUGI__NS_BEGIN } else if (*s == 0) { - return 0; + return PUGIXML_NULL; } else ++s; } @@ -2738,7 +2738,7 @@ PUGI__NS_BEGIN case 5: return strconv_pcdata_impl::parse; case 6: return strconv_pcdata_impl::parse; case 7: return strconv_pcdata_impl::parse; - default: assert(false); return 0; // unreachable + default: assert(false); return PUGIXML_NULL; // unreachable } } @@ -2792,7 +2792,7 @@ PUGI__NS_BEGIN } else if (!*s) { - return 0; + return PUGIXML_NULL; } else ++s; } @@ -2828,7 +2828,7 @@ PUGI__NS_BEGIN } else if (!*s) { - return 0; + return PUGIXML_NULL; } else ++s; } @@ -2860,7 +2860,7 @@ PUGI__NS_BEGIN } else if (!*s) { - return 0; + return PUGIXML_NULL; } else ++s; } @@ -2886,7 +2886,7 @@ PUGI__NS_BEGIN } else if (!*s) { - return 0; + return PUGIXML_NULL; } else ++s; } @@ -2915,7 +2915,7 @@ PUGI__NS_BEGIN case 13: return strconv_attribute_impl::parse_wnorm; case 14: return strconv_attribute_impl::parse_wnorm; case 15: return strconv_attribute_impl::parse_wnorm; - default: assert(false); return 0; // unreachable + default: assert(false); return PUGIXML_NULL; // unreachable } } @@ -2934,7 +2934,7 @@ PUGI__NS_BEGIN char_t* error_offset; xml_parse_status error_status; - xml_parser(xml_allocator* alloc_): alloc(alloc_), error_offset(0), error_status(status_ok) + xml_parser(xml_allocator* alloc_): alloc(alloc_), error_offset(PUGIXML_NULL), error_status(status_ok) { } @@ -3528,7 +3528,7 @@ PUGI__NS_BEGIN return make_parse_result(PUGI__OPTSET(parse_fragment) ? status_ok : status_no_document_element); // get last child of the root before parsing - xml_node_struct* last_root_child = root->first_child ? root->first_child->prev_sibling_c + 0 : 0; + xml_node_struct* last_root_child = root->first_child ? root->first_child->prev_sibling_c + 0 : PUGIXML_NULL; // create parser on stack xml_parser parser(static_cast(xmldoc)); @@ -4445,7 +4445,7 @@ PUGI__NS_BEGIN PUGI__FN void node_copy_tree(xml_node_struct* dn, xml_node_struct* sn) { xml_allocator& alloc = get_allocator(dn); - xml_allocator* shared_alloc = (&alloc == &get_allocator(sn)) ? &alloc : 0; + xml_allocator* shared_alloc = (&alloc == &get_allocator(sn)) ? &alloc : PUGIXML_NULL; node_copy_contents(dn, sn, shared_alloc); @@ -4499,7 +4499,7 @@ PUGI__NS_BEGIN PUGI__FN void node_copy_attribute(xml_attribute_struct* da, xml_attribute_struct* sa) { xml_allocator& alloc = get_allocator(da); - xml_allocator* shared_alloc = (&alloc == &get_allocator(sa)) ? &alloc : 0; + xml_allocator* shared_alloc = (&alloc == &get_allocator(sa)) ? &alloc : PUGIXML_NULL; node_copy_string(da->name, da->header, xml_memory_page_name_allocated_mask, sa->name, sa->header, shared_alloc); node_copy_string(da->value, da->header, xml_memory_page_value_allocated_mask, sa->value, sa->header, shared_alloc); @@ -4608,18 +4608,18 @@ PUGI__NS_BEGIN PUGI__FN double get_value_double(const char_t* value) { #ifdef PUGIXML_WCHAR_MODE - return wcstod(value, 0); + return wcstod(value, PUGIXML_NULL); #else - return strtod(value, 0); + return strtod(value, PUGIXML_NULL); #endif } PUGI__FN float get_value_float(const char_t* value) { #ifdef PUGIXML_WCHAR_MODE - return static_cast(wcstod(value, 0)); + return static_cast(wcstod(value, PUGIXML_NULL)); #else - return static_cast(strtod(value, 0)); + return static_cast(strtod(value, PUGIXML_NULL)); #endif } @@ -4724,10 +4724,10 @@ PUGI__NS_BEGIN xml_encoding buffer_encoding = impl::get_buffer_encoding(encoding, contents, size); // if convert_buffer below throws bad_alloc, we still need to deallocate contents if we own it - auto_deleter contents_guard(own ? contents : 0, xml_memory::deallocate); + auto_deleter contents_guard(own ? contents : PUGIXML_NULL, xml_memory::deallocate); // get private buffer - char_t* buffer = 0; + char_t* buffer = PUGIXML_NULL; size_t length = 0; // coverity[var_deref_model] @@ -4859,7 +4859,7 @@ PUGI__NS_BEGIN static xml_stream_chunk* create() { void* memory = xml_memory::allocate(sizeof(xml_stream_chunk)); - if (!memory) return 0; + if (!memory) return PUGIXML_NULL; return new (memory) xml_stream_chunk(); } @@ -4877,7 +4877,7 @@ PUGI__NS_BEGIN } } - xml_stream_chunk(): next(0), size(0) + xml_stream_chunk(): next(PUGIXML_NULL), size(0) { } @@ -4889,11 +4889,11 @@ PUGI__NS_BEGIN template PUGI__FN xml_parse_status load_stream_data_noseek(std::basic_istream& stream, void** out_buffer, size_t* out_size) { - auto_deleter > chunks(0, xml_stream_chunk::destroy); + auto_deleter > chunks(PUGIXML_NULL, xml_stream_chunk::destroy); // read file to a chunk list size_t total = 0; - xml_stream_chunk* last = 0; + xml_stream_chunk* last = PUGIXML_NULL; while (!stream.eof()) { @@ -4979,7 +4979,7 @@ PUGI__NS_BEGIN template PUGI__FN xml_parse_result load_stream_impl(xml_document_struct* doc, std::basic_istream& stream, unsigned int options, xml_encoding encoding, char_t** out_buffer) { - void* buffer = 0; + void* buffer = PUGIXML_NULL; size_t size = 0; xml_parse_status status = status_ok; @@ -5024,7 +5024,7 @@ PUGI__NS_BEGIN // allocate resulting string char* result = static_cast(xml_memory::allocate(size + 1)); - if (!result) return 0; + if (!result) return PUGIXML_NULL; // second pass: convert to utf8 as_utf8_end(result, size, str, length); @@ -5039,7 +5039,7 @@ PUGI__NS_BEGIN { // there is no standard function to open wide paths, so our best bet is to try utf8 path char* path_utf8 = convert_path_heap(path); - if (!path_utf8) return 0; + if (!path_utf8) return PUGIXML_NULL; // convert mode to ASCII (we mirror _wfopen interface) char mode_ascii[4] = {0}; @@ -5082,7 +5082,7 @@ PUGI__NS_BEGIN name_null_sentry(xml_node_struct* node_): node(node_), name(node_->name) { - node->name = 0; + node->name = PUGIXML_NULL; } ~name_null_sentry() @@ -5105,11 +5105,11 @@ namespace pugi } #ifndef PUGIXML_NO_STL - PUGI__FN xml_writer_stream::xml_writer_stream(std::basic_ostream >& stream): narrow_stream(&stream), wide_stream(0) + PUGI__FN xml_writer_stream::xml_writer_stream(std::basic_ostream >& stream): narrow_stream(&stream), wide_stream(PUGIXML_NULL) { } - PUGI__FN xml_writer_stream::xml_writer_stream(std::basic_ostream >& stream): narrow_stream(0), wide_stream(&stream) + PUGI__FN xml_writer_stream::xml_writer_stream(std::basic_ostream >& stream): narrow_stream(PUGIXML_NULL), wide_stream(&stream) { } @@ -5153,7 +5153,7 @@ namespace pugi return true; } - PUGI__FN xml_attribute::xml_attribute(): _attr(0) + PUGI__FN xml_attribute::xml_attribute(): _attr(PUGIXML_NULL) { } @@ -5167,7 +5167,7 @@ namespace pugi PUGI__FN xml_attribute::operator xml_attribute::unspecified_bool_type() const { - return _attr ? unspecified_bool_xml_attribute : 0; + return _attr ? unspecified_bool_xml_attribute : PUGIXML_NULL; } PUGI__FN bool xml_attribute::operator!() const @@ -5479,7 +5479,7 @@ namespace pugi } #endif - PUGI__FN xml_node::xml_node(): _root(0) + PUGI__FN xml_node::xml_node(): _root(PUGIXML_NULL) { } @@ -5493,7 +5493,7 @@ namespace pugi PUGI__FN xml_node::operator xml_node::unspecified_bool_type() const { - return _root ? unspecified_bool_xml_node : 0; + return _root ? unspecified_bool_xml_node : PUGIXML_NULL; } PUGI__FN bool xml_node::operator!() const @@ -5503,22 +5503,22 @@ namespace pugi PUGI__FN xml_node::iterator xml_node::begin() const { - return iterator(_root ? _root->first_child + 0 : 0, _root); + return iterator(_root ? _root->first_child + 0 : PUGIXML_NULL, _root); } PUGI__FN xml_node::iterator xml_node::end() const { - return iterator(0, _root); + return iterator(PUGIXML_NULL, _root); } PUGI__FN xml_node::attribute_iterator xml_node::attributes_begin() const { - return attribute_iterator(_root ? _root->first_attribute + 0 : 0, _root); + return attribute_iterator(_root ? _root->first_attribute + 0 : PUGIXML_NULL, _root); } PUGI__FN xml_node::attribute_iterator xml_node::attributes_end() const { - return attribute_iterator(0, _root); + return attribute_iterator(PUGIXML_NULL, _root); } PUGI__FN xml_object_range xml_node::children() const @@ -5528,7 +5528,7 @@ namespace pugi PUGI__FN xml_object_range xml_node::children(const char_t* name_) const { - return xml_object_range(xml_named_node_iterator(child(name_)._root, _root, name_), xml_named_node_iterator(0, _root, name_)); + return xml_object_range(xml_named_node_iterator(child(name_)._root, _root, name_), xml_named_node_iterator(PUGIXML_NULL, _root, name_)); } PUGI__FN xml_object_range xml_node::attributes() const @@ -6210,7 +6210,7 @@ namespace pugi attr = next; } - _root->first_attribute = 0; + _root->first_attribute = PUGIXML_NULL; return true; } @@ -6249,7 +6249,7 @@ namespace pugi cur = next; } - _root->first_child = 0; + _root->first_child = PUGIXML_NULL; return true; } @@ -6266,7 +6266,7 @@ namespace pugi doc->header |= impl::xml_memory_page_contents_shared_mask; // get extra buffer element (we'll store the document fragment buffer there so that we can deallocate it later) - impl::xml_memory_page* page = 0; + impl::xml_memory_page* page = PUGIXML_NULL; impl::xml_extra_buffer* extra = static_cast(doc->allocate_memory(sizeof(impl::xml_extra_buffer) + sizeof(void*), page)); (void)page; @@ -6279,11 +6279,11 @@ namespace pugi #endif // add extra buffer to the list - extra->buffer = 0; + extra->buffer = PUGIXML_NULL; extra->next = doc->extra_buffers; doc->extra_buffers = extra; - // name of the root has to be NULL before parsing - otherwise closing node mismatches will not be detected at the top level + // name of the root has to be PUGIXML_NULL before parsing - otherwise closing node mismatches will not be detected at the top level impl::name_null_sentry sentry(_root); return impl::load_buffer_impl(doc, _root, const_cast(contents), size, options, encoding, false, false, &extra->buffer); @@ -6419,7 +6419,7 @@ namespace pugi xml_node arg_begin(_root); if (!walker.begin(arg_begin)) return false; - xml_node_struct* cur = _root ? _root->first_child + 0 : 0; + xml_node_struct* cur = _root ? _root->first_child + 0 : PUGIXML_NULL; if (cur) { @@ -6555,7 +6555,7 @@ namespace pugi if (impl::is_text_node(node)) return node; - return 0; + return PUGIXML_NULL; } PUGI__FN xml_node_struct* xml_text::_data_new() @@ -6566,7 +6566,7 @@ namespace pugi return xml_node(_root).append_child(node_pcdata).internal_object(); } - PUGI__FN xml_text::xml_text(): _root(0) + PUGI__FN xml_text::xml_text(): _root(PUGIXML_NULL) { } @@ -6576,7 +6576,7 @@ namespace pugi PUGI__FN xml_text::operator xml_text::unspecified_bool_type() const { - return _data() ? unspecified_bool_xml_text : 0; + return _data() ? unspecified_bool_xml_text : PUGIXML_NULL; } PUGI__FN bool xml_text::operator!() const @@ -6586,7 +6586,7 @@ namespace pugi PUGI__FN bool xml_text::empty() const { - return _data() == 0; + return _data() == PUGIXML_NULL; } PUGI__FN const char_t* xml_text::get() const @@ -6957,7 +6957,7 @@ namespace pugi return temp; } - PUGI__FN xml_named_node_iterator::xml_named_node_iterator(): _name(0) + PUGI__FN xml_named_node_iterator::xml_named_node_iterator(): _name(PUGIXML_NULL) { } @@ -7067,7 +7067,7 @@ namespace pugi } } - PUGI__FN xml_document::xml_document(): _buffer(0) + PUGI__FN xml_document::xml_document(): _buffer(PUGIXML_NULL) { _create(); } @@ -7078,7 +7078,7 @@ namespace pugi } #ifdef PUGIXML_HAS_MOVE - PUGI__FN xml_document::xml_document(xml_document&& rhs) PUGIXML_NOEXCEPT_IF_NOT_COMPACT: _buffer(0) + PUGI__FN xml_document::xml_document(xml_document&& rhs) PUGIXML_NOEXCEPT_IF_NOT_COMPACT: _buffer(PUGIXML_NULL) { _create(); _move(rhs); @@ -7160,7 +7160,7 @@ namespace pugi if (_buffer) { impl::xml_memory::deallocate(_buffer); - _buffer = 0; + _buffer = PUGIXML_NULL; } // destroy extra buffers (note: no need to destroy linked list nodes, they're allocated using document allocator) @@ -7188,7 +7188,7 @@ namespace pugi static_cast(_root)->hash.clear(); #endif - _root = 0; + _root = PUGIXML_NULL; } #ifdef PUGIXML_HAS_MOVE @@ -7243,7 +7243,7 @@ namespace pugi doc->_hash = &doc->hash; // make sure we don't access other hash up until the end when we reinitialize other document - other->_hash = 0; + other->_hash = PUGIXML_NULL; #endif // move page structure @@ -7261,7 +7261,7 @@ namespace pugi page->prev = doc_page; doc_page->next = page; - other_page->next = 0; + other_page->next = PUGIXML_NULL; } // make sure pages point to the correct document state @@ -7298,7 +7298,7 @@ namespace pugi // reset other document new (other) impl::xml_document_struct(PUGI__GETPAGE(other)); - rhs._buffer = 0; + rhs._buffer = PUGIXML_NULL; } #endif @@ -7725,7 +7725,7 @@ PUGI__NS_BEGIN for (size_t probe = 0; probe <= hashmod; ++probe) { - if (table[bucket] == 0) + if (table[bucket] == PUGIXML_NULL) { table[bucket] = key; return true; @@ -7773,7 +7773,7 @@ PUGI__NS_BEGIN size_t _root_size; bool* _error; - xpath_allocator(xpath_memory_block* root, bool* error = 0): _root(root), _root_size(0), _error(error) + xpath_allocator(xpath_memory_block* root, bool* error = PUGIXML_NULL): _root(root), _root_size(0), _error(error) { } @@ -7801,7 +7801,7 @@ PUGI__NS_BEGIN if (!block) { if (_error) *_error = true; - return 0; + return PUGIXML_NULL; } block->next = _root; @@ -7821,7 +7821,7 @@ PUGI__NS_BEGIN new_size = (new_size + xpath_memory_block_alignment - 1) & ~(xpath_memory_block_alignment - 1); // we can only reallocate the last object - assert(ptr == 0 || static_cast(ptr) + old_size == &_root->data[0] + _root_size); + assert(ptr == PUGIXML_NULL || static_cast(ptr) + old_size == &_root->data[0] + _root_size); // try to reallocate the object inplace if (ptr && _root_size - old_size + new_size <= _root->capacity) @@ -7832,7 +7832,7 @@ PUGI__NS_BEGIN // allocate a new block void* result = allocate(new_size); - if (!result) return 0; + if (!result) return PUGIXML_NULL; // we have a new block if (ptr) @@ -7927,7 +7927,7 @@ PUGI__NS_BEGIN xpath_stack_data(): result(blocks + 0, &oom), temp(blocks + 1, &oom), oom(false) { - blocks[0].next = blocks[1].next = 0; + blocks[0].next = blocks[1].next = PUGIXML_NULL; blocks[0].capacity = blocks[1].capacity = sizeof(blocks[0].data); stack.result = &result; @@ -7953,7 +7953,7 @@ PUGI__NS_BEGIN static char_t* duplicate_string(const char_t* string, size_t length, xpath_allocator* alloc) { char_t* result = static_cast(alloc->allocate((length + 1) * sizeof(char_t))); - if (!result) return 0; + if (!result) return PUGIXML_NULL; memcpy(result, string, length * sizeof(char_t)); result[length] = 0; @@ -8013,7 +8013,7 @@ PUGI__NS_BEGIN size_t result_length = target_length + source_length; // allocate new buffer - char_t* result = static_cast(alloc->reallocate(_uses_heap ? const_cast(_buffer) : 0, (target_length + 1) * sizeof(char_t), (result_length + 1) * sizeof(char_t))); + char_t* result = static_cast(alloc->reallocate(_uses_heap ? const_cast(_buffer) : PUGIXML_NULL, (target_length + 1) * sizeof(char_t), (result_length + 1) * sizeof(char_t))); if (!result) return; // append first string to the new buffer in case there was no reallocation @@ -8048,7 +8048,7 @@ PUGI__NS_BEGIN size_t length_ = strlength(_buffer); const char_t* data_ = duplicate_string(_buffer, length_, alloc); - if (!data_) return 0; + if (!data_) return PUGIXML_NULL; _buffer = data_; _uses_heap = true; @@ -8257,7 +8257,7 @@ PUGI__NS_BEGIN if (node->value && (node->header & impl::xml_memory_page_value_allocated_or_shared_mask) == 0) return node->value; } - return 0; + return PUGIXML_NULL; } xml_attribute_struct* attr = xnode.attribute().internal_object(); @@ -8270,10 +8270,10 @@ PUGI__NS_BEGIN if ((attr->header & impl::xml_memory_page_value_allocated_or_shared_mask) == 0) return attr->value; } - return 0; + return PUGIXML_NULL; } - return 0; + return PUGIXML_NULL; } struct document_order_comparator @@ -8377,7 +8377,7 @@ PUGI__NS_BEGIN return PUGIXML_TEXT("0"); default: - return 0; + return PUGIXML_NULL; } #else // fallback @@ -8386,7 +8386,7 @@ PUGI__NS_BEGIN if (v == 0) return PUGIXML_TEXT("0"); if (v != v) return PUGIXML_TEXT("NaN"); if (v * 2 == v) return value > 0 ? PUGIXML_TEXT("Infinity") : PUGIXML_TEXT("-Infinity"); - return 0; + return PUGIXML_NULL; #endif } @@ -8551,9 +8551,9 @@ PUGI__NS_BEGIN // parse string #ifdef PUGIXML_WCHAR_MODE - return wcstod(string, 0); + return wcstod(string, PUGIXML_NULL); #else - return strtod(string, 0); + return strtod(string, PUGIXML_NULL); #endif } @@ -8615,7 +8615,7 @@ PUGI__NS_BEGIN { const char_t* pos = find_char(name, ':'); - prefix = pos ? name : 0; + prefix = pos ? name : PUGIXML_NULL; prefix_length = pos ? static_cast(pos - name) : 0; } @@ -8733,7 +8733,7 @@ PUGI__NS_BEGIN unsigned int tc = static_cast(*to); if (fc >= 128 || tc >= 128) - return 0; + return PUGIXML_NULL; // code=128 means "skip character" if (!table[fc]) @@ -8748,7 +8748,7 @@ PUGI__NS_BEGIN table[i] = static_cast(i); void* result = alloc->allocate(sizeof(table)); - if (!result) return 0; + if (!result) return PUGIXML_NULL; memcpy(result, table, sizeof(table)); @@ -8812,7 +8812,7 @@ PUGI__NS_BEGIN struct xpath_variable_string: xpath_variable { - xpath_variable_string(): xpath_variable(xpath_type_string), value(0) + xpath_variable_string(): xpath_variable(xpath_type_string), value(PUGIXML_NULL) { } @@ -8859,11 +8859,11 @@ PUGI__NS_BEGIN template PUGI__FN T* new_xpath_variable(const char_t* name) { size_t length = strlength(name); - if (length == 0) return 0; // empty variable names are invalid + if (length == 0) return PUGIXML_NULL; // empty variable names are invalid // $$ we can't use offsetof(T, name) because T is non-POD, so we just allocate additional length characters void* memory = xml_memory::allocate(sizeof(T) + length * sizeof(char_t)); - if (!memory) return 0; + if (!memory) return PUGIXML_NULL; T* result = new (memory) T(); @@ -8889,7 +8889,7 @@ PUGI__NS_BEGIN return new_xpath_variable(name); default: - return 0; + return PUGIXML_NULL; } } @@ -9042,7 +9042,7 @@ PUGI__NS_BEGIN xpath_node* _eos; public: - xpath_node_set_raw(): _type(xpath_node_set::type_unsorted), _begin(0), _end(0), _eos(0) + xpath_node_set_raw(): _type(xpath_node_set::type_unsorted), _begin(PUGIXML_NULL), _end(PUGIXML_NULL), _eos(PUGIXML_NULL) { } @@ -9234,7 +9234,7 @@ PUGI__NS_BEGIN const char_t* begin; const char_t* end; - xpath_lexer_string(): begin(0), end(0) + xpath_lexer_string(): begin(PUGIXML_NULL), end(PUGIXML_NULL) { } @@ -10421,40 +10421,40 @@ PUGI__NS_BEGIN public: xpath_ast_node(ast_type_t type, xpath_value_type rettype_, const char_t* value): - _type(static_cast(type)), _rettype(static_cast(rettype_)), _axis(0), _test(0), _left(0), _right(0), _next(0) + _type(static_cast(type)), _rettype(static_cast(rettype_)), _axis(0), _test(0), _left(PUGIXML_NULL), _right(PUGIXML_NULL), _next(PUGIXML_NULL) { assert(type == ast_string_constant); _data.string = value; } xpath_ast_node(ast_type_t type, xpath_value_type rettype_, double value): - _type(static_cast(type)), _rettype(static_cast(rettype_)), _axis(0), _test(0), _left(0), _right(0), _next(0) + _type(static_cast(type)), _rettype(static_cast(rettype_)), _axis(0), _test(0), _left(PUGIXML_NULL), _right(PUGIXML_NULL), _next(PUGIXML_NULL) { assert(type == ast_number_constant); _data.number = value; } xpath_ast_node(ast_type_t type, xpath_value_type rettype_, xpath_variable* value): - _type(static_cast(type)), _rettype(static_cast(rettype_)), _axis(0), _test(0), _left(0), _right(0), _next(0) + _type(static_cast(type)), _rettype(static_cast(rettype_)), _axis(0), _test(0), _left(PUGIXML_NULL), _right(PUGIXML_NULL), _next(PUGIXML_NULL) { assert(type == ast_variable); _data.variable = value; } - xpath_ast_node(ast_type_t type, xpath_value_type rettype_, xpath_ast_node* left = 0, xpath_ast_node* right = 0): - _type(static_cast(type)), _rettype(static_cast(rettype_)), _axis(0), _test(0), _left(left), _right(right), _next(0) + xpath_ast_node(ast_type_t type, xpath_value_type rettype_, xpath_ast_node* left = PUGIXML_NULL, xpath_ast_node* right = PUGIXML_NULL): + _type(static_cast(type)), _rettype(static_cast(rettype_)), _axis(0), _test(0), _left(left), _right(right), _next(PUGIXML_NULL) { } xpath_ast_node(ast_type_t type, xpath_ast_node* left, axis_t axis, nodetest_t test, const char_t* contents): - _type(static_cast(type)), _rettype(xpath_type_node_set), _axis(static_cast(axis)), _test(static_cast(test)), _left(left), _right(0), _next(0) + _type(static_cast(type)), _rettype(xpath_type_node_set), _axis(static_cast(axis)), _test(static_cast(test)), _left(left), _right(PUGIXML_NULL), _next(PUGIXML_NULL) { assert(type == ast_step); _data.nodetest = contents; } xpath_ast_node(ast_type_t type, xpath_ast_node* left, xpath_ast_node* right, predicate_t test): - _type(static_cast(type)), _rettype(xpath_type_node_set), _axis(0), _test(static_cast(test)), _left(left), _right(right), _next(0) + _type(static_cast(type)), _rettype(xpath_type_node_set), _axis(0), _test(static_cast(test)), _left(left), _right(right), _next(PUGIXML_NULL) { assert(type == ast_filter || type == ast_predicate); } @@ -10514,7 +10514,7 @@ PUGI__NS_BEGIN xpath_string lr = _left->eval_string(c, stack); xpath_string rr = _right->eval_string(c, stack); - return find_substring(lr.c_str(), rr.c_str()) != 0; + return find_substring(lr.c_str(), rr.c_str()) != PUGIXML_NULL; } case ast_func_boolean: @@ -11323,7 +11323,7 @@ PUGI__NS_BEGIN _result->error = message; _result->offset = _lexer.current_pos() - _query; - return 0; + return PUGIXML_NULL; } xpath_ast_node* error_oom() @@ -11331,7 +11331,7 @@ PUGI__NS_BEGIN assert(_alloc->_error); *_alloc->_error = true; - return 0; + return PUGIXML_NULL; } xpath_ast_node* error_rec() @@ -11347,37 +11347,37 @@ PUGI__NS_BEGIN xpath_ast_node* alloc_node(ast_type_t type, xpath_value_type rettype, const char_t* value) { void* memory = alloc_node(); - return memory ? new (memory) xpath_ast_node(type, rettype, value) : 0; + return memory ? new (memory) xpath_ast_node(type, rettype, value) : PUGIXML_NULL; } xpath_ast_node* alloc_node(ast_type_t type, xpath_value_type rettype, double value) { void* memory = alloc_node(); - return memory ? new (memory) xpath_ast_node(type, rettype, value) : 0; + return memory ? new (memory) xpath_ast_node(type, rettype, value) : PUGIXML_NULL; } xpath_ast_node* alloc_node(ast_type_t type, xpath_value_type rettype, xpath_variable* value) { void* memory = alloc_node(); - return memory ? new (memory) xpath_ast_node(type, rettype, value) : 0; + return memory ? new (memory) xpath_ast_node(type, rettype, value) : PUGIXML_NULL; } - xpath_ast_node* alloc_node(ast_type_t type, xpath_value_type rettype, xpath_ast_node* left = 0, xpath_ast_node* right = 0) + xpath_ast_node* alloc_node(ast_type_t type, xpath_value_type rettype, xpath_ast_node* left = PUGIXML_NULL, xpath_ast_node* right = PUGIXML_NULL) { void* memory = alloc_node(); - return memory ? new (memory) xpath_ast_node(type, rettype, left, right) : 0; + return memory ? new (memory) xpath_ast_node(type, rettype, left, right) : PUGIXML_NULL; } xpath_ast_node* alloc_node(ast_type_t type, xpath_ast_node* left, axis_t axis, nodetest_t test, const char_t* contents) { void* memory = alloc_node(); - return memory ? new (memory) xpath_ast_node(type, left, axis, test, contents) : 0; + return memory ? new (memory) xpath_ast_node(type, left, axis, test, contents) : PUGIXML_NULL; } xpath_ast_node* alloc_node(ast_type_t type, xpath_ast_node* left, xpath_ast_node* right, predicate_t test) { void* memory = alloc_node(); - return memory ? new (memory) xpath_ast_node(type, left, right, test) : 0; + return memory ? new (memory) xpath_ast_node(type, left, right, test) : PUGIXML_NULL; } const char_t* alloc_string(const xpath_lexer_string& value) @@ -11388,7 +11388,7 @@ PUGI__NS_BEGIN size_t length = static_cast(value.end - value.begin); char_t* c = static_cast(_alloc->allocate((length + 1) * sizeof(char_t))); - if (!c) return 0; + if (!c) return PUGIXML_NULL; memcpy(c, value.begin, length * sizeof(char_t)); c[length] = 0; @@ -11631,7 +11631,7 @@ PUGI__NS_BEGIN if (!_variables) return error("Unknown variable: variable set is not provided"); - xpath_variable* var = 0; + xpath_variable* var = PUGIXML_NULL; if (!get_variable_scratch(_scratch, _variables, name.begin, name.end, &var)) return error_oom(); @@ -11648,7 +11648,7 @@ PUGI__NS_BEGIN _lexer.next(); xpath_ast_node* n = parse_expression(); - if (!n) return 0; + if (!n) return PUGIXML_NULL; if (_lexer.current() != lex_close_brace) return error("Expected ')' to match an opening '('"); @@ -11661,7 +11661,7 @@ PUGI__NS_BEGIN case lex_quoted_string: { const char_t* value = alloc_string(_lexer.contents()); - if (!value) return 0; + if (!value) return PUGIXML_NULL; _lexer.next(); @@ -11682,13 +11682,13 @@ PUGI__NS_BEGIN case lex_string: { - xpath_ast_node* args[2] = {0}; + xpath_ast_node* args[2] = {PUGIXML_NULL}; size_t argc = 0; xpath_lexer_string function = _lexer.contents(); _lexer.next(); - xpath_ast_node* last_arg = 0; + xpath_ast_node* last_arg = PUGIXML_NULL; if (_lexer.current() != lex_open_brace) return error("Unrecognized function call"); @@ -11709,7 +11709,7 @@ PUGI__NS_BEGIN return error_rec(); xpath_ast_node* n = parse_expression(); - if (!n) return 0; + if (!n) return PUGIXML_NULL; if (argc < 2) args[argc] = n; else last_arg->set_next(n); @@ -11736,7 +11736,7 @@ PUGI__NS_BEGIN xpath_ast_node* parse_filter_expression() { xpath_ast_node* n = parse_primary_expression(); - if (!n) return 0; + if (!n) return PUGIXML_NULL; size_t old_depth = _depth; @@ -11751,10 +11751,10 @@ PUGI__NS_BEGIN return error("Predicate has to be applied to node set"); xpath_ast_node* expr = parse_expression(); - if (!expr) return 0; + if (!expr) return PUGIXML_NULL; n = alloc_node(ast_filter, n, expr, predicate_default); - if (!n) return 0; + if (!n) return PUGIXML_NULL; if (_lexer.current() != lex_close_square_brace) return error("Expected ']' to match an opening '['"); @@ -11794,7 +11794,7 @@ PUGI__NS_BEGIN if (_lexer.current() == lex_open_square_brace) return error("Predicates are not allowed after an abbreviated step"); - return alloc_node(ast_step, set, axis_self, nodetest_type_node, 0); + return alloc_node(ast_step, set, axis_self, nodetest_type_node, PUGIXML_NULL); } else if (_lexer.current() == lex_double_dot) { @@ -11803,7 +11803,7 @@ PUGI__NS_BEGIN if (_lexer.current() == lex_open_square_brace) return error("Predicates are not allowed after an abbreviated step"); - return alloc_node(ast_step, set, axis_parent, nodetest_type_node, 0); + return alloc_node(ast_step, set, axis_parent, nodetest_type_node, PUGIXML_NULL); } nodetest_t nt_type = nodetest_none; @@ -11910,14 +11910,14 @@ PUGI__NS_BEGIN } const char_t* nt_name_copy = alloc_string(nt_name); - if (!nt_name_copy) return 0; + if (!nt_name_copy) return PUGIXML_NULL; xpath_ast_node* n = alloc_node(ast_step, set, axis, nt_type, nt_name_copy); - if (!n) return 0; + if (!n) return PUGIXML_NULL; size_t old_depth = _depth; - xpath_ast_node* last = 0; + xpath_ast_node* last = PUGIXML_NULL; while (_lexer.current() == lex_open_square_brace) { @@ -11927,10 +11927,10 @@ PUGI__NS_BEGIN return error_rec(); xpath_ast_node* expr = parse_expression(); - if (!expr) return 0; + if (!expr) return PUGIXML_NULL; - xpath_ast_node* pred = alloc_node(ast_predicate, 0, expr, predicate_default); - if (!pred) return 0; + xpath_ast_node* pred = alloc_node(ast_predicate, PUGIXML_NULL, expr, predicate_default); + if (!pred) return PUGIXML_NULL; if (_lexer.current() != lex_close_square_brace) return error("Expected ']' to match an opening '['"); @@ -11951,7 +11951,7 @@ PUGI__NS_BEGIN xpath_ast_node* parse_relative_location_path(xpath_ast_node* set) { xpath_ast_node* n = parse_step(set); - if (!n) return 0; + if (!n) return PUGIXML_NULL; size_t old_depth = _depth; @@ -11962,8 +11962,8 @@ PUGI__NS_BEGIN if (l == lex_double_slash) { - n = alloc_node(ast_step, n, axis_descendant_or_self, nodetest_type_node, 0); - if (!n) return 0; + n = alloc_node(ast_step, n, axis_descendant_or_self, nodetest_type_node, PUGIXML_NULL); + if (!n) return PUGIXML_NULL; ++_depth; } @@ -11972,7 +11972,7 @@ PUGI__NS_BEGIN return error_rec(); n = parse_step(n); - if (!n) return 0; + if (!n) return PUGIXML_NULL; } _depth = old_depth; @@ -11989,7 +11989,7 @@ PUGI__NS_BEGIN _lexer.next(); xpath_ast_node* n = alloc_node(ast_step_root, xpath_type_node_set); - if (!n) return 0; + if (!n) return PUGIXML_NULL; // relative location path can start from axis_attribute, dot, double_dot, multiply and string lexemes; any other lexeme means standalone root path lexeme_t l = _lexer.current(); @@ -12004,16 +12004,16 @@ PUGI__NS_BEGIN _lexer.next(); xpath_ast_node* n = alloc_node(ast_step_root, xpath_type_node_set); - if (!n) return 0; + if (!n) return PUGIXML_NULL; - n = alloc_node(ast_step, n, axis_descendant_or_self, nodetest_type_node, 0); - if (!n) return 0; + n = alloc_node(ast_step, n, axis_descendant_or_self, nodetest_type_node, PUGIXML_NULL); + if (!n) return PUGIXML_NULL; return parse_relative_location_path(n); } // else clause moved outside of if because of bogus warning 'control may reach end of non-void function being inlined' in gcc 4.0.1 - return parse_relative_location_path(0); + return parse_relative_location_path(PUGIXML_NULL); } // PathExpr ::= LocationPath @@ -12050,7 +12050,7 @@ PUGI__NS_BEGIN } xpath_ast_node* n = parse_filter_expression(); - if (!n) return 0; + if (!n) return PUGIXML_NULL; if (_lexer.current() == lex_slash || _lexer.current() == lex_double_slash) { @@ -12062,8 +12062,8 @@ PUGI__NS_BEGIN if (n->rettype() != xpath_type_node_set) return error("Step has to be applied to node set"); - n = alloc_node(ast_step, n, axis_descendant_or_self, nodetest_type_node, 0); - if (!n) return 0; + n = alloc_node(ast_step, n, axis_descendant_or_self, nodetest_type_node, PUGIXML_NULL); + if (!n) return PUGIXML_NULL; } // select from location path @@ -12078,7 +12078,7 @@ PUGI__NS_BEGIN // precedence 7+ - only parses union expressions xpath_ast_node* n = parse_expression(7); - if (!n) return 0; + if (!n) return PUGIXML_NULL; return alloc_node(ast_op_negate, xpath_type_number, n); } @@ -12166,14 +12166,14 @@ PUGI__NS_BEGIN return error_rec(); xpath_ast_node* rhs = parse_path_or_unary_expression(); - if (!rhs) return 0; + if (!rhs) return PUGIXML_NULL; binary_op_t nextop = binary_op_t::parse(_lexer); while (nextop.asttype != ast_unknown && nextop.precedence > op.precedence) { rhs = parse_expression_rec(rhs, nextop.precedence); - if (!rhs) return 0; + if (!rhs) return PUGIXML_NULL; nextop = binary_op_t::parse(_lexer); } @@ -12182,7 +12182,7 @@ PUGI__NS_BEGIN return error("Union operator has to be applied to node sets"); lhs = alloc_node(op.asttype, op.rettype, lhs, rhs); - if (!lhs) return 0; + if (!lhs) return PUGIXML_NULL; op = binary_op_t::parse(_lexer); } @@ -12216,7 +12216,7 @@ PUGI__NS_BEGIN return error_rec(); xpath_ast_node* n = parse_path_or_unary_expression(); - if (!n) return 0; + if (!n) return PUGIXML_NULL; n = parse_expression_rec(n, limit); @@ -12232,7 +12232,7 @@ PUGI__NS_BEGIN xpath_ast_node* parse() { xpath_ast_node* n = parse_expression(); - if (!n) return 0; + if (!n) return PUGIXML_NULL; assert(_depth == 0); @@ -12256,7 +12256,7 @@ PUGI__NS_BEGIN static xpath_query_impl* create() { void* memory = xml_memory::allocate(sizeof(xpath_query_impl)); - if (!memory) return 0; + if (!memory) return PUGIXML_NULL; return new (memory) xpath_query_impl(); } @@ -12270,9 +12270,9 @@ PUGI__NS_BEGIN xml_memory::deallocate(impl); } - xpath_query_impl(): root(0), alloc(&block, &oom), oom(false) + xpath_query_impl(): root(PUGIXML_NULL), alloc(&block, &oom), oom(false) { - block.next = 0; + block.next = PUGIXML_NULL; block.capacity = sizeof(block.data); } @@ -12284,12 +12284,12 @@ PUGI__NS_BEGIN PUGI__FN impl::xpath_ast_node* evaluate_node_set_prepare(xpath_query_impl* impl) { - if (!impl) return 0; + if (!impl) return PUGIXML_NULL; if (impl->root->rettype() != xpath_type_node_set) { #ifdef PUGIXML_NO_EXCEPTIONS - return 0; + return PUGIXML_NULL; #else xpath_parse_result res; res.error = "Expression does not evaluate to node set"; @@ -12354,7 +12354,7 @@ namespace pugi PUGI__FN xpath_node::operator xpath_node::unspecified_bool_type() const { - return (_node || _attribute) ? unspecified_bool_xpath_node : 0; + return (_node || _attribute) ? unspecified_bool_xpath_node : PUGIXML_NULL; } PUGI__FN bool xpath_node::operator!() const @@ -12524,7 +12524,7 @@ namespace pugi PUGI__FN xpath_parse_result::operator bool() const { - return error == 0; + return error == PUGIXML_NULL; } PUGI__FN const char* xpath_parse_result::description() const @@ -12532,7 +12532,7 @@ namespace pugi return error ? error : "No error"; } - PUGI__FN xpath_variable::xpath_variable(xpath_value_type type_): _type(type_), _next(0) + PUGI__FN xpath_variable::xpath_variable(xpath_value_type type_): _type(type_), _next(PUGIXML_NULL) { } @@ -12554,7 +12554,7 @@ namespace pugi default: assert(false && "Invalid variable type"); // unreachable - return 0; + return PUGIXML_NULL; } } @@ -12575,7 +12575,7 @@ namespace pugi PUGI__FN const char_t* xpath_variable::get_string() const { - const char_t* value = (_type == xpath_type_string) ? static_cast(this)->value : 0; + const char_t* value = (_type == xpath_type_string) ? static_cast(this)->value : PUGIXML_NULL; return value ? value : PUGIXML_TEXT(""); } @@ -12632,7 +12632,7 @@ namespace pugi PUGI__FN xpath_variable_set::xpath_variable_set() { for (size_t i = 0; i < sizeof(_data) / sizeof(_data[0]); ++i) - _data[i] = 0; + _data[i] = PUGIXML_NULL; } PUGI__FN xpath_variable_set::~xpath_variable_set() @@ -12644,7 +12644,7 @@ namespace pugi PUGI__FN xpath_variable_set::xpath_variable_set(const xpath_variable_set& rhs) { for (size_t i = 0; i < sizeof(_data) / sizeof(_data[0]); ++i) - _data[i] = 0; + _data[i] = PUGIXML_NULL; _assign(rhs); } @@ -12664,7 +12664,7 @@ namespace pugi for (size_t i = 0; i < sizeof(_data) / sizeof(_data[0]); ++i) { _data[i] = rhs._data[i]; - rhs._data[i] = 0; + rhs._data[i] = PUGIXML_NULL; } } @@ -12675,7 +12675,7 @@ namespace pugi _destroy(_data[i]); _data[i] = rhs._data[i]; - rhs._data[i] = 0; + rhs._data[i] = PUGIXML_NULL; } return *this; @@ -12714,12 +12714,12 @@ namespace pugi if (impl::strequal(var->name(), name)) return var; - return 0; + return PUGIXML_NULL; } PUGI__FN bool xpath_variable_set::_clone(xpath_variable* var, xpath_variable** out_result) { - xpath_variable* last = 0; + xpath_variable* last = PUGIXML_NULL; while (var) { @@ -12764,7 +12764,7 @@ namespace pugi // look for existing variable for (xpath_variable* var = _data[hash]; var; var = var->_next) if (impl::strequal(var->name(), name)) - return var->type() == type ? var : 0; + return var->type() == type ? var : PUGIXML_NULL; // add new variable xpath_variable* result = impl::new_xpath_variable(type, name); @@ -12813,7 +12813,7 @@ namespace pugi return _find(name); } - PUGI__FN xpath_query::xpath_query(const char_t* query, xpath_variable_set* variables): _impl(0) + PUGI__FN xpath_query::xpath_query(const char_t* query, xpath_variable_set* variables): _impl(PUGIXML_NULL) { impl::xpath_query_impl* qimpl = impl::xpath_query_impl::create(); @@ -12837,7 +12837,7 @@ namespace pugi qimpl->root->optimize(&qimpl->alloc); _impl = impl.release(); - _result.error = 0; + _result.error = PUGIXML_NULL; } else { @@ -12851,7 +12851,7 @@ namespace pugi } } - PUGI__FN xpath_query::xpath_query(): _impl(0) + PUGI__FN xpath_query::xpath_query(): _impl(PUGIXML_NULL) { } @@ -12866,7 +12866,7 @@ namespace pugi { _impl = rhs._impl; _result = rhs._result; - rhs._impl = 0; + rhs._impl = PUGIXML_NULL; rhs._result = xpath_parse_result(); } @@ -12879,7 +12879,7 @@ namespace pugi _impl = rhs._impl; _result = rhs._result; - rhs._impl = 0; + rhs._impl = PUGIXML_NULL; rhs._result = xpath_parse_result(); return *this; @@ -13043,7 +13043,7 @@ namespace pugi PUGI__FN xpath_query::operator xpath_query::unspecified_bool_type() const { - return _impl ? unspecified_bool_xpath_query : 0; + return _impl ? unspecified_bool_xpath_query : PUGIXML_NULL; } PUGI__FN bool xpath_query::operator!() const diff --git a/tests/allocator.cpp b/tests/allocator.cpp index 588e456..6e5c3f0 100644 --- a/tests/allocator.cpp +++ b/tests/allocator.cpp @@ -15,6 +15,15 @@ # 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 #if defined(_WIN32) || defined(_WIN64) # ifdef __MWERKS__ @@ -93,7 +102,6 @@ namespace void* allocate_page_aligned(size_t size) { void* result = malloc(size + page_size); - return reinterpret_cast(align_to_page(reinterpret_cast(result))); } @@ -102,7 +110,7 @@ namespace size_t aligned_size = align_to_page(size); void* ptr = allocate_page_aligned(aligned_size + page_size); - if (!ptr) return 0; + if (!ptr) return PUGIXML_NULL; char* end = static_cast(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* result = allocate(size + memory_alignment); - if (!result) return 0; + if (!result) return PUGIXML_NULL; memcpy(result, &size, sizeof(size_t)); diff --git a/tests/main.cpp b/tests/main.cpp index 352b58b..856df1c 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -18,7 +18,7 @@ # include #endif -test_runner* test_runner::_tests = 0; +test_runner* test_runner::_tests = PUGIXML_NULL; size_t test_runner::_memory_fail_threshold = 0; bool test_runner::_memory_fail_triggered = false; jmp_buf test_runner::_failure_buffer; @@ -36,12 +36,12 @@ static void* custom_allocate(size_t size) g_memory_fail_triggered = true; test_runner::_memory_fail_triggered = true; - return 0; + return PUGIXML_NULL; } else { void* ptr = memory_allocate(size); - if (!ptr) return 0; + if (!ptr) return PUGIXML_NULL; g_memory_total_size += memory_size(ptr); g_memory_total_count++; @@ -183,7 +183,7 @@ int main(int, char** argv) unsigned int total = 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) { diff --git a/tests/test.cpp b/tests/test.cpp index a97116e..4a69a85 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -164,7 +164,7 @@ xpath_node_set_tester::xpath_node_set_tester(const pugi::xpath_node_set& set, co if (result.empty()) { - document_order = 0; + document_order = PUGIXML_NULL; document_size = 0; } else diff --git a/tests/test.hpp b/tests/test.hpp index dd14af6..1ede950 100644 --- a/tests/test.hpp +++ b/tests/test.hpp @@ -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_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_BOOLEAN(node, query, expected) CHECK_XPATH_BOOLEAN_VAR(node, query, 0, expected) -#define CHECK_XPATH_NUMBER(node, query, expected) CHECK_XPATH_NUMBER_VAR(node, query, 0, expected) -#define CHECK_XPATH_NUMBER_NAN(node, query) CHECK_XPATH_NUMBER_NAN_VAR(node, query, 0) -#define CHECK_XPATH_NODESET(node, query) CHECK_XPATH_NODESET_VAR(node, query, 0) -#define CHECK_XPATH_FAIL(query) CHECK_XPATH_FAIL_VAR(query, 0) +#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, PUGIXML_NULL, 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, PUGIXML_NULL) +#define CHECK_XPATH_NODESET(node, query) CHECK_XPATH_NODESET_VAR(node, query, PUGIXML_NULL) +#define CHECK_XPATH_FAIL(query) CHECK_XPATH_FAIL_VAR(query, PUGIXML_NULL) #endif #ifdef PUGIXML_NO_EXCEPTIONS diff --git a/tests/test_document.cpp b/tests/test_document.cpp index 2e2904d..0d98835 100644 --- a/tests/test_document.cpp +++ b/tests/test_document.cpp @@ -889,7 +889,7 @@ TEST(document_parse_result_description) { result.status = static_cast(i); - CHECK(result.description() != 0); + CHECK(result.description() != PUGIXML_NULL); CHECK(result.description()[0] != 0); } } @@ -1098,11 +1098,11 @@ TEST(document_contents_preserve) { file_data_t files[] = { - {"tests/data/utftest_utf16_be_clean.xml", encoding_utf16_be, 0, 0}, - {"tests/data/utftest_utf16_le_clean.xml", encoding_utf16_le, 0, 0}, - {"tests/data/utftest_utf32_be_clean.xml", encoding_utf32_be, 0, 0}, - {"tests/data/utftest_utf32_le_clean.xml", encoding_utf32_le, 0, 0}, - {"tests/data/utftest_utf8_clean.xml", encoding_utf8, 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, PUGIXML_NULL, 0}, + {"tests/data/utftest_utf32_be_clean.xml", encoding_utf32_be, PUGIXML_NULL, 0}, + {"tests/data/utftest_utf32_le_clean.xml", encoding_utf32_le, PUGIXML_NULL, 0}, + {"tests/data/utftest_utf8_clean.xml", encoding_utf8, PUGIXML_NULL, 0} }; // load files in memory @@ -1136,8 +1136,8 @@ TEST(document_contents_preserve_latin1) { file_data_t files[] = { - {"tests/data/latintest_utf8.xml", encoding_utf8, 0, 0}, - {"tests/data/latintest_latin1.xml", encoding_latin1, 0, 0} + {"tests/data/latintest_utf8.xml", encoding_utf8, PUGIXML_NULL, 0}, + {"tests/data/latintest_latin1.xml", encoding_latin1, PUGIXML_NULL, 0} }; // load files in memory @@ -1239,15 +1239,15 @@ TEST(document_load_buffer_empty) xml_document doc; 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(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); 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; 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(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); 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; - CHECK(doc.load_buffer(0, 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).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_own(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(PUGIXML_NULL, 12).status == status_io_error && !doc.first_child()); } 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 + 3, 1).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; } @@ -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 + 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(0, 0, parse_fragment) && !doc.first_child()); + CHECK(doc.load_buffer(PUGIXML_NULL, 0, parse_fragment) && !doc.first_child()); 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 + 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(0, 0).status == status_no_document_element); + CHECK(doc.load_buffer_inplace(PUGIXML_NULL, 0).status == status_no_document_element); delete[] data; } @@ -1597,12 +1597,12 @@ TEST(document_convert_out_of_memory) { file_data_t files[] = { - {"tests/data/utftest_utf16_be_clean.xml", encoding_utf16_be, 0, 0}, - {"tests/data/utftest_utf16_le_clean.xml", encoding_utf16_le, 0, 0}, - {"tests/data/utftest_utf32_be_clean.xml", encoding_utf32_be, 0, 0}, - {"tests/data/utftest_utf32_le_clean.xml", encoding_utf32_le, 0, 0}, - {"tests/data/utftest_utf8_clean.xml", encoding_utf8, 0, 0}, - {"tests/data/latintest_latin1.xml", encoding_latin1, 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, PUGIXML_NULL, 0}, + {"tests/data/utftest_utf32_be_clean.xml", encoding_utf32_be, PUGIXML_NULL, 0}, + {"tests/data/utftest_utf32_le_clean.xml", encoding_utf32_le, PUGIXML_NULL, 0}, + {"tests/data/utftest_utf8_clean.xml", encoding_utf8, PUGIXML_NULL, 0}, + {"tests/data/latintest_latin1.xml", encoding_latin1, PUGIXML_NULL, 0} }; // load files in memory diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp index 3451f19..f28e058 100644 --- a/tests/test_dom_modify.cpp +++ b/tests/test_dom_modify.cpp @@ -1345,8 +1345,8 @@ TEST_XML(dom_node_append_buffer_empty, "") 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, 0).status == status_no_document_element); - CHECK(node.append_buffer(0, 0, parse_fragment).status == status_ok); + CHECK(node.append_buffer(PUGIXML_NULL, 0).status == status_no_document_element); + CHECK(node.append_buffer(PUGIXML_NULL, 0, parse_fragment).status == status_ok); CHECK_NODE(doc, STR("")); } diff --git a/tests/test_dom_traverse.cpp b/tests/test_dom_traverse.cpp index 0c1e3af..d7af87b 100644 --- a/tests/test_dom_traverse.cpp +++ b/tests/test_dom_traverse.cpp @@ -981,14 +981,14 @@ TEST_XML(dom_internal_object, "value") xml_attribute attr = node.first_attribute(); xml_node value = node.first_child(); - CHECK(xml_node().internal_object() == 0); - CHECK(xml_attribute().internal_object() == 0); + CHECK(xml_node().internal_object() == PUGIXML_NULL); + CHECK(xml_attribute().internal_object() == PUGIXML_NULL); - CHECK(node.internal_object() != 0); - CHECK(value.internal_object() != 0); + CHECK(node.internal_object() != PUGIXML_NULL); + CHECK(value.internal_object() != PUGIXML_NULL); CHECK(node.internal_object() != value.internal_object()); - CHECK(attr.internal_object() != 0); + CHECK(attr.internal_object() != PUGIXML_NULL); xml_node node_copy = node; CHECK(node_copy.internal_object() == node.internal_object()); @@ -1100,24 +1100,24 @@ TEST_XML(dom_unspecified_bool_coverage, "text") xml_node node = doc.first_child(); CHECK(node); - static_cast(node)(0); + static_cast(node)(PUGIXML_NULL); CHECK(node.first_attribute()); - static_cast(node.first_attribute())(0); + static_cast(node.first_attribute())(PUGIXML_NULL); CHECK(node.text()); - static_cast(node.text())(0); + static_cast(node.text())(PUGIXML_NULL); #ifndef PUGIXML_NO_XPATH xpath_query q(STR("/node")); CHECK(q); - static_cast(q)(0); + static_cast(q)(PUGIXML_NULL); xpath_node qn = q.evaluate_node(doc); CHECK(qn); - static_cast(qn)(0); + static_cast(qn)(PUGIXML_NULL); #endif } diff --git a/tests/test_xpath.cpp b/tests/test_xpath.cpp index 0fbe392..6e18af5 100644 --- a/tests/test_xpath.cpp +++ b/tests/test_xpath.cpp @@ -416,7 +416,7 @@ TEST_XML(xpath_out_of_memory_evaluate, "") CHECK_ALLOC_FAIL(CHECK(q.evaluate_string(doc).empty())); #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_set(doc).empty())); } @@ -432,7 +432,7 @@ TEST(xpath_out_of_memory_evaluate_concat) 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) @@ -448,7 +448,7 @@ TEST(xpath_out_of_memory_evaluate_concat_list) 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) @@ -462,7 +462,7 @@ TEST(xpath_out_of_memory_evaluate_substring) 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, "") @@ -516,7 +516,7 @@ TEST_XML(xpath_out_of_memory_evaluate_normalize_space_0, " 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())")); - 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, " 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 ") @@ -525,7 +525,7 @@ TEST_XML(xpath_out_of_memory_evaluate_normalize_space_1, " 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))")); - 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, " 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 ") @@ -534,7 +534,7 @@ TEST_XML(xpath_out_of_memory_evaluate_translate, " 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'))")); - 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, " 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 ") @@ -543,7 +543,7 @@ TEST_XML(xpath_out_of_memory_evaluate_translate_table, " 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'))")); - 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) @@ -563,7 +563,7 @@ TEST(xpath_out_of_memory_evaluate_string_append) xpath_query q(STR("string(n)")); 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) @@ -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); - 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) @@ -587,7 +587,7 @@ TEST(xpath_memory_concat_massive) node.append_child(STR("c")).text().set(i % 10); 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); } diff --git a/tests/test_xpath_api.cpp b/tests/test_xpath_api.cpp index 8687e35..b426e3d 100644 --- a/tests/test_xpath_api.cpp +++ b/tests/test_xpath_api.cpp @@ -198,7 +198,7 @@ TEST_XML(xpath_api_evaluate_fail, "") CHECK(q.evaluate_boolean(doc) == false); 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 CHECK(q.evaluate_string(doc).empty()); @@ -277,7 +277,7 @@ TEST(xpath_api_evaluate_string) // test for empty buffer std::basic_string 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(0, 0, xml_node()) == 11); + CHECK(q.evaluate_string(PUGIXML_NULL, 0, xml_node()) == 11); } TEST(xpath_api_return_type) @@ -315,7 +315,7 @@ TEST(xpath_api_query_result) xpath_query q(STR("node")); CHECK(q.result()); - CHECK(q.result().error == 0); + CHECK(q.result().error == PUGIXML_NULL); CHECK(q.result().offset == 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(); 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.offset == 13); diff --git a/tests/test_xpath_parse.cpp b/tests/test_xpath_parse.cpp index bfa59ff..e30ea4c 100644 --- a/tests/test_xpath_parse.cpp +++ b/tests/test_xpath_parse.cpp @@ -332,7 +332,7 @@ TEST(xpath_parse_result_default) xpath_parse_result result; CHECK(!result); - CHECK(result.error != 0); + CHECK(result.error != PUGIXML_NULL); CHECK(result.offset == 0); } diff --git a/tests/test_xpath_variables.cpp b/tests/test_xpath_variables.cpp index 1a1fc19..09388fc 100644 --- a/tests/test_xpath_variables.cpp +++ b/tests/test_xpath_variables.cpp @@ -135,15 +135,15 @@ TEST(xpath_variables_set_operations) 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_node_set) == 0); + CHECK(set.add(STR("var2"), xpath_type_node_set) == PUGIXML_NULL); CHECK(set.get(STR("var1")) == v1); CHECK(set.get(STR("var2")) == v2); - CHECK(set.get(STR("var")) == 0); - CHECK(set.get(STR("var11")) == 0); + CHECK(set.get(STR("var")) == PUGIXML_NULL); + CHECK(set.get(STR("var11")) == PUGIXML_NULL); CHECK(static_cast(set).get(STR("var1")) == v1); - CHECK(static_cast(set).get(STR("var3")) == 0); + CHECK(static_cast(set).get(STR("var3")) == PUGIXML_NULL); } TEST_XML(xpath_variables_set_operations_set, "") @@ -179,7 +179,7 @@ TEST(xpath_variables_set_out_of_memory) 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(!var); }