From bc288124f3620915a96301681267bb199d7a0dca Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 27 Jul 2020 14:50:23 -0700 Subject: [PATCH] [clang-tidy] replace 0/nullptr with macro Found with modernize-use-nullptr Signed-off-by: Rosen Penev --- src/pugixml.cpp | 344 ++++++++++++++++++++++++------------------------ 1 file changed, 172 insertions(+), 172 deletions(-) diff --git a/src/pugixml.cpp b/src/pugixml.cpp index c4e6dbc..db0dda0 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -278,7 +278,7 @@ PUGI__NS_BEGIN T* release() { T* result = data; - data = 0; + data = PUGIXML_NULL; return result; } }; @@ -461,9 +461,9 @@ 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; @@ -520,7 +520,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); @@ -603,7 +603,7 @@ PUGI__NS_BEGIN if (page->freed_size == page->busy_size) { - if (page->next == 0) + if (page->next == PUGIXML_NULL) { assert(_root == page); @@ -650,7 +650,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); @@ -712,7 +712,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) { @@ -1094,7 +1094,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); } @@ -1110,7 +1110,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); } @@ -1141,7 +1141,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) { } @@ -1175,7 +1175,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); } @@ -1184,7 +1184,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); } @@ -1316,9 +1316,9 @@ PUGI__NS_BEGIN else parent->first_child = node->next_sibling; - 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) @@ -1392,16 +1392,16 @@ PUGI__NS_BEGIN else node->first_attribute = attr->next_attribute; - 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); @@ -1410,10 +1410,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); @@ -1995,7 +1995,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)) @@ -2407,7 +2407,7 @@ PUGI__NS_BEGIN char_t* end; size_t size; - gap(): end(0), size(0) + gap(): end(PUGIXML_NULL), size(0) { } @@ -2619,7 +2619,7 @@ PUGI__NS_BEGIN } else if (*s == 0) { - return 0; + return PUGIXML_NULL; } else ++s; } @@ -2647,7 +2647,7 @@ PUGI__NS_BEGIN } else if (*s == 0) { - return 0; + return PUGIXML_NULL; } else ++s; } @@ -2720,7 +2720,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 } } @@ -2774,7 +2774,7 @@ PUGI__NS_BEGIN } else if (!*s) { - return 0; + return PUGIXML_NULL; } else ++s; } @@ -2810,7 +2810,7 @@ PUGI__NS_BEGIN } else if (!*s) { - return 0; + return PUGIXML_NULL; } else ++s; } @@ -2842,7 +2842,7 @@ PUGI__NS_BEGIN } else if (!*s) { - return 0; + return PUGIXML_NULL; } else ++s; } @@ -2868,7 +2868,7 @@ PUGI__NS_BEGIN } else if (!*s) { - return 0; + return PUGIXML_NULL; } else ++s; } @@ -2897,7 +2897,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 } } @@ -2916,7 +2916,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) { } @@ -3510,7 +3510,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)); @@ -4427,7 +4427,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); @@ -4481,7 +4481,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); @@ -4592,7 +4592,7 @@ PUGI__NS_BEGIN #ifdef PUGIXML_WCHAR_MODE return wcstod(value, 0); #else - return strtod(value, 0); + return strtod(value, PUGIXML_NULL); #endif } @@ -4601,7 +4601,7 @@ PUGI__NS_BEGIN #ifdef PUGIXML_WCHAR_MODE return static_cast(wcstod(value, 0)); #else - return static_cast(strtod(value, 0)); + return static_cast(strtod(value, PUGIXML_NULL)); #endif } @@ -4706,7 +4706,7 @@ PUGI__NS_BEGIN xml_encoding buffer_encoding = impl::get_buffer_encoding(encoding, contents, size); // get private buffer - char_t* buffer = 0; + char_t* buffer = PUGIXML_NULL; size_t length = 0; // coverity[var_deref_model] @@ -4835,7 +4835,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(); } @@ -4853,7 +4853,7 @@ PUGI__NS_BEGIN } } - xml_stream_chunk(): next(0), size(0) + xml_stream_chunk(): next(PUGIXML_NULL), size(0) { } @@ -4865,11 +4865,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()) { @@ -4955,7 +4955,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; @@ -5000,7 +5000,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); @@ -5015,7 +5015,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}; @@ -5058,7 +5058,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() @@ -5081,11 +5081,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) { } @@ -5129,7 +5129,7 @@ namespace pugi return true; } - PUGI__FN xml_attribute::xml_attribute(): _attr(0) + PUGI__FN xml_attribute::xml_attribute(): _attr(PUGIXML_NULL) { } @@ -5143,7 +5143,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 @@ -5425,7 +5425,7 @@ namespace pugi } #endif - PUGI__FN xml_node::xml_node(): _root(0) + PUGI__FN xml_node::xml_node(): _root(PUGIXML_NULL) { } @@ -5439,7 +5439,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 @@ -5449,22 +5449,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 @@ -5474,7 +5474,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 @@ -6113,7 +6113,7 @@ namespace pugi attr = next; } - _root->first_attribute = 0; + _root->first_attribute = PUGIXML_NULL; return true; } @@ -6152,7 +6152,7 @@ namespace pugi cur = next; } - _root->first_child = 0; + _root->first_child = PUGIXML_NULL; return true; } @@ -6169,7 +6169,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; @@ -6182,7 +6182,7 @@ 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; @@ -6302,7 +6302,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) { @@ -6438,7 +6438,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() @@ -6449,7 +6449,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) { } @@ -6459,7 +6459,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 @@ -6469,7 +6469,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 @@ -6824,7 +6824,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) { } @@ -6934,7 +6934,7 @@ namespace pugi } } - PUGI__FN xml_document::xml_document(): _buffer(0) + PUGI__FN xml_document::xml_document(): _buffer(PUGIXML_NULL) { _create(); } @@ -6945,7 +6945,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); @@ -7027,7 +7027,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) @@ -7055,7 +7055,7 @@ namespace pugi static_cast(_root)->hash.clear(); #endif - _root = 0; + _root = PUGIXML_NULL; } #ifdef PUGIXML_HAS_MOVE @@ -7128,7 +7128,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 @@ -7165,7 +7165,7 @@ namespace pugi // reset other document new (other) impl::xml_document_struct(PUGI__GETPAGE(other)); - rhs._buffer = 0; + rhs._buffer = PUGIXML_NULL; } #endif @@ -7592,7 +7592,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; @@ -7640,7 +7640,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) { } @@ -7668,7 +7668,7 @@ PUGI__NS_BEGIN if (!block) { if (_error) *_error = true; - return 0; + return PUGIXML_NULL; } block->next = _root; @@ -7688,7 +7688,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) @@ -7699,7 +7699,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) @@ -7794,7 +7794,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; @@ -7820,7 +7820,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; @@ -7880,7 +7880,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 @@ -7915,7 +7915,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; @@ -8124,7 +8124,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(); @@ -8137,10 +8137,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 @@ -8253,7 +8253,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 } @@ -8420,7 +8420,7 @@ PUGI__NS_BEGIN #ifdef PUGIXML_WCHAR_MODE return wcstod(string, 0); #else - return strtod(string, 0); + return strtod(string, PUGIXML_NULL); #endif } @@ -8482,7 +8482,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; } @@ -8600,7 +8600,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]) @@ -8615,7 +8615,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)); @@ -8679,7 +8679,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) { } @@ -8726,11 +8726,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(); @@ -8756,7 +8756,7 @@ PUGI__NS_BEGIN return new_xpath_variable(name); default: - return 0; + return PUGIXML_NULL; } } @@ -8909,7 +8909,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) { } @@ -9101,7 +9101,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) { } @@ -10288,40 +10288,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); } @@ -10381,7 +10381,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: @@ -11190,7 +11190,7 @@ PUGI__NS_BEGIN _result->error = message; _result->offset = _lexer.current_pos() - _query; - return 0; + return PUGIXML_NULL; } xpath_ast_node* error_oom() @@ -11198,7 +11198,7 @@ PUGI__NS_BEGIN assert(_alloc->_error); *_alloc->_error = true; - return 0; + return PUGIXML_NULL; } xpath_ast_node* error_rec() @@ -11214,37 +11214,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) @@ -11255,7 +11255,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; @@ -11498,7 +11498,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(); @@ -11515,7 +11515,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 '('"); @@ -11528,7 +11528,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(); @@ -11549,13 +11549,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"); @@ -11576,7 +11576,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); @@ -11603,7 +11603,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; @@ -11618,10 +11618,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 '['"); @@ -11661,7 +11661,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) { @@ -11670,7 +11670,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; @@ -11777,14 +11777,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) { @@ -11794,10 +11794,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 '['"); @@ -11818,7 +11818,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; @@ -11829,7 +11829,7 @@ PUGI__NS_BEGIN if (l == lex_double_slash) { - n = alloc_node(ast_step, n, axis_descendant_or_self, nodetest_type_node, 0); + n = alloc_node(ast_step, n, axis_descendant_or_self, nodetest_type_node, PUGIXML_NULL); if (!n) return 0; ++_depth; @@ -11839,7 +11839,7 @@ PUGI__NS_BEGIN return error_rec(); n = parse_step(n); - if (!n) return 0; + if (!n) return PUGIXML_NULL; } _depth = old_depth; @@ -11856,7 +11856,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(); @@ -11871,16 +11871,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 @@ -11917,7 +11917,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) { @@ -11929,8 +11929,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 @@ -11945,7 +11945,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); } @@ -12033,14 +12033,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); } @@ -12049,7 +12049,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); } @@ -12083,7 +12083,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); @@ -12099,7 +12099,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); @@ -12123,7 +12123,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(); } @@ -12137,9 +12137,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); } @@ -12151,7 +12151,7 @@ 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) { @@ -12221,7 +12221,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 @@ -12273,7 +12273,7 @@ namespace pugi if (_begin != _storage) impl::xml_memory::deallocate(_begin); - // size check is necessary because for begin_ = end_ = nullptr, memcpy is UB + // size check is necessary because for begin_ = end_ = PUGIXML_NULL, memcpy is UB if (size_) memcpy(storage, begin_, size_ * sizeof(xpath_node)); @@ -12391,7 +12391,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 @@ -12399,7 +12399,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) { } @@ -12421,7 +12421,7 @@ namespace pugi default: assert(false && "Invalid variable type"); // unreachable - return 0; + return PUGIXML_NULL; } } @@ -12442,7 +12442,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(""); } @@ -12499,7 +12499,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() @@ -12511,7 +12511,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); } @@ -12531,7 +12531,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; } } @@ -12542,7 +12542,7 @@ namespace pugi _destroy(_data[i]); _data[i] = rhs._data[i]; - rhs._data[i] = 0; + rhs._data[i] = PUGIXML_NULL; } return *this; @@ -12581,12 +12581,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) { @@ -12631,7 +12631,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); @@ -12680,7 +12680,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(); @@ -12704,7 +12704,7 @@ namespace pugi qimpl->root->optimize(&qimpl->alloc); _impl = impl.release(); - _result.error = 0; + _result.error = PUGIXML_NULL; } else { @@ -12718,7 +12718,7 @@ namespace pugi } } - PUGI__FN xpath_query::xpath_query(): _impl(0) + PUGI__FN xpath_query::xpath_query(): _impl(PUGIXML_NULL) { } @@ -12733,7 +12733,7 @@ namespace pugi { _impl = rhs._impl; _result = rhs._result; - rhs._impl = 0; + rhs._impl = PUGIXML_NULL; rhs._result = xpath_parse_result(); } @@ -12746,7 +12746,7 @@ namespace pugi _impl = rhs._impl; _result = rhs._result; - rhs._impl = 0; + rhs._impl = PUGIXML_NULL; rhs._result = xpath_parse_result(); return *this; @@ -12910,7 +12910,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