Remove some more easy NewZeroed calls Bug: 491512320 Change-Id: I4f4c23a4fa0054e67b4118789b68d6cab6dea2f4 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/90647 Reviewed-by: Rudolf Polzer <rpolzer@google.com> Auto-Submit: David Benjamin <davidben@google.com> Commit-Queue: Rudolf Polzer <rpolzer@google.com>
diff --git a/crypto/bio/pair.cc b/crypto/bio/pair.cc index 72a6f75..11b5c2e 100644 --- a/crypto/bio/pair.cc +++ b/crypto/bio/pair.cc
@@ -29,27 +29,27 @@ namespace { struct bio_bio_st { - BIO *peer; // NULL if buf == NULL. - // If peer != NULL, then BIO_get_data(peer) is also a bio_bio_st, - // and its "peer" member points back to us. - // peer != NULL iff init != 0 in the BIO. + BIO *peer = nullptr; // NULL if buf == NULL. + // If peer != NULL, then BIO_get_data(peer) is also a + // bio_bio_st, and its "peer" member points back to us. + // peer != NULL iff init != 0 in the BIO. // This is for what we write (i.e. reading uses peer's struct): - int closed; // valid iff peer != NULL - size_t len; // valid iff buf != NULL; 0 if peer == NULL - size_t offset; // valid iff buf != NULL; 0 if len == 0 - size_t size; - uint8_t *buf; // "size" elements (if != NULL) + int closed = 0; // valid iff peer != NULL + size_t len = 0; // valid iff buf != NULL; 0 if peer == NULL + size_t offset = 0; // valid iff buf != NULL; 0 if len == 0 + size_t size = 0; + uint8_t *buf = nullptr; // "size" elements (if != NULL) - size_t request; // valid iff peer != NULL; 0 if len != 0, - // otherwise set by peer to number of bytes - // it (unsuccessfully) tried to read, - // never more than buffer space (size-len) warrants. + size_t request = 0; // valid iff peer != NULL; 0 if len != 0, + // otherwise set by peer to number of bytes + // it (unsuccessfully) tried to read, + // never more than buffer space (size-len) warrants. }; } // namespace static int bio_new(BIO *bio) { - struct bio_bio_st *b = NewZeroed<struct bio_bio_st>(); + struct bio_bio_st *b = New<struct bio_bio_st>(); if (b == nullptr) { return 0; }
diff --git a/crypto/lhash/internal.h b/crypto/lhash/internal.h index 42931a6..27c7780 100644 --- a/crypto/lhash/internal.h +++ b/crypto/lhash/internal.h
@@ -65,7 +65,7 @@ typedef uint32_t (*lhash_hash_func)(const void *a); typedef uint32_t (*lhash_hash_func_helper)(lhash_hash_func func, const void *a); -typedef struct lhash_st _LHASH; +struct _LHASH; // OPENSSL_lh_new returns a new, empty hash table or NULL on error. OPENSSL_EXPORT _LHASH *OPENSSL_lh_new(lhash_hash_func hash,
diff --git a/crypto/lhash/lhash.cc b/crypto/lhash/lhash.cc index a95dfcf..b074bb8 100644 --- a/crypto/lhash/lhash.cc +++ b/crypto/lhash/lhash.cc
@@ -33,37 +33,37 @@ static const size_t kMaxAverageChainLength = 2; static const size_t kMinAverageChainLength = 1; -// lhash_item_st is an element of a hash chain. It points to the opaque data +// LHASH_ITEM is an element of a hash chain. It points to the opaque data // for this element and to the next item in the chain. The linked-list is NULL // terminated. -typedef struct lhash_item_st { - void *data; - struct lhash_item_st *next; +struct LHASH_ITEM { + void *data = nullptr; + LHASH_ITEM *next = nullptr; // hash contains the cached, hash value of |data|. - uint32_t hash; -} LHASH_ITEM; + uint32_t hash = 0; +}; -struct lhash_st { +struct _LHASH { // num_items contains the total number of items in the hash table. - size_t num_items; + size_t num_items = 0; // buckets is an array of |num_buckets| pointers. Each points to the head of // a chain of LHASH_ITEM objects that have the same hash value, mod // |num_buckets|. - LHASH_ITEM **buckets; + LHASH_ITEM **buckets = nullptr; // num_buckets contains the length of |buckets|. This value is always >= // kMinNumBuckets. - size_t num_buckets; + size_t num_buckets = 0; // callback_depth contains the current depth of |lh_doall| or |lh_doall_arg| // calls. If non-zero then this suppresses resizing of the |buckets| array, // which would otherwise disrupt the iteration. - unsigned callback_depth; + unsigned callback_depth = 0; - lhash_cmp_func comp; - lhash_hash_func hash; + lhash_cmp_func comp = nullptr; + lhash_hash_func hash = nullptr; }; _LHASH *OPENSSL_lh_new(lhash_hash_func hash, lhash_cmp_func comp) { - _LHASH *ret = NewZeroed<_LHASH>(); + _LHASH *ret = New<_LHASH>(); if (ret == nullptr) { return nullptr; }
diff --git a/crypto/x509/policy.cc b/crypto/x509/policy.cc index 535035c..5534fea 100644 --- a/crypto/x509/policy.cc +++ b/crypto/x509/policy.cc
@@ -45,9 +45,9 @@ // An X509_POLICY_NODE is a node in the policy graph. It corresponds to a node // from RFC 5280, section 6.1.2, step (a), but we store some fields differently. -typedef struct x509_policy_node_st { +struct X509_POLICY_NODE { // policy is the "valid_policy" field from RFC 5280. - ASN1_OBJECT *policy; + ASN1_OBJECT *policy = nullptr; // parent_policies, if non-empty, is the list of "valid_policy" values for all // nodes which are a parent of this node. In this case, no entry in this list @@ -62,31 +62,31 @@ // concrete policy as a parent. Section 6.1.3, step (d.1.ii) only runs if // there was no match in step (d.1.i). We do not need to represent a parent // list of, say, {anyPolicy, OID1, OID2}. - STACK_OF(ASN1_OBJECT) *parent_policies; + STACK_OF(ASN1_OBJECT) *parent_policies = nullptr; // mapped is one if this node matches a policy mapping in the certificate and // zero otherwise. - int mapped; + int mapped = 0; // reachable is one if this node is reachable from some valid policy in the // end-entity certificate. It is computed during |has_explicit_policy|. - int reachable; -} X509_POLICY_NODE; + int reachable = 0; +}; DEFINE_NAMESPACED_STACK_OF(X509_POLICY_NODE) // An X509_POLICY_LEVEL is the collection of nodes at the same depth in the // policy graph. This structure can also be used to represent a level's // "expected_policy_set" values. See |process_policy_mappings|. -typedef struct x509_policy_level_st { +struct X509_POLICY_LEVEL { // nodes is the list of nodes at this depth, except for the anyPolicy node, if // any. This list is sorted by policy OID for efficient lookup. - STACK_OF(X509_POLICY_NODE) *nodes; + STACK_OF(X509_POLICY_NODE) *nodes = nullptr; // has_any_policy is one if there is an anyPolicy node at this depth, and zero // otherwise. - int has_any_policy; -} X509_POLICY_LEVEL; + int has_any_policy = 0; +}; DEFINE_NAMESPACED_STACK_OF(X509_POLICY_LEVEL) @@ -106,7 +106,7 @@ static X509_POLICY_NODE *x509_policy_node_new(const ASN1_OBJECT *policy) { assert(!is_any_policy(policy)); - X509_POLICY_NODE *node = NewZeroed<X509_POLICY_NODE>(); + X509_POLICY_NODE *node = New<X509_POLICY_NODE>(); if (node == nullptr) { return nullptr; } @@ -132,7 +132,7 @@ } static X509_POLICY_LEVEL *x509_policy_level_new() { - X509_POLICY_LEVEL *level = NewZeroed<X509_POLICY_LEVEL>(); + X509_POLICY_LEVEL *level = New<X509_POLICY_LEVEL>(); if (level == nullptr) { return nullptr; }