Convert ASN1_OBJECT_new() to calloc().
authorjsing <jsing@openbsd.org>
Fri, 3 Dec 2021 16:58:11 +0000 (16:58 +0000)
committerjsing <jsing@openbsd.org>
Fri, 3 Dec 2021 16:58:11 +0000 (16:58 +0000)
Rather than using malloc() and then initialising all struct members, use
calloc() and only initialise the single non-zero value member.

ok schwarze@ tb@

lib/libcrypto/asn1/a_object.c

index 8600f80..9b3bae0 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: a_object.c,v 1.32 2021/05/01 13:16:30 tb Exp $ */
+/* $OpenBSD: a_object.c,v 1.33 2021/12/03 16:58:11 jsing Exp $ */
 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
@@ -354,20 +354,15 @@ err:
 ASN1_OBJECT *
 ASN1_OBJECT_new(void)
 {
-       ASN1_OBJECT *ret;
+       ASN1_OBJECT *a;
 
-       ret = malloc(sizeof(ASN1_OBJECT));
-       if (ret == NULL) {
+       if ((a = calloc(1, sizeof(ASN1_OBJECT))) == NULL) {
                ASN1error(ERR_R_MALLOC_FAILURE);
                return (NULL);
        }
-       ret->length = 0;
-       ret->data = NULL;
-       ret->nid = 0;
-       ret->sn = NULL;
-       ret->ln = NULL;
-       ret->flags = ASN1_OBJECT_FLAG_DYNAMIC;
-       return (ret);
+       a->flags = ASN1_OBJECT_FLAG_DYNAMIC;
+
+       return a;
 }
 
 void