From da9b61085fa8c8f7e3937a53292f37ee69149488 Mon Sep 17 00:00:00 2001 From: tb <> Date: Fri, 25 Sep 2020 11:05:21 +0000 Subject: Simplify UI_new_method() Use calloc() instead of malloc() and setting all members manually to 0. Avoid unnecessary else branch. --- src/lib/libcrypto/ui/ui_lib.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'src/lib') diff --git a/src/lib/libcrypto/ui/ui_lib.c b/src/lib/libcrypto/ui/ui_lib.c index 1e3a4ee705..0a22eba69f 100644 --- a/src/lib/libcrypto/ui/ui_lib.c +++ b/src/lib/libcrypto/ui/ui_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ui_lib.c,v 1.41 2020/09/25 10:56:36 tb Exp $ */ +/* $OpenBSD: ui_lib.c,v 1.42 2020/09/25 11:05:21 tb Exp $ */ /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL * project 2001. */ @@ -79,20 +79,14 @@ UI_new_method(const UI_METHOD *method) { UI *ret; - ret = malloc(sizeof(UI)); - if (ret == NULL) { + if ((ret = calloc(1, sizeof(UI))) == NULL) { UIerror(ERR_R_MALLOC_FAILURE); return NULL; } - if (method == NULL) + if ((ret->meth = method) == NULL) ret->meth = UI_get_default_method(); - else - ret->meth = method; - - ret->strings = NULL; - ret->user_data = NULL; - ret->flags = 0; CRYPTO_new_ex_data(CRYPTO_EX_INDEX_UI, ret, &ret->ex_data); + return ret; } -- cgit v1.2.3-55-g6feb