mpz_t *p;
unsigned long int *e;
idx_t nfactors;
+ idx_t nalloc;
};
static void factor (uintmax_t, uintmax_t, struct factors *);
factors->p = nullptr;
factors->e = nullptr;
factors->nfactors = 0;
+ factors->nalloc = 0;
}
static void
if (i < 0 || mpz_cmp (p[i], prime) != 0)
{
- p = xireallocarray (p, nfactors + 1, sizeof p[0]);
- e = xireallocarray (e, nfactors + 1, sizeof e[0]);
+ if (factors->nfactors == factors->nalloc)
+ {
+ p = xpalloc (p, &factors->nalloc, 1, -1, sizeof *p);
+ e = xireallocarray (e, factors->nalloc, sizeof *e);
+ }
mpz_init (p[nfactors]);
- for (long j = nfactors - 1; j > i; j--)
+ for (ptrdiff_t j = nfactors - 1; j > i; j--)
{
mpz_set (p[j + 1], p[j]);
e[j + 1] = e[j];
files, or perhaps other processes the user cares about). */
static int nbpids = 0;
static pid_t * pids = nullptr;
+static idx_t pids_alloc;
/* True if we have ever read standard input. */
static bool have_read_stdin;
break;
case PID_OPTION:
- {
- pid_t pid =
- xdectoumax (optarg, 0, PID_T_MAX, "", _("invalid PID"), 0);
- pids = xreallocarray (pids, nbpids + 1, sizeof (pid_t));
- pids[nbpids] = pid;
- nbpids++;
- }
+ if (nbpids == pids_alloc)
+ pids = xpalloc (pids, &pids_alloc, 1,
+ MIN (INT_MAX, PTRDIFF_MAX), sizeof *pids);
+ pids[nbpids++] = xdectoumax (optarg, 0, PID_T_MAX, "",
+ _("invalid PID"), 0);
break;
case PRESUME_INPUT_PIPE_OPTION: