From 8d63c9dd1c6d1b78caee7aa21670185fe022d0df Mon Sep 17 00:00:00 2001 From: david Date: Sat, 25 Jul 2026 05:05:21 -0300 Subject: [PATCH] segfault if you go to negative numbers in the maze game... --- games/gamemaze.c | 6 +++--- petratc.c | 10 +++++----- rat.c | 10 +++++----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/games/gamemaze.c b/games/gamemaze.c index 3ce8737..6e563cf 100644 --- a/games/gamemaze.c +++ b/games/gamemaze.c @@ -276,8 +276,8 @@ void gamemaze(){ case 'q': case 'Q': stop(); break; case 'r': case 'R': properrestart(&curs, &W, &H); break; case 'a': case 'A': case KEY_LEFT: - if(!iswall(curs.posy, curs.posx - 1)){ - curs.posx -= 1; + if(curs.posx > 0 && !iswall(curs.posy, curs.posx - 1)){ + curs.posx -= 1; } break; case 'd': case 'D': case KEY_RIGHT: @@ -286,7 +286,7 @@ void gamemaze(){ } break; case 'w': case 'W': case KEY_UP: - if (!iswall(curs.posy - 1, curs.posx)){ + if (curs.posy > 0 && !iswall(curs.posy - 1, curs.posx)){ curs.posy -= 1; } break; diff --git a/petratc.c b/petratc.c index d3171cd..2cb60fb 100644 --- a/petratc.c +++ b/petratc.c @@ -33,9 +33,9 @@ char *funfact[] = { Rat rat; -//i was cleaning the code up a bit and what the fuck is this +/*i was cleaning the code up a bit and what the fuck is this //it's so funny Rat rat - +*/ void printrat(WINDOW *win){ werase(win); @@ -101,13 +101,13 @@ int truing = 1; case '2': endwin(); gamemaze(); - //printf("the maze is really dark squeak...\n\n"); + /*printf("the maze is really dark squeak...\n\n");*/ refresh(); break; case '4': endwin(); gamecatch(); - //printf("your rat feels cleaner!\n\n"); + /*printf("your rat feels cleaner!\n\n");*/ refresh(); break; case '5': @@ -118,7 +118,7 @@ int truing = 1; case '9': break; case '0': truing = 0; break; } -// i will put those printfs where the squeaks go but i have no clue how to do that today +/* i will put those printfs where the squeaks go but i have no clue how to do that today */ if(truing) printrat(win); } diff --git a/rat.c b/rat.c index e713cc4..136659f 100644 --- a/rat.c +++ b/rat.c @@ -47,7 +47,7 @@ void load(void) { &rat.hunger, &rat.love, &rat.fun, &rat.clean, &rat.health, &rat.age) != 6){ fprintf(stderr, "error: failed to initialize save data.\n"); } - //this should shut the compiler up + /*this should shut the compiler up*/ fclose(f); } @@ -67,12 +67,12 @@ float decay(float current, float dayspassed, float rate) { void setstat(){ int timenow = time(NULL); int newage = timenow - rat.age; - float days = newage / 86400.0f; //one day + float days = newage / 86400.0f; /*one day*/ - rat.hunger = decay(rat.hunger, days, 50.0f); //hungry beast - rat.love = decay(rat.love, days, 1.1f); //rats love you they won't hate you easly + rat.hunger = decay(rat.hunger, days, 50.0f); /*hungry beast*/ + rat.love = decay(rat.love, days, 1.1f); /*rats love you they won't hate you easly*/ rat.fun = decay(rat.fun, days, 25.0f); - rat.clean = decay(rat.clean, days, 5.0f);//rats are surprisingly clean they clean themselves so slow + rat.clean = decay(rat.clean, days, 5.0f);/*rats are surprisingly clean they clean themselves so slow*/ rat.health = decay(rat.health, days, 0.6f); rat.age = timenow;