Skip to content

Commit

Permalink
fix arraylength computation in the colorformat() method causing seg f…
Browse files Browse the repository at this point in the history
…ault when patch_argv_global is called
  • Loading branch information
catriverr committed Aug 22, 2024
1 parent cc261bf commit d6eb78a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
12 changes: 6 additions & 6 deletions lib/bin/gmeng.h
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,10 @@ static std::vector<std::string> bgcolornames = {

static std::string colorformat(std::string data) {
std::string formatted = data;
for (int i = 0; i < sizeof(Gmeng::colors); i++) {
for (int i = 0; i < (sizeof(Gmeng::colors)/sizeof(*Gmeng::colors)); i++) {
formatted = str_replace(formatted, "~" + colornames[i] + "~", Gmeng::colors[i]);
};
for (int i = 0; i < sizeof(Gmeng::bgcolors); i++) {
for (int i = 0; i < (sizeof(Gmeng::bgcolors)/sizeof(*Gmeng::bgcolors)); i++) {
formatted = str_replace(formatted, "~" + bgcolornames[i] + "~", Gmeng::bgcolors[i]);
};
formatted = str_replace(formatted, "~h~", "\033[1m");
Expand Down Expand Up @@ -649,9 +649,9 @@ static void __explain_why_i_cannot_run_to_dumbass_using_windows() {
exit(1);
};

static void _gargv_patch_global(int argc, char* argv[]) {
__annot__(_gargv_patch_global, "patches the Gmeng::global variable with the command-line arguments.");
__functree_call__(__FILE__, __LINE__, _gargv_patch_global);
static void patch_argv_global(int argc, char* argv[]) {
__annot__(patch_argv_global, "patches the Gmeng::global variable with the command-line arguments.");
__functree_call__(__FILE__, __LINE__, patch_argv_global);
#if _WIN32
__explain_why_i_cannot_run_to_dumbass_using_windows();
return;
Expand All @@ -666,7 +666,7 @@ static void _gargv_patch_global(int argc, char* argv[]) {
ioctl(STDOUT_FILENO, TIOCGWINSZ, &size);
int times = size.ws_col-11;
__gmeng_write_log__("gmeng.log", "command-line argument requested help menu\n");
SAY("~Br~\x0F~h~~y~GMENG " + (Gmeng::version) + "~n~ | " + Gmeng::colors[6] + "Terminal-Based 2D Game Engine~n~ | Help Menu\n");
SAY("~Br~\x0F~h~\x0F~y~GMENG " + (Gmeng::version) + "~n~ | " + Gmeng::colors[6] + "Terminal-Based 2D Game Engine~n~ | Help Menu\n");
SAY("~_~~st~" + repeatString("-", times+11) + "~n~\n");
SAY("~h~~r~Gmeng~n~ is a standalone terminal-based game engine, utilizing ~y~pthread~n~ and the ~b~C++ Standard library~n~.\n");
SAY("~_~Currently, Gmeng is only available to MacOS and Linux users while on its active development phase.\n");
Expand Down
2 changes: 1 addition & 1 deletion lib/bin/src/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ int main2( int argc, char** argv ) {
};

int main(int argc, char** argv) {
_gargv_patch_global(argc, argv);
patch_argv_global(argc, argv);
SAY("~b~~r~CLI to be implemented~n~\n");
return 0;
};
14 changes: 12 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# Compiler and flags
CXX := g++
CXXFLAGS := -lcurl -g --std=c++20 -pthread `pkg-config --libs --cflags ncursesw` -Wno-deprecated-declarations -Wno-writable-strings -Wno-switch-bool -Wno-format-security -framework ApplicationServices
CXXFLAGS := -lcurl --std=c++20 -pthread `pkg-config --libs --cflags ncursesw` -Wno-deprecated-declarations -Wno-writable-strings -Wno-switch-bool -Wno-format-security -framework ApplicationServices
OUTFILE := -o gmeng

ifeq ($(filter debug,$(MAKECMDGOALS)), debug)
CXXFLAGS += -fsanitize=address
CXXFLAGS += -g
endif

# Default target builds lib/bin/src/index.cpp
all: lib/bin/out/gmeng

Expand All @@ -17,5 +23,9 @@ test: test.cpp
test2: tests/test.cpp
$(CXX) $(CXXFLAGS) -o tests/out/test.o tests/test.cpp

# Target for building with the debug flag
debug:
@$(MAKE) CXXFLAGS="$(CXXFLAGS)" $(filter-out debug,$(MAKECMDGOALS))

# Phony targets
.PHONY: all test test2
.PHONY: all test test2 debug
Binary file modified tests/out/test.o
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ int main(int argc, char* argv[]) {
bool do_main1 = false;
gm_log("test.cpp",__LINE__,"gmeng_tests -> SPAWN(1)");
gm::global.dev_console = false;
_gargv_patch_global(argc, argv);
patch_argv_global(argc, argv);
for (int i = 0; i < argc; i++) {
char *v_arg = argv[i];
std::string argument (v_arg);
Expand Down

0 comments on commit d6eb78a

Please sign in to comment.