Modern programmers have things SOOOOO easy...I

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andrew Davie

I asked Claude AI to bug-hunt for me. Amazing.
You can point it at your GitHub repository and it will grab the files and analyse.
Not all bugs probably, but certainly some gotchas in there.

Confirmed Bugs
resetTracking() in scroll.c — wrong variable clamped twice
clamp(&scrollX, SCROLL_MIN_X, SCROLL_MAX_X);
clamp(&scrollX, SCROLL_MIN_X, SCROLL_MAX_X);  // BUG: should be scrollY

scrollY is calculated and then never clamped. Copy-paste error. scrollY can end up out of bounds, which will produce rendering glitches or out-of-range RAM writes via the scroll rendering code.
clamp() in scroll.c — returns nothing despite int return type

int clamp(int *v, int min, int max) {
    if (*v < min) *v = min;
    if (*v > max) *v = max;
    // no return statement
}


Undefined behaviour — the function has return type int but no return. GCC will likely warn but still compile; the returned value is garbage. Should either be void or return *v.
initNextLife() in main.c — function body is inside #if 0

void initNextLife() {
#if 0
    // entire body including all init logic
#endif
    pulsePlayerColour = 0;
}

Only pulsePlayerColour = 0 executes. All the critical init (bufferedSWCHA, exitTrigger, gameFrame, lavaSurfaceTrixel, showLava, showWater, initWyrms(), initPlayer(), initSprites(), initParticles(), initCharAnimations(), setScoreCycle() etc.) is dead code. This is almost certainly unintentional — someone #if 0'd the whole body during debugging and never reinstated it. Currently initGameState_Game() manually calls many of these, so it partly compensates, but they're not called on subsequent lives.
drawBit() in drawScreen.c — octal literal

if (x < -0100 || x > 0x200 || y < -0x300 || y > 0x000)

-0100 is octal -64, not decimal -100. Almost certainly a copy-paste or typo. The bounds check for the left side of the mace chain is therefore much tighter than intended — pixels to the left between -100 and -64 get drawn when they shouldn't (or vice versa depending on intent).
processLava() in board.c — mismatched braces in switch

switch (*me) {
case CH_LAVA_BLANK: {
    if (!(rand & (15 << 7))) {
        (*me)++;
        ...
    }
    break;
case CH_LAVA_SMALL:    // <-- this case is INSIDE the CH_LAVA_BLANK block
    *me = CH_LAVA_MEDIUM;
    break;
case CH_LAVA_MEDIUM:
    ...

The closing } for the CH_LAVA_BLANK case comes after the other cases. The case CH_LAVA_SMALL:, case CH_LAVA_MEDIUM:, and case CH_LAVA_LARGE: labels are syntactically inside the compound statement block for CH_LAVA_BLANK. This compiles (C allows it), and the fall-through behaviour ends up working, but it's structurally wrong — the closing brace is in the wrong place, and any future edit to this switch is a trap.
drawPlanetName() in score.c — out-of-bounds array access

const char *p = planetName[cave < sizeof(planetName) ? cave : sizeof(planetName) - 1];

sizeof(planetName) is the byte size of the pointer array, not the element count. On a 32-bit ARM that's 10 * 4 = 40, not 10. The condition cave < sizeof(planetName) is always true for any sane cave number, so the clamp never activates — but more importantly, if the intent was to guard against cave >= 10, it fails completely. Should be sizeof(planetName) / sizeof(planetName
  • ).
nDotsBackwards() in particle.c — unchecked sphereDot return

int idx = sphereDot(...);
particle[idx].x += ...;  // idx may be -1
particle[idx].y += ...;

sphereDot returns -1 if the dot is off-screen. The other callers check if (idx >= 0) — this one doesn't, so it writes to particle[-1], which is whatever's just before the particle array in memory.

Probable Bugs / High-Risk
sound.c — processSoundEffects() break exits the wrong scope

else
    break;  // "sounds full or higher priority, ignore any more lower priority sounds"

This break is inside the for (id = 0; ...) loop. It breaks the whole sound scanning loop the moment it finds a sound that can't be placed, skipping all remaining lower-priority sounds in the queue. The comment explains the intent, but it also means that if a medium-priority sound fails to find a slot, any pending lower-priority sounds behind it never get a chance either — even if a slot is available. Probably intentional but it's fragile.
wyrm.c — wyrm->head used after decrement without bounds check

wyrm->head--;
wyrm->length--;
// ...
for (int i = 0; i <= wyrm->head; i++) { ... }

If wyrm->head was 0 before the decrement it becomes -1 (signed), but the loop condition i <= wyrm->head with i = 0 and head = -1 fails immediately — so it's harmless in that case. But wyrm->x
  • was just written via *segment = CH_DUST_ROCK_0 using index wyrm->y
  • * 40, and then the indices are shifted. Needs careful tracing.
drawPlayerSprite() — destLine = -1 out-of-bounds write on first iteration
(Flagged in the earlier review — still a real risk if buffer layout changes.)
player.c — spriteShape[] contains null pointers

0,  // shape_FRAME_ARMS_IN_AIR  // 02
0,  // shape_FRAME_IMPATIENT    // 06
...

drawPlayerSprite() dereferences spriteShape[*playerAnimation] without a null check. Any animation frame that references one of these null entries (FRAME_ARMS_IN_AIR = 2, FRAME_IMPATIENT = 6, etc.) will crash. The commented-out null check in the code suggests this was noticed and removed. If any animation ever lands on one of those frame IDs the game dies.

The resetTracking double-clamp of scrollX, the dead initNextLife body, and the nDotsBackwards unchecked -1 index are the most clear-cut actual bugs. The octal literal in drawBit is also a genuine mistake. The rest are high-risk structural issues.






Andrew Davie

#1
High praise indeed.
The #if 0 is deliberate, as it happens.

SpiceWare

This AI stuff is pretty slick, though I am limited in what I can use it for at work because most of our code falls under ITAR restrictions.

I've have used Grok to help develop new custom user controls as those don't fall under ITAR. Our programs use C++ .Net WinForm for the GUI and our users have been running into performance bottlenecks with the TreeView control as the spacecraft models grow in size.  Grok helped me build a new WPF multi-pick TreeView control.  The new control is embedded into our WinForm application by way of an ElementHost control. The WPF TreeView handles significantly larger amounts of data than the WinForm TreeView, solving the performance issue.