| 403 | string 'outfile'. */ |
| 404 | |
| 405 | static void |
| 406 | next_file_name (void) |
| 407 | { |
| 408 | /* Index in suffix_alphabet of each character in the suffix. */ |
| 409 | static idx_t *sufindex; |
| 410 | static idx_t outbase_length; |
| 411 | static idx_t outfile_length; |
| 412 | static idx_t addsuf_length; |
| 413 | |
| 414 | if (! outfile) |
| 415 | { |
| 416 | bool overflow, widen; |
| 417 | |
| 418 | new_name: |
| 419 | widen = !! outfile_length; |
| 420 | |
| 421 | if (! widen) |
| 422 | { |
| 423 | /* Allocate and initialize the first file name. */ |
| 424 | |
| 425 | outbase_length = strlen (outbase); |
| 426 | addsuf_length = additional_suffix ? strlen (additional_suffix) : 0; |
| 427 | overflow = ckd_add (&outfile_length, outbase_length + addsuf_length, |
| 428 | suffix_length); |
| 429 | } |
| 430 | else |
| 431 | { |
| 432 | /* Reallocate and initialize a new wider file name. |
| 433 | We do this by subsuming the unchanging part of |
| 434 | the generated suffix into the prefix (base), and |
| 435 | reinitializing the now one longer suffix. */ |
| 436 | |
| 437 | overflow = ckd_add (&outfile_length, outfile_length, 2); |
| 438 | suffix_length++; |
| 439 | } |
| 440 | |
| 441 | idx_t outfile_size; |
| 442 | overflow |= ckd_add (&outfile_size, outfile_length, 1); |
| 443 | if (overflow) |
| 444 | xalloc_die (); |
| 445 | outfile = xirealloc (outfile, outfile_size); |
| 446 | |
| 447 | if (! widen) |
| 448 | memcpy (outfile, outbase, outbase_length); |
| 449 | else |
| 450 | { |
| 451 | /* Append the last alphabet character to the file name prefix. */ |
| 452 | outfile[outbase_length] = suffix_alphabet[sufindex[0]]; |
| 453 | outbase_length++; |
| 454 | } |
| 455 | |
| 456 | outfile_mid = outfile + outbase_length; |
| 457 | memset (outfile_mid, suffix_alphabet[0], suffix_length); |
| 458 | if (additional_suffix) |
| 459 | memcpy (outfile_mid + suffix_length, additional_suffix, addsuf_length); |
| 460 | outfile[outfile_length] = 0; |
| 461 | |
| 462 | free (sufindex); |
no test coverage detected