Skip to content

Commit

Permalink
add return value for expand
Browse files Browse the repository at this point in the history
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from #1223)
  • Loading branch information
mrpre authored and Rich Salz committed Jul 1, 2016
1 parent a66069d commit 0a1d3a8
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions crypto/lhash/lhash.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#define UP_LOAD (2*LH_LOAD_MULT) /* load times 256 (default 2) */
#define DOWN_LOAD (LH_LOAD_MULT) /* load times 256 (default 1) */

static void expand(OPENSSL_LHASH *lh);
static int expand(OPENSSL_LHASH *lh);
static void contract(OPENSSL_LHASH *lh);
static OPENSSL_LH_NODE **getrn(OPENSSL_LHASH *lh, const void *data, unsigned long *rhash);

Expand Down Expand Up @@ -72,11 +72,17 @@ void *OPENSSL_LH_insert(OPENSSL_LHASH *lh, void *data)
unsigned long hash;
OPENSSL_LH_NODE *nn, **rn;
void *ret;

int val = 0;

lh->error = 0;
if (lh->up_load <= (lh->num_items * LH_LOAD_MULT / lh->num_nodes))
expand(lh);

val = expand(lh);

if(val){
lh->error++;
return (NULL);
}

rn = getrn(lh, data, &hash);

if (*rn == NULL) {
Expand Down Expand Up @@ -184,7 +190,7 @@ void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNCARG func, void
doall_util_fn(lh, 1, (OPENSSL_LH_DOALL_FUNC)0, func, arg);
}

static void expand(OPENSSL_LHASH *lh)
static int expand(OPENSSL_LHASH *lh)
{
OPENSSL_LH_NODE **n, **n1, **n2, *np;
unsigned int p, i, j;
Expand Down Expand Up @@ -216,7 +222,7 @@ static void expand(OPENSSL_LHASH *lh)
/* fputs("realloc error in lhash",stderr); */
lh->error++;
lh->p = 0;
return;
return -1;
}
for (i = (int)lh->num_alloc_nodes; i < j; i++) /* 26/02/92 eay */
n[i] = NULL; /* 02/03/92 eay */
Expand All @@ -226,6 +232,7 @@ static void expand(OPENSSL_LHASH *lh)
lh->p = 0;
lh->b = n;
}
return 0;
}

static void contract(OPENSSL_LHASH *lh)
Expand Down

0 comments on commit 0a1d3a8

Please sign in to comment.