Skip to content

Commit

Permalink
Use -Werror in CI (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
andiwand authored Aug 18, 2024
1 parent a1d8261 commit 916ec72
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 138 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ jobs:
-DCMAKE_TOOLCHAIN_FILE="conan_toolchain.cmake"
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_CXX_FLAGS="-Werror"
-DCMAKE_INSTALL_PREFIX=install
-DODR_TEST=ON
- name: build
Expand Down
30 changes: 15 additions & 15 deletions cli/src/translate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ int main(int argc, char **argv) {
password = argv[3];
}

File file{input};
DecodedFile decoded_file{input};

HtmlConfig config;
config.editable = true;

PasswordCallback password_callback = [&]() {
if (!password) {
if (decoded_file.is_document_file()) {
DocumentFile document_file = decoded_file.document_file();
if (document_file.password_encrypted() && !password) {
std::cerr << "document encrypted but no password given" << std::endl;
std::exit(2);
return 2;
}
if (document_file.password_encrypted() &&
!document_file.decrypt(*password)) {
std::cerr << "wrong password" << std::endl;
return 1;
}
return *password;
};

try {
html::translate(file, output, config, password_callback);
} catch (const WrongPassword &e) {
std::cerr << "wrong password" << std::endl;
return 1;
}

HtmlConfig config;
config.editable = true;

html::translate(decoded_file, output, config);

return 0;
}
6 changes: 6 additions & 0 deletions src/odr/internal/html/document_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ void html::translate_master_page(MasterPage masterPage, HtmlWriter &out,
void html::translate_text(const Element element, HtmlWriter &out,
const HtmlConfig &config,
const HtmlResourceLocator &resourceLocator) {
(void)resourceLocator;

Text text = element.text();

out.write_element_begin(
Expand All @@ -253,6 +255,7 @@ void html::translate_line_break(Element element, HtmlWriter &out,
const HtmlConfig &config,
const HtmlResourceLocator &resourceLocator) {
(void)config;
(void)resourceLocator;

LineBreak line_break = element.line_break();

Expand Down Expand Up @@ -319,6 +322,9 @@ void html::translate_link(Element element, HtmlWriter &out,
void html::translate_bookmark(Element element, HtmlWriter &out,
const HtmlConfig &config,
const HtmlResourceLocator &resourceLocator) {
(void)config;
(void)resourceLocator;

Bookmark bookmark = element.bookmark();

out.write_element_begin("a",
Expand Down
3 changes: 2 additions & 1 deletion src/odr/internal/json/json_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ namespace odr::internal {

void json::check_json_file(std::istream &in) {
// TODO limit check size
(void)nlohmann::json::parse(in);
auto json = nlohmann::json::parse(in);
(void)json;
// TODO check if that even works
}

Expand Down
13 changes: 9 additions & 4 deletions src/odr/internal/pdf/pdf_cmap_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,19 @@ std::variant<Object, std::string> CMapParser::read_token() const {
m_parser.read_string());
}
if (m_parser.peek_name()) {
return m_parser.read_name();
return Object(m_parser.read_name());
}
if (m_parser.peek_dictionary()) {
return m_parser.read_dictionary();
return Object(m_parser.read_dictionary());
}

std::string token;
while (true) {
int_type c = m_parser.geti();
if (c == eof) {
int_type i = m_parser.geti();
if (i == eof) {
return token;
}
auto c = static_cast<char_type>(i);
if (ObjectParser::is_whitespace(c)) {
return token;
}
Expand All @@ -50,6 +51,8 @@ std::variant<Object, std::string> CMapParser::read_token() const {
}

void CMapParser::read_codespacerange(std::uint32_t n, CMap &cmap) const {
(void)cmap;

m_parser.skip_whitespace();
for (std::uint32_t i = 0; i < n; ++i) {
auto from_glyph = m_parser.read_object();
Expand Down Expand Up @@ -86,6 +89,8 @@ void CMapParser::read_bfchar(std::uint32_t n, CMap &cmap) const {
}

void CMapParser::read_bfrange(std::uint32_t n, CMap &cmap) const {
(void)cmap;

m_parser.skip_whitespace();
for (std::uint32_t i = 0; i < n; ++i) {
auto from_glyph = m_parser.read_object();
Expand Down
20 changes: 10 additions & 10 deletions src/odr/internal/pdf/pdf_document_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pdf::Font *parse_font(DocumentParser &parser, const ObjectReference &reference,

font->type = Type::font;
font->object_reference = reference;
font->object = dictionary;
font->object = Object(dictionary);

if (dictionary.has_key("ToUnicode")) {
IndirectObject to_unicode_obj =
Expand All @@ -43,12 +43,12 @@ pdf::Font *parse_font(DocumentParser &parser, const ObjectReference &reference,

pdf::Resources *parse_resources(DocumentParser &parser, const Object &object,
Document &document) {
Resources *resources = document.create_element<Resources>();
auto *resources = document.create_element<Resources>();

Dictionary dictionary = parser.resolve_object_copy(object).as_dictionary();

resources->type = Type::resources;
resources->object = dictionary;
resources->object = Object(dictionary);

if (!dictionary["Font"].is_null()) {
Dictionary font_table =
Expand All @@ -64,14 +64,14 @@ pdf::Resources *parse_resources(DocumentParser &parser, const Object &object,
pdf::Annotation *parse_annotation(DocumentParser &parser,
const ObjectReference &reference,
Document &document) {
Annotation *annotation = document.create_element<Annotation>();
auto *annotation = document.create_element<Annotation>();

IndirectObject object = parser.read_object(reference);
const Dictionary &dictionary = object.object.as_dictionary();

annotation->type = Type::annotation;
annotation->object_reference = reference;
annotation->object = dictionary;
annotation->object = Object(dictionary);

return annotation;
}
Expand All @@ -85,7 +85,7 @@ pdf::Page *parse_page(DocumentParser &parser, const ObjectReference &reference,

page->type = Type::page;
page->object_reference = reference;
page->object = dictionary;
page->object = Object(dictionary);
page->parent = dynamic_cast<Pages *>(parent);
page->resources = parse_resources(parser, dictionary["Resources"], document);

Expand All @@ -112,14 +112,14 @@ pdf::Page *parse_page(DocumentParser &parser, const ObjectReference &reference,

pdf::Pages *parse_pages(DocumentParser &parser,
const ObjectReference &reference, Document &document) {
Pages *pages = document.create_element<Pages>();
auto *pages = document.create_element<Pages>();

IndirectObject object = parser.read_object(reference);
const Dictionary &dictionary = object.object.as_dictionary();

pages->type = Type::pages;
pages->object_reference = reference;
pages->object = dictionary;
pages->object = Object(dictionary);
pages->count = dictionary["Count"].as_integer();

for (const Object &kid : dictionary["Kids"].as_array()) {
Expand Down Expand Up @@ -151,15 +151,15 @@ pdf::Element *parse_page_or_pages(DocumentParser &parser,
pdf::Catalog *parse_catalog(DocumentParser &parser,
const ObjectReference &reference,
Document &document) {
Catalog *catalog = document.create_element<Catalog>();
auto *catalog = document.create_element<Catalog>();

IndirectObject object = parser.read_object(reference);
const Dictionary &dictionary = object.object.as_dictionary();
const ObjectReference &pages_reference = dictionary["Pages"].as_reference();

catalog->type = Type::catalog;
catalog->object_reference = reference;
catalog->object = dictionary;
catalog->object = Object(dictionary);
catalog->pages = parse_pages(parser, pages_reference, document);

return catalog;
Expand Down
10 changes: 5 additions & 5 deletions src/odr/internal/pdf/pdf_graphics_operator_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,17 @@ GraphicsOperator GraphicsOperatorParser::read_operator() const {

while (true) {
if (m_parser.peek_number()) {
std::visit([&](auto v) { result.arguments.push_back(v); },
std::visit([&](auto v) { result.arguments.emplace_back(v); },
m_parser.read_integer_or_real());
} else if (m_parser.peek_name()) {
result.arguments.push_back(m_parser.read_name());
result.arguments.emplace_back(m_parser.read_name());
} else if (m_parser.peek_string()) {
std::visit([&](auto s) { result.arguments.push_back(std::move(s)); },
std::visit([&](auto s) { result.arguments.emplace_back(std::move(s)); },
m_parser.read_string());
} else if (m_parser.peek_array()) {
result.arguments.push_back(m_parser.read_array());
result.arguments.emplace_back(m_parser.read_array());
} else if (m_parser.peek_dictionary()) {
result.arguments.push_back(m_parser.read_dictionary());
result.arguments.emplace_back(m_parser.read_dictionary());
} else {
m_parser.skip_whitespace();
break;
Expand Down
Loading

0 comments on commit 916ec72

Please sign in to comment.