check that data alignment is in range and a power of two

Otherwise, the alignment gets truncated to fit in char, so
`align 256` is handled as no alignment requirement.
This commit is contained in:
Michael Forney 2024-03-26 11:04:42 -07:00 committed by Quentin Carbonneaux
parent 1b7770e271
commit 85827e2232

View file

@ -1091,6 +1091,9 @@ parsedat(void cb(Dat *), Lnk *lnk)
if (t == Talign) {
if (nextnl() != Tint)
err("alignment expected");
if (tokval.num <= 0 || tokval.num > CHAR_MAX
|| (tokval.num & (tokval.num-1)) != 0)
err("invalid alignment");
lnk->align = tokval.num;
t = nextnl();
}