From 766ae1587d5a62f3f569a6fd40947b4c85844eaa Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Mon, 20 Feb 2017 14:18:25 +0100 Subject: preinitialize variables to work-around warnings with clang's scan-build Signed-off-by: Nikos Mavrogiannopoulos --- lib/dh.c | 2 +- lib/opencdk/read-packet.c | 15 ++++++++------- lib/opencdk/stream.c | 2 +- lib/x509/common.c | 4 ++-- lib/x509/privkey_pkcs8.c | 6 ++++-- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/dh.c b/lib/dh.c index 06e6145984..8f8905f7c2 100644 --- a/lib/dh.c +++ b/lib/dh.c @@ -442,7 +442,7 @@ gnutls_dh_params_export_pkcs3(gnutls_dh_params_t params, unsigned char *params_data, size_t * params_data_size) { - gnutls_datum_t out; + gnutls_datum_t out = {NULL, 0}; int ret; ret = gnutls_dh_params_export2_pkcs3(params, format, &out); diff --git a/lib/opencdk/read-packet.c b/lib/opencdk/read-packet.c index 87ab06c569..202fdee4f7 100644 --- a/lib/opencdk/read-packet.c +++ b/lib/opencdk/read-packet.c @@ -85,7 +85,7 @@ static u16 read_16(cdk_stream_t s) /* read about S2K at http://tools.ietf.org/html/rfc4880#section-3.7.1 */ static cdk_error_t read_s2k(cdk_stream_t inp, cdk_s2k_t s2k) { - size_t nread; + size_t nread = 0; s2k->mode = cdk_stream_getc(inp); s2k->hash_algo = cdk_stream_getc(inp); @@ -219,7 +219,7 @@ read_pubkey_enc(cdk_stream_t inp, size_t pktlen, cdk_pkt_pubkey_enc_t pke) static cdk_error_t read_mdc(cdk_stream_t inp, cdk_pkt_mdc_t mdc) { - size_t n; + size_t n = 0; cdk_error_t rc; if (!inp || !mdc) @@ -319,7 +319,7 @@ read_public_subkey(cdk_stream_t inp, size_t pktlen, cdk_pkt_pubkey_t pk) static cdk_error_t read_secret_key(cdk_stream_t inp, size_t pktlen, cdk_pkt_seckey_t sk) { - size_t p1, p2, nread; + size_t p1, p2, nread = 0; int i, nskey; int rc; @@ -574,7 +574,7 @@ static cdk_error_t read_subpkt(cdk_stream_t inp, cdk_subpkt_t * r_ctx, size_t * r_nbytes) { int c, c1; - size_t size, nread, n; + size_t size, nread = 0, n; cdk_subpkt_t node; cdk_error_t rc; @@ -620,11 +620,12 @@ read_subpkt(cdk_stream_t inp, cdk_subpkt_t * r_ctx, size_t * r_nbytes) n++; node->size--; rc = stream_read(inp, node->d, node->size, &nread); - n += nread; if (rc) { cdk_subpkt_free(node); return rc; } + + n += nread; *r_nbytes = n; if (!*r_ctx) *r_ctx = node; @@ -821,7 +822,7 @@ read_literal(cdk_stream_t inp, size_t pktlen, cdk_pkt_literal_t * ret_pt, int is_partial) { cdk_pkt_literal_t pt = *ret_pt; - size_t nread; + size_t nread = 0; cdk_error_t rc; if (!inp || !pt) @@ -935,7 +936,7 @@ read_new_length(cdk_stream_t inp, static cdk_error_t skip_packet(cdk_stream_t inp, size_t pktlen) { byte buf[BUFSIZE]; - size_t nread, buflen = DIM(buf); + size_t nread = 0, buflen = DIM(buf); while (pktlen > 0) { cdk_error_t rc; diff --git a/lib/opencdk/stream.c b/lib/opencdk/stream.c index a4e54926c7..496115aa3e 100644 --- a/lib/opencdk/stream.c +++ b/lib/opencdk/stream.c @@ -939,7 +939,7 @@ int cdk_stream_read(cdk_stream_t s, void *buf, size_t buflen) int cdk_stream_getc(cdk_stream_t s) { - unsigned char buf[2]; + unsigned char buf[2] = {0}; int nread; if (!s) { diff --git a/lib/x509/common.c b/lib/x509/common.c index 12fc7c7e56..38425bde4c 100644 --- a/lib/x509/common.c +++ b/lib/x509/common.c @@ -936,7 +936,7 @@ _gnutls_x509_der_encode_and_copy(ASN1_TYPE src, const char *src_name, int str) { int result; - gnutls_datum_t encoded; + gnutls_datum_t encoded = {NULL, 0}; result = _gnutls_x509_der_encode(src, src_name, &encoded, str); @@ -1240,7 +1240,7 @@ int _gnutls_x509_get_signature_algorithm(ASN1_TYPE src, const char *src_name) { int result; - gnutls_datum_t sa; + gnutls_datum_t sa = {NULL, 0}; /* Read the signature algorithm. Note that parameters are not * read. They will be read from the issuer's certificate if needed. diff --git a/lib/x509/privkey_pkcs8.c b/lib/x509/privkey_pkcs8.c index 06c9ec0bce..39728885ba 100644 --- a/lib/x509/privkey_pkcs8.c +++ b/lib/x509/privkey_pkcs8.c @@ -383,7 +383,7 @@ gnutls_x509_privkey_export_pkcs8(gnutls_x509_privkey_t key, void *output_data, size_t * output_data_size) { - ASN1_TYPE pkcs8_asn, pkey_info; + ASN1_TYPE pkcs8_asn = NULL, pkey_info; int ret; gnutls_datum_t tmp; schema_id schema; @@ -471,6 +471,8 @@ gnutls_pkcs8_info(const gnutls_datum_t * data, gnutls_x509_crt_fmt_t format, const struct pkcs_cipher_schema_st *p = NULL; struct pbkdf2_params kdf; + memset(&kdf, 0, sizeof(kdf)); + if (oid) *oid = NULL; @@ -579,7 +581,7 @@ gnutls_x509_privkey_export2_pkcs8(gnutls_x509_privkey_t key, const char *password, unsigned int flags, gnutls_datum_t * out) { - ASN1_TYPE pkcs8_asn, pkey_info; + ASN1_TYPE pkcs8_asn = NULL, pkey_info; int ret; gnutls_datum_t tmp; schema_id schema; -- cgit v1.2.1