From e53ef68469d21b315ff5cba7ae1c50b8b36df038 Mon Sep 17 00:00:00 2001 From: Thomas Fussell Date: Sun, 3 Jan 2021 12:20:46 -0500 Subject: [PATCH 1/4] fix compiler warnings and some valgrind problems --- .../xlnt/workbook/calculation_properties.hpp | 4 +- source/detail/default_case.hpp | 4 +- .../detail/implementations/workbook_impl.hpp | 6 +-- source/detail/serialization/xlsx_consumer.cpp | 5 +-- source/detail/serialization/xlsx_producer.cpp | 38 +++++++++---------- source/detail/serialization/xlsx_producer.hpp | 14 +++++++ source/utils/time.cpp | 5 +-- source/utils/timedelta.cpp | 5 +-- third-party/miniz/miniz.c | 2 +- 9 files changed, 46 insertions(+), 37 deletions(-) diff --git a/include/xlnt/workbook/calculation_properties.hpp b/include/xlnt/workbook/calculation_properties.hpp index 1b269a41..cd2e34ea 100644 --- a/include/xlnt/workbook/calculation_properties.hpp +++ b/include/xlnt/workbook/calculation_properties.hpp @@ -38,12 +38,12 @@ public: /// If this is older than the version of the Excel calculation engine opening /// the workbook, cell values will be recalculated. /// - std::size_t calc_id; + std::size_t calc_id = 0; /// /// If this is true, concurrent calculation will be enabled for the workbook. /// - bool concurrent_calc; + bool concurrent_calc = false; }; inline bool operator==(const calculation_properties &lhs, const calculation_properties &rhs) diff --git a/source/detail/default_case.hpp b/source/detail/default_case.hpp index 0f484bf0..70074e24 100644 --- a/source/detail/default_case.hpp +++ b/source/detail/default_case.hpp @@ -28,7 +28,7 @@ #define EXCEPT_ON_UNHANDLED_SWITCH_CASE #ifdef EXCEPT_ON_UNHANDLED_SWITCH_CASE -#define default_case(default_value) throw xlnt::unhandled_switch_case(); +#define default_case(default_value) throw xlnt::unhandled_switch_case() #else -#define default_case(default_value) return default_value; +#define default_case(default_value) return default_value #endif diff --git a/source/detail/implementations/workbook_impl.hpp b/source/detail/implementations/workbook_impl.hpp index cab2d6c9..92a64a82 100644 --- a/source/detail/implementations/workbook_impl.hpp +++ b/source/detail/implementations/workbook_impl.hpp @@ -144,9 +144,9 @@ struct workbook_impl struct file_version_t { std::string app_name; - std::size_t last_edited; - std::size_t lowest_edited; - std::size_t rup_build; + std::size_t last_edited = 0; + std::size_t lowest_edited = 0; + std::size_t rup_build = 0; bool operator==(const file_version_t& rhs) const { diff --git a/source/detail/serialization/xlsx_consumer.cpp b/source/detail/serialization/xlsx_consumer.cpp index 4b21eacf..7ac2d5f5 100644 --- a/source/detail/serialization/xlsx_consumer.cpp +++ b/source/detail/serialization/xlsx_consumer.cpp @@ -245,10 +245,7 @@ xlnt::detail::Cell parse_cell(xlnt::row_t row_arg, xml::parser *parser) } } // Prevents unhandled exceptions from being triggered. - for (auto &attr : parser->attribute_map()) - { - (void)attr; - } + parser->attribute_map(); } return c; } diff --git a/source/detail/serialization/xlsx_producer.cpp b/source/detail/serialization/xlsx_producer.cpp index db8279af..105fb218 100644 --- a/source/detail/serialization/xlsx_producer.cpp +++ b/source/detail/serialization/xlsx_producer.cpp @@ -836,7 +836,7 @@ void xlsx_producer::write_rich_text(const std::string &ns, const xlnt::rich_text if (run.second.get().has_size()) { write_start_element(ns, "sz"); - write_attribute("val", run.second.get().size()); + write_attribute("val", run.second.get().size()); write_end_element(ns, "sz"); } @@ -1024,7 +1024,7 @@ void xlsx_producer::write_font(const font &f) if (f.has_size()) { write_start_element(xmlns, "sz"); - write_attribute("val", f.size()); + write_attribute("val", f.size()); write_end_element(xmlns, "sz"); } @@ -1098,33 +1098,33 @@ void xlsx_producer::write_fill(const fill &f) if (gradient.degree() != 0.) { - write_attribute("degree", gradient.degree()); + write_attribute("degree", gradient.degree()); } if (gradient.left() != 0.) { - write_attribute("left", gradient.left()); + write_attribute("left", gradient.left()); } if (gradient.right() != 0.) { - write_attribute("right", gradient.right()); + write_attribute("right", gradient.right()); } if (gradient.top() != 0.) { - write_attribute("top", gradient.top()); + write_attribute("top", gradient.top()); } if (gradient.bottom() != 0.) { - write_attribute("bottom", gradient.bottom()); + write_attribute("bottom", gradient.bottom()); } for (const auto &stop : gradient.stops()) { write_start_element(xmlns, "stop"); - write_attribute("position", stop.first); + write_attribute("position", stop.first); write_start_element(xmlns, "color"); write_color(stop.second); write_end_element(xmlns, "color"); @@ -2376,21 +2376,21 @@ void xlsx_producer::write_worksheet(const relationship &rel) if (format_properties.base_col_width.is_set()) { - write_attribute("baseColWidth", + write_attribute("baseColWidth", format_properties.base_col_width.get()); } if (format_properties.default_column_width.is_set()) { - write_attribute("defaultColWidth", + write_attribute("defaultColWidth", format_properties.default_column_width.get()); } - write_attribute("defaultRowHeight", + write_attribute("defaultRowHeight", format_properties.default_row_height); if (format_properties.dy_descent.is_set()) { - write_attribute(xml::qname(xmlns_x14ac, "dyDescent"), + write_attribute(xml::qname(xmlns_x14ac, "dyDescent"), format_properties.dy_descent.get()); } @@ -2543,7 +2543,7 @@ void xlsx_producer::write_worksheet(const relationship &rel) if (props.dy_descent.is_set()) { - write_attribute(xml::qname(xmlns_x14ac, "dyDescent"), props.dy_descent.get()); + write_attribute(xml::qname(xmlns_x14ac, "dyDescent"), props.dy_descent.get()); } } @@ -2813,12 +2813,12 @@ void xlsx_producer::write_worksheet(const relationship &rel) { write_start_element(xmlns, "pageMargins"); - write_attribute("left", ws.page_margins().left()); - write_attribute("right", ws.page_margins().right()); - write_attribute("top", ws.page_margins().top()); - write_attribute("bottom", ws.page_margins().bottom()); - write_attribute("header", ws.page_margins().header()); - write_attribute("footer", ws.page_margins().footer()); + write_attribute("left", ws.page_margins().left()); + write_attribute("right", ws.page_margins().right()); + write_attribute("top", ws.page_margins().top()); + write_attribute("bottom", ws.page_margins().bottom()); + write_attribute("header", ws.page_margins().header()); + write_attribute("footer", ws.page_margins().footer()); write_end_element(xmlns, "pageMargins"); } diff --git a/source/detail/serialization/xlsx_producer.hpp b/source/detail/serialization/xlsx_producer.hpp index 80afdf01..d49bcab1 100644 --- a/source/detail/serialization/xlsx_producer.hpp +++ b/source/detail/serialization/xlsx_producer.hpp @@ -178,11 +178,18 @@ private: current_part_serializer_->attribute(name, value); } + template ::value, bool> = true> void write_attribute(const std::string &name, double value) { current_part_serializer_->attribute(name, converter_.serialise(value)); } + template ::value, bool> = true> + void write_attribute(const std::string &name, Integer value) + { + current_part_serializer_->attribute(name, std::to_string(value)); + } + // qname attribute name // not integer or float type template ::value>::type> @@ -191,11 +198,18 @@ private: current_part_serializer_->attribute(name, value); } + template ::value, bool> = true> void write_attribute(const xml::qname &name, double value) { current_part_serializer_->attribute(name, converter_.serialise(value)); } + template ::value, bool> = true> + void write_attribute(const xml::qname &name, Integer value) + { + current_part_serializer_->attribute(name, std::to_string(value)); + } + template void write_characters(T characters, bool preserve_whitespace = false) diff --git a/source/utils/time.cpp b/source/utils/time.cpp index d2bbe25c..a76f70f1 100644 --- a/source/utils/time.cpp +++ b/source/utils/time.cpp @@ -117,9 +117,8 @@ double time::to_number() const microseconds += static_cast(minute * 1e6 * 60); auto microseconds_per_hour = static_cast(1e6) * 60 * 60; microseconds += static_cast(hour) * microseconds_per_hour; - auto number = microseconds / (24.0 * microseconds_per_hour); - auto hundred_billion = static_cast(1e9) * 100; - number = std::floor(number * hundred_billion + 0.5) / hundred_billion; + auto number = static_cast(microseconds) / (24.0 * static_cast(microseconds_per_hour)); + number = std::floor(number * 100e9 + 0.5) / 100e9; return number; } diff --git a/source/utils/timedelta.cpp b/source/utils/timedelta.cpp index 16b4a4f2..43ebd473 100644 --- a/source/utils/timedelta.cpp +++ b/source/utils/timedelta.cpp @@ -44,9 +44,8 @@ double timedelta::to_number() const total_microseconds += static_cast(minutes * 1e6 * 60); auto microseconds_per_hour = static_cast(1e6) * 60 * 60; total_microseconds += static_cast(hours) * microseconds_per_hour; - auto number = total_microseconds / (24.0 * microseconds_per_hour); - auto hundred_billion = static_cast(1e9) * 100; - number = std::floor(number * hundred_billion + 0.5) / hundred_billion; + auto number = static_cast(total_microseconds) / (24.0 * static_cast(microseconds_per_hour)); + number = std::floor(number * 100e9 + 0.5) / 100e9; number += days; return number; diff --git a/third-party/miniz/miniz.c b/third-party/miniz/miniz.c index 9ded4c75..f408fdfd 100644 --- a/third-party/miniz/miniz.c +++ b/third-party/miniz/miniz.c @@ -3076,7 +3076,7 @@ static FILE *mz_freopen(const char *pPath, const char *pMode, FILE *pStream) #define MZ_DELETE_FILE remove #else -#pragma message("Using fopen, ftello, fseeko, stat() etc. path for file I/O - this path may not support large files.") +//#pragma message("Using fopen, ftello, fseeko, stat() etc. path for file I/O - this path may not support large files.") #ifndef MINIZ_NO_TIME #include #endif From c007dafe33dff4aa6178cb19e6e4ad48626f872e Mon Sep 17 00:00:00 2001 From: Thomas Fussell Date: Sun, 3 Jan 2021 18:26:48 -0500 Subject: [PATCH 2/4] add include --- source/detail/serialization/xlsx_producer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/source/detail/serialization/xlsx_producer.cpp b/source/detail/serialization/xlsx_producer.cpp index 105fb218..89ec06a5 100644 --- a/source/detail/serialization/xlsx_producer.cpp +++ b/source/detail/serialization/xlsx_producer.cpp @@ -24,6 +24,7 @@ #include #include // for std::accumulate #include +#include #include #include From a8b631bcbb61d0d7dfcc2de5fa689dbe37675081 Mon Sep 17 00:00:00 2001 From: Thomas Fussell Date: Sun, 3 Jan 2021 18:42:56 -0500 Subject: [PATCH 3/4] replace enable_if_t --- source/detail/serialization/xlsx_producer.hpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/source/detail/serialization/xlsx_producer.hpp b/source/detail/serialization/xlsx_producer.hpp index d49bcab1..745b377b 100644 --- a/source/detail/serialization/xlsx_producer.hpp +++ b/source/detail/serialization/xlsx_producer.hpp @@ -178,14 +178,14 @@ private: current_part_serializer_->attribute(name, value); } - template ::value, bool> = true> - void write_attribute(const std::string &name, double value) + template ::value, T>::type* = nullptr> + void write_attribute(const std::string &name, T value) { current_part_serializer_->attribute(name, converter_.serialise(value)); } - template ::value, bool> = true> - void write_attribute(const std::string &name, Integer value) + template ::value, T>::type* = nullptr> + void write_attribute(const std::string &name, T value) { current_part_serializer_->attribute(name, std::to_string(value)); } @@ -198,14 +198,14 @@ private: current_part_serializer_->attribute(name, value); } - template ::value, bool> = true> - void write_attribute(const xml::qname &name, double value) + template ::value, T>::type* = nullptr> + void write_attribute(const xml::qname &name, T value) { current_part_serializer_->attribute(name, converter_.serialise(value)); } - template ::value, bool> = true> - void write_attribute(const xml::qname &name, Integer value) + template ::value, T>::type* = nullptr> + void write_attribute(const xml::qname &name, T value) { current_part_serializer_->attribute(name, std::to_string(value)); } From 6987c1f233551bfe9a7060572c3bc6813fe46443 Mon Sep 17 00:00:00 2001 From: Thomas Fussell Date: Sun, 3 Jan 2021 19:04:41 -0500 Subject: [PATCH 4/4] add constructor --- source/detail/implementations/workbook_impl.hpp | 10 +++++++--- source/workbook/workbook.cpp | 6 +++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/source/detail/implementations/workbook_impl.hpp b/source/detail/implementations/workbook_impl.hpp index 92a64a82..7c4e028f 100644 --- a/source/detail/implementations/workbook_impl.hpp +++ b/source/detail/implementations/workbook_impl.hpp @@ -144,9 +144,13 @@ struct workbook_impl struct file_version_t { std::string app_name; - std::size_t last_edited = 0; - std::size_t lowest_edited = 0; - std::size_t rup_build = 0; + std::size_t last_edited; + std::size_t lowest_edited; + std::size_t rup_build; + + file_version_t(): last_edited(0), lowest_edited(0), rup_build(0) { + + } bool operator==(const file_version_t& rhs) const { diff --git a/source/workbook/workbook.cpp b/source/workbook/workbook.cpp index fcdb6a13..ff96a72e 100644 --- a/source/workbook/workbook.cpp +++ b/source/workbook/workbook.cpp @@ -414,7 +414,11 @@ workbook workbook::empty() wb.extended_property(xlnt::extended_property::hyperlinks_changed, false); wb.extended_property(xlnt::extended_property::app_version, "15.0300"); - auto file_version = detail::workbook_impl::file_version_t{"xl", 6, 6, 26709}; + detail::workbook_impl::file_version_t file_version; + file_version.app_name = "xl"; + file_version.last_edited = 6; + file_version.lowest_edited = 6; + file_version.rup_build = 26709; wb.d_->file_version_ = file_version; xlnt::workbook_view wb_view;