From: jsing Date: Fri, 3 Dec 2021 17:01:07 +0000 (+0000) Subject: Convert ASN1_STRING_type_new() to calloc(). X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=a059a1e0d6def91e9c103afb5a78aa26097c82f2;p=openbsd Convert ASN1_STRING_type_new() to calloc(). Rather than using malloc() and then initialising all struct members, use calloc() and only initialise the single non-zero value member. ok schwarze@ tb@ --- diff --git a/lib/libcrypto/asn1/asn1_lib.c b/lib/libcrypto/asn1/asn1_lib.c index b04fa3c6012..0998b418290 100644 --- a/lib/libcrypto/asn1/asn1_lib.c +++ b/lib/libcrypto/asn1/asn1_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: asn1_lib.c,v 1.46 2021/11/13 20:44:00 schwarze Exp $ */ +/* $OpenBSD: asn1_lib.c,v 1.47 2021/12/03 17:01:07 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -359,18 +359,15 @@ ASN1_STRING_new(void) ASN1_STRING * ASN1_STRING_type_new(int type) { - ASN1_STRING *ret; + ASN1_STRING *a; - ret = malloc(sizeof(ASN1_STRING)); - if (ret == NULL) { + if ((a = calloc(1, sizeof(ASN1_STRING))) == NULL) { ASN1error(ERR_R_MALLOC_FAILURE); - return (NULL); + return NULL; } - ret->length = 0; - ret->type = type; - ret->data = NULL; - ret->flags = 0; - return (ret); + a->type = type; + + return a; } void