Skip to content

tools: check that menu label and icon tables are fully initialised - #256

Open
magikh0e wants to merge 1 commit into
cifertech:devfrom
magikh0e:tools-check-menu-tables
Open

magikh0e wants to merge 1 commit into
cifertech:devfrom
magikh0e:tools-check-menu-tables

Conversation

@magikh0e

@magikh0e magikh0e commented Sep 25, 2026 •

Copy link
Copy Markdown

The menus are parallel arrays: a ..._items[N] of labels beside a
..._icons[N] of bitmap pointers, walked by the same index.

Add an entry to one and forget the other and the compiler says nothing. An
array with fewer initialisers than its declared size is legal C++, and the
missing elements are null. Neither -Wall nor -Wextra warns.

What happens next is not a blank row. displaySubmenu() hands the pointer to
TFT_eSPI's drawBitmap, which dereferences it, so the board faults the moment
that page is opened. The crash lands in the drawing code, a long way from the
table that caused it, and only on that one page of that one menu. That
combination is what makes it expensive to track down.

It currently finds nothing, and that is the point

Run against this tree at 90f7967, all 30 tables are full and all 13
label/icon pairs agree. This is a regression guard rather than a bug report.
I am proposing it because it is the failure I hit on a fork of this code:
raising a page's feature count from 2 to 3 left the icon table with two
initialisers, and it compiled clean.

Testing

Mutation tested against this tree, with the checker's own output:

change result
drop one icon, keep the label gps_submenu_icons[gps_NUM_SUBMENU_ITEMS] is 3 but has 2 initialisers
raise a size constant, leave the table gps_submenu_icons[gps_NUM_SUBMENU_ITEMS] is 4 but has 3 initialisers
unmodified tree passes, exit 0

Both mutations are reverted. The branch contains only the new file.

What it is

One file, tools/check_menu_tables.py, about 100 lines. It reads source, so
it needs no board and no toolchain, and nothing beyond the standard library.
Exit status is 0 when every table is full and each label table's bound matches
its icon table's, so it drops into CI as is if you want it there.

Nothing else in the repo is touched.

Licence

I maintain a GPL-3.0-or-later fork, so to be unambiguous: this contribution is
offered under the MIT licence, the same as the rest of this project. It is
original work and does not derive from any GPL dependency in my fork.

@magikh0e
magikh0e force-pushed the tools-check-menu-tables branch from 5faeaa9 to 529c02d Compare September 25, 2026 18:53
The menus are parallel arrays: a `..._items[N]` of labels beside a
`..._icons[N]` of bitmap pointers, walked by the same index. Add an entry to
one and forget the other and C++ says nothing. An array with fewer
initialisers than its declared size is legal, and the missing elements are
null. Neither -Wall nor -Wextra warns.

What happens then is not a blank row. displaySubmenu() hands the pointer to
TFT_eSPI's drawBitmap, which dereferences it, so the board faults the moment
that menu page is opened. The crash lands in the drawing code, a long way
from the table that caused it, and only on one page of one menu.

Reads source. No board, no toolchain, nothing beyond the standard library. It
also checks that each label table and its icon table share a bound, since two
tables walked with different lengths is the same bug with an extra step.
@magikh0e
magikh0e force-pushed the tools-check-menu-tables branch from 529c02d to cfb3dda Compare September 25, 2026 18:53
@magikh0e
magikh0e changed the base branch from main to dev October 6, 2026 10:00
@magikh0e

magikh0e commented Oct 6, 2026

Copy link
Copy Markdown
Author

Retargeted from main to dev, per CONTRIBUTING.md. The diff is unchanged: main is an ancestor of dev, so this branch diffs identically against either, and it still merges cleanly.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

⌂ 换网址