** 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. */
| 1482 | ** despite its size. |
| 1483 | */ |
| 1484 | static KOption getdetails (Header *h, size_t totalsize, |
| 1485 | const char **fmt, int *psize, int *ntoalign) { |
| 1486 | KOption opt = getoption(h, fmt, psize); |
| 1487 | int align = *psize; /* usually, alignment follows size */ |
| 1488 | if (opt == Kpaddalign) { /* 'X' gets alignment from following option */ |
| 1489 | if (**fmt == '\0' || getoption(h, fmt, &align) == Kchar || align == 0) |
| 1490 | luaL_argerror(h->L, 1, "invalid next option for option 'X'"); |
| 1491 | } |
| 1492 | if (align <= 1 || opt == Kchar) /* need no alignment? */ |
| 1493 | *ntoalign = 0; |
| 1494 | else { |
| 1495 | if (align > h->maxalign) /* enforce maximum alignment */ |
| 1496 | align = h->maxalign; |
| 1497 | if (l_unlikely((align & (align - 1)) != 0)) /* not a power of 2? */ |
| 1498 | luaL_argerror(h->L, 1, "format asks for alignment not power of 2"); |
| 1499 | *ntoalign = (align - (int)(totalsize & (align - 1))) & (align - 1); |
| 1500 | } |
| 1501 | return opt; |
| 1502 | } |
| 1503 | |
| 1504 | |
| 1505 | /* |
no test coverage detected