Skip to content

Commit a318302

Browse files
Marcel Dütscherclaude
andcommitted
Fix CodeQL findings: drop dead branches and redundant guards
Seven trivial fixes for findings CodeQL surfaced in src/: - main.cpp: drop "if (jpg)" before free() (free(NULL) is a no-op) - main.cpp: drop empty if-block whose only content was a comment - main.cpp: drop "if (boostHap > 0)" guard — boostHap inits to 2 and is only ever reassigned upward - face.cpp: drop "if (pileCount > 0)" guard inside drawCleaningButton — the function already early-returns on pileCount == 0 - face.cpp: drop unreachable ": 70" branch in drawActivityCrossGame — row is clamped to [0,5] above, so "row <= 5" is always true - face.cpp: rename inner buf[12] to playsBuf to stop shadowing the outer buf[40] in drawActivityGameOver - face.cpp: drop unused friendlyCell local in drawMediaSelectScreen Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 1c0cec5 commit a318302

2 files changed

Lines changed: 16 additions & 23 deletions

File tree

src/face.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,13 @@ void drawCleaningButton(M5Canvas& c, uint8_t pileCount, uint32_t now_ms) {
208208
c.drawLine(cx - 11, cy + 7, cx + 11, cy - 9, red);
209209

210210
// Tiny badge in the corner with the count
211-
if (pileCount > 0) {
212-
char buf[4];
213-
snprintf(buf, sizeof(buf), "%u", (unsigned)pileCount);
214-
c.setTextDatum(top_right);
215-
c.setTextSize(1);
216-
c.setTextColor(glyph);
217-
c.drawString(buf, r.x + r.w - 4, r.y + 3);
218-
c.setTextDatum(top_left);
219-
}
211+
char buf[4];
212+
snprintf(buf, sizeof(buf), "%u", (unsigned)pileCount);
213+
c.setTextDatum(top_right);
214+
c.setTextSize(1);
215+
c.setTextColor(glyph);
216+
c.drawString(buf, r.x + r.w - 4, r.y + 3);
217+
c.setTextDatum(top_left);
220218
}
221219

222220
// Falling rain — stripes of blue raindrops at varying speeds.
@@ -3304,7 +3302,7 @@ void drawActivityCrossGame(M5Canvas& c, const ActivityView& v) {
33043302
int row = v.petRow;
33053303
if (row < 0) row = 0;
33063304
if (row > 5) row = 5;
3307-
int py = (row == 0) ? 222 : (row <= 5 ? kCrossLaneY[row - 1] - 2 : 70);
3305+
int py = (row == 0) ? 222 : kCrossLaneY[row - 1] - 2;
33083306
if (row >= 5) py = 72;
33093307
drawPetMini(c, kCrossPetX, py, v.animal);
33103308

@@ -3447,12 +3445,12 @@ void drawActivityGameOver(M5Canvas& c, const ActivityView& v) {
34473445
// Run counter underneath the label so the user sees how many tries
34483446
// are left without extra UI clutter.
34493447
if (v.maxPlaysPerSession > 0) {
3450-
char buf[12];
3451-
snprintf(buf, sizeof(buf), "%u / %u",
3448+
char playsBuf[12];
3449+
snprintf(playsBuf, sizeof(playsBuf), "%u / %u",
34523450
(unsigned)v.playsInSession, (unsigned)v.maxPlaysPerSession);
34533451
c.setTextSize(1);
34543452
c.setTextColor(fg);
3455-
c.drawString(buf, r.x + r.w / 2, r.y + r.h / 2 + 10);
3453+
c.drawString(playsBuf, r.x + r.w / 2, r.y + r.h / 2 + 10);
34563454
}
34573455
}
34583456
// OK button — secondary (neutral), ends the game and returns to the
@@ -7574,7 +7572,6 @@ void drawMediaSelectScreen(M5Canvas& c, const MediaSelectView& v) {
75747572
bool radioCell = (i == 5);
75757573
bool cameraCell = (i == 6);
75767574
bool galleryCell = (i == 7);
7577-
bool friendlyCell = friendsCell || radioCell || cameraCell || galleryCell;
75787575
uint16_t bg = friendsCell ? c.color565(220, 240, 220) :
75797576
radioCell ? c.color565(245, 230, 200) :
75807577
cameraCell ? c.color565(225, 215, 240) :

src/main.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,11 +1177,9 @@ static void applyActivityReward(uint32_t now) {
11771177
newBest = true;
11781178
}
11791179

1180-
if (boostHap > 0) {
1181-
changeHappiness(+boostHap, now);
1182-
spawnFloatToBar(FloatType::Heart, petHeadX(), petHeadY(),
1183-
TargetBar::Happiness, now);
1184-
}
1180+
changeHappiness(+boostHap, now);
1181+
spawnFloatToBar(FloatType::Heart, petHeadX(), petHeadY(),
1182+
TargetBar::Happiness, now);
11851183
if (boostEng > 0) {
11861184
changeEnergy(+boostEng, now);
11871185
}
@@ -3335,7 +3333,7 @@ static void handleTouchCameraMode(int tx, int ty, bool pressed,
33353333
if (ok && jpg && len > 0) {
33363334
ok = photo_store::save(jpg, len);
33373335
}
3338-
if (jpg) free(jpg);
3336+
free(jpg);
33393337

33403338
g_pet.cameraSaveOverlay = true;
33413339
g_pet.cameraSaveOverlayUntilMs = now + kCameraSaveOverlayMs;
@@ -6220,9 +6218,7 @@ void loop() {
62206218
if (g_pet.persisted.needs.energy != energyBefore) {
62216219
g_pet.engLastChangeMs = now;
62226220
}
6223-
if (g_pet.persisted.needs.happiness != /*tracked elsewhere*/0) {
6224-
// happiness/fullness decay is silent; we don't pulse on every −1.
6225-
}
6221+
// happiness/fullness decay is silent; we don't pulse on every −1.
62266222

62276223
// Sleep regen visualization: occasional Z float toward energy bar
62286224
if (sleeping && now - g_pet.lastSleepRegenMs > SLEEP_REGEN_FLOAT_MS) {

0 commit comments

Comments
 (0)