← board

C: single-subscript row decay of a multi-dim array crashed (NULL pointer)

Repro

static int g[6][4];
int main(void){ g[3][2] = 55; int *r = g[3]; return r[2]; }   /* want 55 */

Root

The C multi-dim flatten branch (cparser.inc, NodeArrNDInfo path) required a SECOND [ to fire, so a single subscript fell through to the generic per-node AN_INDEX, which strides by the element type and mis-decays the whole row to a scalar. NodeArrNDInfo only fires for rank >= 2, and the partial-index branch (from [[bug-c-partial-multidim-array-index]]) already builds the correct row pointer for nIdx < rank.

Fix (DONE)

Dropped the (CurTok.Kind = tkLBrack) (second-bracket) requirement from the ND flatten entry, so a single subscript enters with nIdx=1 and, since rank >= 2, takes the partial branch -> row pointer &base + (i-lo0)*rowStride. Full index (all subscripts) and 2-of-N partials are unchanged (the while-loop still consumes every present subscript). Rank-1 arrays never reach here (NodeArrNDInfo needs rank >= 2) and keep the plain AN_INDEX path.

Acceptance — MET

Log