** Read, classify, and fill other details about the next option. ** 'psize' is filled with option's size, 'notoalign' with its ** alignment requirements. ** Local variable 'size' gets the size to be aligned. (Kpadal option ** always gets its full alignment, other options are limited by ** the maximum alignment ('maxalign'). Kchar option needs no alignment ** despite its size. */
| 1539 | ** despite its size. |
| 1540 | */ |
| 1541 | static KOption getdetails (Header *h, size_t totalsize, |
| 1542 | const char **fmt, int *psize, int *ntoalign) { |
| 1543 | KOption opt = getoption(h, fmt, psize); |
| 1544 | int align = *psize; /* usually, alignment follows size */ |
| 1545 | if (opt == Kpaddalign) { /* 'X' gets alignment from following option */ |
| 1546 | if (**fmt == '\0' || getoption(h, fmt, &align) == Kchar || align == 0) |
| 1547 | luaL_argerror(h->L, 1, "invalid next option for option 'X'"); |
| 1548 | } |
| 1549 | if (align <= 1 || opt == Kchar) /* need no alignment? */ |
| 1550 | *ntoalign = 0; |
| 1551 | else { |
| 1552 | if (align > h->maxalign) /* enforce maximum alignment */ |
| 1553 | align = h->maxalign; |
| 1554 | if (l_unlikely((align & (align - 1)) != 0)) /* not a power of 2? */ |
| 1555 | luaL_argerror(h->L, 1, "format asks for alignment not power of 2"); |
| 1556 | *ntoalign = (align - (int)(totalsize & (align - 1))) & (align - 1); |
| 1557 | } |
| 1558 | return opt; |
| 1559 | } |
| 1560 | |
| 1561 | |
| 1562 | /* |
no test coverage detected