gabrielzschmitz / Tomato.C

A pomodoro timer written in pure C.
GNU General Public License v3.0
316 stars 20 forks source link

🔧 Initializes unitialized machineFrame animation variable #42

Closed CarlosCraveiro closed 7 months ago

CarlosCraveiro commented 7 months ago

The Problem

As reported in the issue #40, sometimes the action of skipping the Pomodoro was causing weird segmentation faults.

After some debugging I discovered that the frameIndex was behaving weirdly at:

/* Print the coffee machine frames */
void printMachine(appData* app) {
// ...
int frameIndex = app->machineFrame * 11;
// ...
for (int i = 0; i < 11; i++) {
    mvprintw(starty + i, startx, "%s", machineFrames[frameIndex + i]);
  }
// ...

Causing unexpected illegal memory accesses at machineFrames. I printed the value of frameIndex in the giff available at Before section.

The Solution

Apparently the problem was solved by initializing the app->machineFrame with the other Animation Variables at tomato.c

//...
  /* Animation variables */
  app->logoFrame = 0;
  app->coffeeFrame = 0;
  app->machineFrame = 0;
  app->bannerFrame = 0;
  app->helpFrame = 0;
  app->notepadFrame = 0;
  app->frameTimer = 0;
  app->framems = 0;
//...

Before:

FrameIndex_bug_cropped

After:

WorkingWithoutProblem_cropped

gabrielzschmitz commented 7 months ago

I am very grateful for your work of debug! I really just forgot the machineFrame specifically... 😅. My bad, I hope it didn't take up too much of your time.

CarlosCraveiro commented 7 months ago

Haha, no problem! I took the early afternoon to hunt for this bug. It was a fun experience btw, it's been a while since I debugged a C program like this.

I got excited to help when I saw your commitment to the project yesterday. In fact, I discovered this program yesterday through a post on r/unixporn and I loved the proposal. It's the Pomodoro app I always wanted!

gabrielzschmitz commented 7 months ago

Thanks! In a month or two I should refactor the whole app, then it should not be that buggy... as I created this app in the first year of university.

CarlosCraveiro commented 7 months ago

I look forward to the refactoring. Hope it stays as amazing as it is now!