Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ Checks: >
performance-*,
portability-*,
-bugprone-easily-swappable-parameters,
-bugprone-derived-method-shadowing-base-method,
-bugprone-narrowing-conversions,
-performance-enum-size,
-portability-avoid-pragma-once,
# clang-analyzer-* stays enabled but advisory: its only findings are inside
# third-party -isystem headers (cryptopp/httplib/csv), which we cannot patch.
# Typed value handles intentionally refine inherited nonvirtual methods.
# Path-sensitive analyzer findings remain advisory, including dependency code.
WarningsAsErrors: '*,-clang-analyzer-*'
HeaderFilterRegex: '(^|/)src/odr/'
FormatStyle: file
2 changes: 2 additions & 0 deletions src/odr/exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ struct Exception : std::runtime_error {
template <ErrorCode C> struct CodedException : Exception {
using Exception::Exception;

// Every instantiation returns its enum constant without dependent code.
// NOLINTNEXTLINE(portability-template-virtual-member-function)
[[nodiscard]] ErrorCode code() const noexcept override { return C; }
};

Expand Down
7 changes: 4 additions & 3 deletions src/odr/internal/common/sheet_recalculation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ class StaleCells final : public formula::CellSource {
m_circular.insert(busy, m_stack.end());
return std::nullopt;
}
if (!formula->second.node.has_value() || formula->second.spanned) {
const Formula &entry = formula->second;
if (!entry.node.has_value() || entry.spanned) {
m_results.emplace(position, std::nullopt);
return std::nullopt;
}
Expand All @@ -127,8 +128,8 @@ class StaleCells final : public formula::CellSource {
return std::nullopt;
}
m_stack.push_back(position);
const std::optional<formula::Value> result = formula::evaluate(
*formula->second.node, position, *this, m_base->settings());
const std::optional<formula::Value> result =
formula::evaluate(*entry.node, position, *this, m_base->settings());
m_stack.pop_back();
// a result the depth limit cut short is computed again
if (!m_frontier.has_value()) {
Expand Down
7 changes: 2 additions & 5 deletions src/odr/internal/html/pdf_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1235,11 +1235,8 @@ class HtmlServiceImpl final : public HtmlService {
build_link_resolver(*m_parser, *m_document, pages));
const std::size_t begin =
std::min<std::size_t>(config().page_range_begin, pages.size());
const std::size_t end =
config().page_range_end
? std::clamp<std::size_t>(*config().page_range_end, begin,
pages.size())
: pages.size();
const std::size_t end = std::clamp<std::size_t>(
config().page_range_end.value_or(pages.size()), begin, pages.size());
m_first_page = begin;
m_pages.assign(pages.begin() + static_cast<std::ptrdiff_t>(begin),
pages.begin() + static_cast<std::ptrdiff_t>(end));
Expand Down
6 changes: 5 additions & 1 deletion src/odr/internal/odf/odf_style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <cstdlib>
#include <cstring>
#include <ranges>
#include <stdexcept>
#include <string>
#include <string_view>
#include <unordered_map>
Expand Down Expand Up @@ -946,9 +947,12 @@ std::string
StyleRegistry::create_paragraph_style(pugi::xml_node automatic_styles,
const char *base_name,
const ParagraphStyle &style) {
if (!style.text_align.has_value()) {
throw std::invalid_argument("paragraph alignment is missing");
}
const std::string base = base_name != nullptr ? base_name : "";
const std::string key =
fmt::format("{}|{}", base, static_cast<int>(*style.text_align));
fmt::format("{}|{}", base, static_cast<std::int32_t>(*style.text_align));
if (const auto it = m_created_paragraph_styles.find(key);
it != std::end(m_created_paragraph_styles)) {
return it->second;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ class ElementAdapter final : public AdapterBase {
/// so those refuse.
void paragraph_set_style(const ElementIdentifier element_id,
const ParagraphStyle &style) const override {
if (!style.text_align.has_value()) {
throw std::invalid_argument("paragraph alignment is missing");
}
const char *algn = nullptr;
switch (*style.text_align) {
case TextAlign::left:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ void ooxml::spreadsheet::move_comments(const pugi::xml_node comments,
continue;
}
at.set(span->first);
const std::int64_t shift = static_cast<std::int64_t>(span->first) - old;
pugi::xml_text anchor = data.child("x:Anchor").text();
std::vector<std::int64_t> values;
for (const std::string_view value :
Expand All @@ -649,8 +650,8 @@ void ooxml::spreadsheet::move_comments(const pugi::xml_node comments,
values.push_back(std::strtoll(std::string(value).c_str(), nullptr, 10));
}
if (values.size() == 8) {
values[first] += static_cast<std::int64_t>(span->first) - old;
values[first + 4] += static_cast<std::int64_t>(span->first) - old;
values[first] += shift;
values[first + 4] += shift;
anchor.set(fmt::format("{}", fmt::join(values, ", ")).c_str());
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/odr/internal/ooxml/text/ooxml_text_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <optional>
#include <ostream>
#include <sstream>
#include <stdexcept>
#include <string_view>

namespace odr::internal::ooxml::text {
Expand Down Expand Up @@ -395,6 +396,9 @@ class ElementAdapter final : public AdapterBase {
}
void paragraph_set_style(const ElementIdentifier element_id,
const ParagraphStyle &style) const override {
if (!style.text_align.has_value()) {
throw std::invalid_argument("paragraph alignment is missing");
}
pugi::xml_node node = get_node(element_id);
pugi::xml_node properties = node.child("w:pPr");
if (!properties) {
Expand Down
2 changes: 1 addition & 1 deletion src/odr/internal/pdf/pdf_document_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1743,7 +1743,7 @@ std::string DocumentParser::read_object_stream(const IndirectObject &object) {
throw UnauthenticatedReadError();
}
if (m_decryptor.has_value()) {
raw = m_decryptor->decrypt_stream(object.reference, std::move(raw));
raw = m_decryptor->decrypt_stream(object.reference, raw);
}
return raw;
}
Expand Down
2 changes: 1 addition & 1 deletion src/odr/internal/pdf/pdf_file_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ ObjectStream FileParser::read_object_stream(const std::uint32_t n,
void FileParser::read_header() {
const std::string header1 = m_parser.read_line();
// the second line is an optional binary-marker comment; read past it
[[maybe_unused]] const std::string header2 = m_parser.read_line();
m_parser.read_line();

if (!util::string::starts_with(header1, "%PDF-")) {
throw std::runtime_error("illegal header");
Expand Down
12 changes: 6 additions & 6 deletions src/odr/internal/pdf/pdf_jpx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ std::optional<pdf::JpxImage> pdf::decode_jpx(const std::string &data) {
// A component the `cdef` box marks as opacity is the alpha plane; the rest
// are colour, in codestream order.
std::vector<std::uint32_t> colour;
std::optional<std::uint32_t> alpha_index;
const opj_image_comp_t *alpha = nullptr;
for (std::uint32_t i = 0; i < image->numcomps; ++i) {
if (image->comps[i].alpha != 0 && !alpha_index.has_value()) {
alpha_index = i;
if (image->comps[i].alpha != 0 && alpha == nullptr) {
alpha = &image->comps[i];
} else {
colour.push_back(i);
}
Expand All @@ -188,7 +188,7 @@ std::optional<pdf::JpxImage> pdf::decode_jpx(const std::string &data) {
result.height = height;
result.components = static_cast<std::int32_t>(colour.size());
result.samples.resize(*output_size);
if (alpha_index.has_value()) {
if (alpha != nullptr) {
result.alpha.resize(*output_size / colour.size());
}

Expand All @@ -199,9 +199,9 @@ std::optional<pdf::JpxImage> pdf::decode_jpx(const std::string &data) {
result.samples[out++] =
static_cast<char>(sample_at(image->comps[c], x, y));
}
if (alpha_index.has_value()) {
if (alpha != nullptr) {
result.alpha[static_cast<std::size_t>(y) * width + x] =
sample_at(image->comps[*alpha_index], x, y);
sample_at(*alpha, x, y);
}
}
}
Expand Down
Loading