Skip to content

Commit

Permalink
allow non-fatal compiler errors
Browse files Browse the repository at this point in the history
fix crash in whitespace trim
increase stack size
  • Loading branch information
Paril committed Aug 26, 2024
1 parent 56b5613 commit 2b700f0
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ if (WIN32)

if (MSVC)
# request 8MB stack for all .exe's
set(STACKSIZE 8388608)
set(STACKSIZE 16388608)
set(CMAKE_EXE_LINKER_FLAGS "/STACK:${STACKSIZE}")

add_definitions("/wd4244") # disable "conversion from .. to .., possible loss of data" warning
Expand Down
2 changes: 1 addition & 1 deletion bsputil/bsputil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ int bsputil_main(int _argc, const char **_argv)
logging::init(std::nullopt, bsputil_options);

if (bsputil_options.remainder.size() != 1 || bsputil_options.operations.empty()) {
bsputil_options.print_help();
bsputil_options.print_help(true);
return 1;
}

Expand Down
4 changes: 2 additions & 2 deletions common/entdata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ void entdict_t::parse(parser_base_t &parser)
FError("closing brace without data");

// trim whitespace from start/end
while (std::isspace(keystr.front())) {
while (!keystr.empty() && std::isspace(keystr.front())) {
keystr.erase(keystr.begin());
}
while (std::isspace(keystr.back())) {
while (!keystr.empty() && std::isspace(keystr.back())) {
keystr.erase(keystr.cbegin());
}

Expand Down
11 changes: 7 additions & 4 deletions common/settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ void setting_container::set_settings(const entdict_t &epairs, source source)
}
}

void setting_container::print_help()
void setting_container::print_help(bool fatal)
{
fmt::print("{}usage: {} [-help/-h/-?] [-options] {}\n\n", program_description, program_name, remainder_name);

Expand All @@ -543,7 +543,7 @@ void setting_container::print_help()
}

for (auto setting : grouped.second) {
size_t numPadding = std::max(static_cast<size_t>(0), 28 - (setting->primary_name().size() + 4));
size_t numPadding = std::max(static_cast<size_t>(0), 28 - std::min((size_t) 28, (setting->primary_name().size() + 4)));
fmt::print(
" -{} {:{}} {}\n", setting->primary_name(), setting->format(), numPadding, setting->description());

Expand All @@ -555,7 +555,10 @@ void setting_container::print_help()
printf("\n");
}

throw quit_after_help_exception();
if (fatal)
{
throw quit_after_help_exception();
}
}

void setting_container::print_summary()
Expand Down Expand Up @@ -679,7 +682,7 @@ std::vector<std::string> setting_container::parse(parser_base_t &parser)
}

if (parser.token == "help" || parser.token == "h" || parser.token == "?") {
print_help();
print_help(true);
} else if (parser.token == "rst") {
print_rst_documentation();
}
Expand Down
2 changes: 1 addition & 1 deletion include/common/settings.hh
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ public:

inline auto grouped() const { return _grouped_settings; }

void print_help();
void print_help(bool fatal);
void print_summary();
void print_rst_documentation();

Expand Down
7 changes: 5 additions & 2 deletions light/light.cc
Original file line number Diff line number Diff line change
Expand Up @@ -447,13 +447,16 @@ void light_settings::initialize(int argc, const char **argv)
common_settings::initialize(argc - 1, argv + 1);

if (remainder.size() <= 0 || remainder.size() > 1) {
print_help();
print_help(true);
}

sourceMap = remainder[0];
} catch (parse_exception &ex) {
print_help(false);
logging::print("ERROR OCCURRED WHEN TRYING TO PARSE ARGUMENTS:\n");
logging::print(ex.what());
print_help();
logging::print("\n\n");
throw settings::quit_after_help_exception();
}
}

Expand Down
2 changes: 1 addition & 1 deletion maputil/maputil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ int maputil_main(int argc, const char **argv)
logging::init(std::nullopt, maputil_options);

if (maputil_options.operations.empty()) {
maputil_options.print_help();
maputil_options.print_help(true);
return 1;
}

Expand Down
7 changes: 5 additions & 2 deletions qbsp/qbsp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ void qbsp_settings::initialize(int argc, const char **argv)
common_settings::initialize(argc - 1, argv + 1);

if (remainder.size() <= 0 || remainder.size() > 2) {
print_help();
print_help(true);
}

qbsp_options.map_path = remainder[0];
Expand All @@ -596,8 +596,11 @@ void qbsp_settings::initialize(int argc, const char **argv)
qbsp_options.bsp_path = remainder[1];
}
} catch (parse_exception &ex) {
print_help(false);
logging::print("ERROR OCCURRED WHEN TRYING TO PARSE ARGUMENTS:\n");
logging::print(ex.what());
print_help();
logging::print("\n\n");
throw settings::quit_after_help_exception();
}
}

Expand Down
7 changes: 5 additions & 2 deletions vis/vis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,16 @@ void vis_settings::initialize(int argc, const char **argv)
common_settings::initialize(argc - 1, argv + 1);

if (remainder.size() <= 0 || remainder.size() > 2) {
print_help();
print_help(true);
}

sourceMap = DefaultExtension(remainder[0], "bsp");
} catch (parse_exception &ex) {
print_help(false);
logging::print("ERROR OCCURRED WHEN TRYING TO PARSE ARGUMENTS:\n");
logging::print(ex.what());
print_help();
logging::print("\n\n");
throw settings::quit_after_help_exception();
}
}
} // namespace settings
Expand Down

0 comments on commit 2b700f0

Please sign in to comment.