** 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. */
| 1266 | ** despite its size. |
| 1267 | */ |
| 1268 | static KOption getdetails (Header *h, size_t totalsize, |
| 1269 | const char **fmt, int *psize, int *ntoalign) { |
| 1270 | KOption opt = getoption(h, fmt, psize); |
| 1271 | int align = *psize; /* usually, alignment follows size */ |
| 1272 | if (opt == Kpaddalign) { /* 'X' gets alignment from following option */ |
| 1273 | if (**fmt == '\0' || getoption(h, fmt, &align) == Kchar || align == 0) |
| 1274 | luaL_argerror(h->L, 1, "invalid next option for option 'X'"); |
| 1275 | } |
| 1276 | if (align <= 1 || opt == Kchar) /* need no alignment? */ |
| 1277 | *ntoalign = 0; |
| 1278 | else { |
| 1279 | if (align > h->maxalign) /* enforce maximum alignment */ |
| 1280 | align = h->maxalign; |
| 1281 | if ((align & (align - 1)) != 0) /* is 'align' not a power of 2? */ |
| 1282 | luaL_argerror(h->L, 1, "format asks for alignment not power of 2"); |
| 1283 | *ntoalign = (align - (int)(totalsize & (align - 1))) & (align - 1); |
| 1284 | } |
| 1285 | return opt; |
| 1286 | } |
| 1287 | |
| 1288 | |
| 1289 | /* |
no test coverage detected