Changeset View
Changeset View
Standalone View
Standalone View
b/dirmngr/ks-engine-hkp.c
Context not available. | |||||
static int | static int | ||||
select_random_host (int *table) | select_random_host (int *table) | ||||
{ | { | ||||
int *tbl; | int *tbl = NULL; | ||||
size_t tblsize; | size_t tblsize = 0; | ||||
int pidx, idx; | int pidx, idx; | ||||
/* We create a new table so that we randomly select only from | /* We create a new table so that we randomly select only from | ||||
currently alive hosts. */ | currently alive hosts. */ | ||||
for (idx=0, tblsize=0; (pidx = table[idx]) != -1; idx++) | for (idx=0; (pidx = table[idx]) != -1; idx++) | ||||
if (hosttable[pidx] && !hosttable[pidx]->dead) | if (hosttable[pidx] && !hosttable[pidx]->dead) | ||||
tblsize++; | { | ||||
tblsize++; | |||||
tbl = xtryrealloc(tbl, tblsize * sizeof *tbl); | |||||
if (!tbl) | |||||
return -1; /* memory allocation failed! */ | |||||
tbl[tblsize-1] = pidx; | |||||
} | |||||
if (!tblsize) | if (!tblsize) | ||||
return -1; /* No hosts. */ | return -1; /* No hosts. */ | ||||
tbl = xtrymalloc (tblsize * sizeof *tbl); | |||||
if (!tbl) | |||||
return -1; | |||||
for (idx=0, tblsize=0; (pidx = table[idx]) != -1; idx++) | |||||
if (hosttable[pidx] && !hosttable[pidx]->dead) | |||||
tbl[tblsize++] = pidx; | |||||
if (tblsize == 1) /* Save a get_uint_nonce. */ | if (tblsize == 1) /* Save a get_uint_nonce. */ | ||||
pidx = tbl[0]; | pidx = tbl[0]; | ||||
else | else | ||||
Context not available. |