Fix bad memory access found via warnings

Simple mistakes caught by gcc 11.4 -Wnonnull and -Warray-bounds.

See code diff for details.

Backport: release

Merge request reports

Loading