Return the maximum number of bytes that can be generated by applying FORMAT to an int value. If the format is invalid, diagnose the problem and exit. */
| 1247 | applying FORMAT to an int value. If the format is |
| 1248 | invalid, diagnose the problem and exit. */ |
| 1249 | static idx_t |
| 1250 | max_out (char *format) |
| 1251 | { |
| 1252 | bool percent = false; |
| 1253 | |
| 1254 | for (char *f = format; *f; f++) |
| 1255 | if (*f == '%' && *++f != '%') |
| 1256 | { |
| 1257 | if (percent) |
| 1258 | error (EXIT_FAILURE, 0, |
| 1259 | _("too many %% conversion specifications in suffix")); |
| 1260 | percent = true; |
| 1261 | int flags; |
| 1262 | f += get_format_flags (f, &flags); |
| 1263 | while (c_isdigit (*f)) |
| 1264 | f++; |
| 1265 | if (*f == '.') |
| 1266 | while (c_isdigit (*++f)) |
| 1267 | continue; |
| 1268 | check_format_conv_type (f, flags); |
| 1269 | } |
| 1270 | |
| 1271 | if (! percent) |
| 1272 | error (EXIT_FAILURE, 0, |
| 1273 | _("missing %% conversion specification in suffix")); |
| 1274 | |
| 1275 | int maxlen = snprintf (NULL, 0, format, INT_MAX); |
| 1276 | if (! (0 <= maxlen && maxlen <= IDX_MAX)) |
| 1277 | xalloc_die (); |
| 1278 | return maxlen; |
| 1279 | } |
| 1280 | |
| 1281 | int |
| 1282 | main (int argc, char **argv) |
no test coverage detected