tools/crypto_bench: check malloc fail before using it

Need to check malloc fail before using it, so adjust the location
in the code.

Reviewed-by: Nicolas George <nicolas.george@normalesup.org>
Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
pull/329/head^2
Jun Zhao 6 years ago
parent 181031906e
commit 153a6a67a9
  1. 8
      tools/crypto_bench.c

@ -665,8 +665,8 @@ struct hash_impl implementations[] = {
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
uint8_t *input = av_malloc(MAX_INPUT_SIZE * 2); uint8_t *input;
uint8_t *output = input + MAX_INPUT_SIZE; uint8_t *output;
unsigned i, impl, size; unsigned i, impl, size;
int opt; int opt;
@ -702,12 +702,14 @@ int main(int argc, char **argv)
exit(opt != 'h'); exit(opt != 'h');
} }
} }
input = av_malloc(MAX_INPUT_SIZE * 2);
if (!input) if (!input)
fatal_error("out of memory"); fatal_error("out of memory");
for (i = 0; i < MAX_INPUT_SIZE; i += 4) for (i = 0; i < MAX_INPUT_SIZE; i += 4)
AV_WB32(input + i, i); AV_WB32(input + i, i);
output = input + MAX_INPUT_SIZE;
size = MAX_INPUT_SIZE; size = MAX_INPUT_SIZE;
for (impl = 0; impl < FF_ARRAY_ELEMS(implementations); impl++) for (impl = 0; impl < FF_ARRAY_ELEMS(implementations); impl++)
run_implementation(input, output, &implementations[impl], size); run_implementation(input, output, &implementations[impl], size);

Loading…
Cancel
Save