From 414ad96d7a9042140776912b6a7cef917864e874 Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine" Date: Sun, 24 Jul 2011 03:19:31 +0000 Subject: Fixed compilation for gcc 4.2.1 (apparently not all gcc versions properly implement strict aliasing warning...) git-svn-id: http://pugixml.googlecode.com/svn/trunk@813 99668b35-9821-0410-8761-19e4c4f06640 --- src/pugixml.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/pugixml.cpp b/src/pugixml.cpp index df194b9..774de6c 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -3175,7 +3175,7 @@ namespace } #ifndef PUGIXML_NO_STL - struct xml_stream_chunk + template struct xml_stream_chunk { static xml_stream_chunk* create() { @@ -3204,22 +3204,21 @@ namespace xml_stream_chunk* next; size_t size; - // so that we can use this for both wchar_t and char data (char -> wchar_t casting is prohibited by strict aliasing) - wchar_t data[xml_memory_page_size / sizeof(wchar_t)]; + T data[xml_memory_page_size / sizeof(T)]; }; template xml_parse_status load_stream_data_noseek(std::basic_istream& stream, void** out_buffer, size_t* out_size) { - buffer_holder chunks(0, xml_stream_chunk::destroy); + buffer_holder chunks(0, xml_stream_chunk::destroy); // read file to a chunk list size_t total = 0; - xml_stream_chunk* last = 0; + xml_stream_chunk* last = 0; while (!stream.eof()) { // allocate new chunk - xml_stream_chunk* chunk = xml_stream_chunk::create(); + xml_stream_chunk* chunk = xml_stream_chunk::create(); if (!chunk) return status_out_of_memory; // append chunk to list @@ -3227,7 +3226,7 @@ namespace else chunks.data = last = chunk; // read data to chunk - stream.read(reinterpret_cast(chunk->data), static_cast(sizeof(chunk->data) / sizeof(T))); + stream.read(chunk->data, static_cast(sizeof(chunk->data) / sizeof(T))); chunk->size = static_cast(stream.gcount()) * sizeof(T); // read may set failbit | eofbit in case gcount() is less than read length, so check for other I/O errors @@ -3244,7 +3243,7 @@ namespace char* write = buffer; - for (xml_stream_chunk* chunk = static_cast(chunks.data); chunk; chunk = chunk->next) + for (xml_stream_chunk* chunk = static_cast*>(chunks.data); chunk; chunk = chunk->next) { assert(write + chunk->size <= buffer + total); memcpy(write, chunk->data, chunk->size); -- cgit v1.2.3