memset, memcpy, sizeof consistency fixes

Just as with the OPENSSL_malloc calls, consistently use sizeof(*ptr)
for memset and memcpy.  Remove needless casts for those functions.
For memset, replace alternative forms of zero with 0.

Reviewed-by: Richard Levitte <levitte@openssl.org>
diff --git a/crypto/LPdir_unix.c b/crypto/LPdir_unix.c
index 3a14da1..1428cd1 100644
--- a/crypto/LPdir_unix.c
+++ b/crypto/LPdir_unix.c
@@ -83,7 +83,7 @@
             errno = ENOMEM;
             return 0;
         }
-        memset(*ctx, '\0', sizeof(**ctx));
+        memset(*ctx, 0, sizeof(**ctx));
 
         (*ctx)->dir = opendir(directory);
         if ((*ctx)->dir == NULL) {
diff --git a/crypto/LPdir_vms.c b/crypto/LPdir_vms.c
index 1e8f9e7..362918d 100644
--- a/crypto/LPdir_vms.c
+++ b/crypto/LPdir_vms.c
@@ -109,7 +109,7 @@
             errno = ENOMEM;
             return 0;
         }
-        memset(*ctx, '\0', sizeof(**ctx));
+        memset(*ctx, 0, sizeof(**ctx));
 
         strcpy((*ctx)->filespec, directory);
         strcat((*ctx)->filespec, "*.*;");
diff --git a/crypto/LPdir_win.c b/crypto/LPdir_win.c
index 78a796d..4ff514f 100644
--- a/crypto/LPdir_win.c
+++ b/crypto/LPdir_win.c
@@ -74,7 +74,7 @@
             errno = ENOMEM;
             return 0;
         }
-        memset(*ctx, '\0', sizeof(**ctx));
+        memset(*ctx, 0, sizeof(**ctx));
 
         if (directory[dirlen - 1] != '*') {
             extdirbuf = (char *)malloc(dirlen + 3);
diff --git a/crypto/asn1/a_enum.c b/crypto/asn1/a_enum.c
index 4abd80c..aed3de5 100644
--- a/crypto/asn1/a_enum.c
+++ b/crypto/asn1/a_enum.c
@@ -77,7 +77,7 @@
     if (a->length < (int)(sizeof(long) + 1)) {
         OPENSSL_free(a->data);
         if ((a->data = OPENSSL_malloc(sizeof(long) + 1)) != NULL)
-            memset((char *)a->data, 0, sizeof(long) + 1);
+            memset(a->data, 0, sizeof(long) + 1);
     }
     if (a->data == NULL) {
         ASN1err(ASN1_F_ASN1_ENUMERATED_SET, ERR_R_MALLOC_FAILURE);
diff --git a/crypto/asn1/a_int.c b/crypto/asn1/a_int.c
index 68a312b..2282978 100644
--- a/crypto/asn1/a_int.c
+++ b/crypto/asn1/a_int.c
@@ -349,7 +349,7 @@
     if (a->length < (int)(sizeof(long) + 1)) {
         OPENSSL_free(a->data);
         if ((a->data = OPENSSL_malloc(sizeof(long) + 1)) != NULL)
-            memset((char *)a->data, 0, sizeof(long) + 1);
+            memset(a->data, 0, sizeof(long) + 1);
     }
     if (a->data == NULL) {
         ASN1err(ASN1_F_ASN1_INTEGER_SET, ERR_R_MALLOC_FAILURE);
diff --git a/crypto/asn1/a_verify.c b/crypto/asn1/a_verify.c
index b452999..5b908f1 100644
--- a/crypto/asn1/a_verify.c
+++ b/crypto/asn1/a_verify.c
@@ -121,11 +121,6 @@
         ret = 0;
         goto err;
     }
-    /*
-     * we don't need to zero the 'ctx' because we just checked public
-     * information
-     */
-    /* memset(&ctx,0,sizeof(ctx)); */
     ret = 1;
  err:
     EVP_MD_CTX_cleanup(&ctx);
@@ -221,11 +216,6 @@
         ret = 0;
         goto err;
     }
-    /*
-     * we don't need to zero the 'ctx' because we just checked public
-     * information
-     */
-    /* memset(&ctx,0,sizeof(ctx)); */
     ret = 1;
  err:
     EVP_MD_CTX_cleanup(&ctx);
diff --git a/crypto/asn1/ameth_lib.c b/crypto/asn1/ameth_lib.c
index c7acb46..de70f9b 100644
--- a/crypto/asn1/ameth_lib.c
+++ b/crypto/asn1/ameth_lib.c
@@ -288,8 +288,7 @@
     if (!ameth)
         return NULL;
 
-    memset(ameth, 0, sizeof(EVP_PKEY_ASN1_METHOD));
-
+    memset(ameth, 0, sizeof(*ameth));
     ameth->pkey_id = id;
     ameth->pkey_base_id = id;
     ameth->pkey_flags = flags | ASN1_PKEY_DYNAMIC;
diff --git a/crypto/bio/b_sock.c b/crypto/bio/b_sock.c
index 39499de..e3a1ee9 100644
--- a/crypto/bio/b_sock.c
+++ b/crypto/bio/b_sock.c
@@ -484,7 +484,7 @@
     if (!BIO_get_port(p, &port))
         goto err;
 
-    memset((char *)&server, 0, sizeof(server));
+    memset(&server, 0, sizeof(server));
     server.sa_in.sin_family = AF_INET;
     server.sa_in.sin_port = htons(port);
     addrlen = sizeof(server.sa_in);
diff --git a/crypto/bio/bss_acpt.c b/crypto/bio/bss_acpt.c
index cde8da3..48435b0 100644
--- a/crypto/bio/bss_acpt.c
+++ b/crypto/bio/bss_acpt.c
@@ -140,7 +140,7 @@
     if ((ret = OPENSSL_malloc(sizeof(*ret))) == NULL)
         return (NULL);
 
-    memset(ret, 0, sizeof(BIO_ACCEPT));
+    memset(ret, 0, sizeof(*ret));
     ret->accept_sock = INVALID_SOCKET;
     ret->bind_mode = BIO_BIND_NORMAL;
     return (ret);
diff --git a/crypto/bio/bss_conn.c b/crypto/bio/bss_conn.c
index b8fa828..60f58e2 100644
--- a/crypto/bio/bss_conn.c
+++ b/crypto/bio/bss_conn.c
@@ -178,7 +178,7 @@
 
         case BIO_CONN_S_CREATE_SOCKET:
             /* now setup address */
-            memset((char *)&c->them, 0, sizeof(c->them));
+            memset(&c->them, 0, sizeof(c->them));
             c->them.sin_family = AF_INET;
             c->them.sin_port = htons((unsigned short)c->port);
             l = (unsigned long)
@@ -298,7 +298,7 @@
     ret->ip[2] = 0;
     ret->ip[3] = 0;
     ret->port = 0;
-    memset((char *)&ret->them, 0, sizeof(ret->them));
+    memset(&ret->them, 0, sizeof(ret->them));
     return (ret);
 }
 
diff --git a/crypto/bio/bss_dgram.c b/crypto/bio/bss_dgram.c
index fb1564c..53d8136 100644
--- a/crypto/bio/bss_dgram.c
+++ b/crypto/bio/bss_dgram.c
@@ -228,7 +228,7 @@
     data = OPENSSL_malloc(sizeof(*data));
     if (data == NULL)
         return 0;
-    memset(data, 0x00, sizeof(bio_dgram_data));
+    memset(data, 0, sizeof(*data));
     bi->ptr = data;
 
     bi->flags = 0;
@@ -395,7 +395,7 @@
 
     if (out != NULL) {
         clear_socket_error();
-        memset(&sa.peer, 0x00, sizeof(sa.peer));
+        memset(&sa.peer, 0, sizeof(sa.peer));
         dgram_adjust_rcv_timeout(b);
         ret = recvfrom(b->num, out, outl, 0, &sa.peer.sa, (void *)&sa.len);
         if (sizeof(sa.len.i) != sizeof(sa.len.s) && sa.len.i == 0) {
@@ -569,7 +569,7 @@
     case BIO_CTRL_DGRAM_MTU_DISCOVER:
 # if defined(OPENSSL_SYS_LINUX) && defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DO)
         addr_len = (socklen_t) sizeof(addr);
-        memset((void *)&addr, 0, sizeof(addr));
+        memset(&addr, 0, sizeof(addr));
         if (getsockname(b->num, &addr.sa, &addr_len) < 0) {
             ret = 0;
             break;
@@ -600,7 +600,7 @@
     case BIO_CTRL_DGRAM_QUERY_MTU:
 # if defined(OPENSSL_SYS_LINUX) && defined(IP_MTU)
         addr_len = (socklen_t) sizeof(addr);
-        memset((void *)&addr, 0, sizeof(addr));
+        memset(&addr, 0, sizeof(addr));
         if (getsockname(b->num, &addr.sa, &addr_len) < 0) {
             ret = 0;
             break;
@@ -693,7 +693,7 @@
             }
         } else {
             data->connected = 0;
-            memset(&(data->peer), 0x00, sizeof(data->peer));
+            memset(&data->peer, 0, sizeof(data->peer));
         }
         break;
     case BIO_CTRL_DGRAM_GET_PEER:
@@ -1028,7 +1028,7 @@
 
 #  ifdef SCTP_AUTHENTICATION_EVENT
 #   ifdef SCTP_EVENT
-    memset(&event, 0, sizeof(struct sctp_event));
+    memset(&event, 0, sizeof(event));
     event.se_assoc_id = 0;
     event.se_type = SCTP_AUTHENTICATION_EVENT;
     event.se_on = 1;
@@ -1088,7 +1088,7 @@
     data = OPENSSL_malloc(sizeof(*data));
     if (data == NULL)
         return 0;
-    memset(data, 0x00, sizeof(bio_dgram_sctp_data));
+    memset(data, 0, sizeof(*data));
 #  ifdef SCTP_PR_SCTP_NONE
     data->prinfo.pr_policy = SCTP_PR_SCTP_NONE;
 #  endif
@@ -1149,8 +1149,7 @@
         clear_socket_error();
 
         do {
-            memset(&data->rcvinfo, 0x00,
-                   sizeof(struct bio_dgram_sctp_rcvinfo));
+            memset(&data->rcvinfo, 0, sizeof(data->rcvinfo));
             iov.iov_base = out;
             iov.iov_len = outl;
             msg.msg_name = NULL;
@@ -1229,7 +1228,7 @@
 
                     /* disable sender dry event */
 #  ifdef SCTP_EVENT
-                    memset(&event, 0, sizeof(struct sctp_event));
+                    memset(&event, 0, sizeof(event));
                     event.se_assoc_id = 0;
                     event.se_type = SCTP_SENDER_DRY_EVENT;
                     event.se_on = 0;
@@ -1393,7 +1392,7 @@
      * parameters and flags.
      */
     if (in[0] != 23) {
-        memset(&handshake_sinfo, 0x00, sizeof(struct bio_dgram_sctp_sndinfo));
+        memset(&handshake_sinfo, 0, sizeof(handshake_sinfo));
 #  ifdef SCTP_SACK_IMMEDIATELY
         handshake_sinfo.snd_flags = SCTP_SACK_IMMEDIATELY;
 #  endif
@@ -1433,7 +1432,7 @@
     cmsg->cmsg_type = SCTP_SNDINFO;
     cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndinfo));
     sndinfo = (struct sctp_sndinfo *)CMSG_DATA(cmsg);
-    memset(sndinfo, 0, sizeof(struct sctp_sndinfo));
+    memset(sndinfo, 0, sizeof(*sndinfo));
     sndinfo->snd_sid = sinfo->snd_sid;
     sndinfo->snd_flags = sinfo->snd_flags;
     sndinfo->snd_ppid = sinfo->snd_ppid;
@@ -1446,7 +1445,7 @@
     cmsg->cmsg_type = SCTP_PRINFO;
     cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_prinfo));
     prinfo = (struct sctp_prinfo *)CMSG_DATA(cmsg);
-    memset(prinfo, 0, sizeof(struct sctp_prinfo));
+    memset(prinfo, 0, sizeof(*prinfo));
     prinfo->pr_policy = pinfo->pr_policy;
     prinfo->pr_value = pinfo->pr_value;
     msg.msg_controllen += CMSG_SPACE(sizeof(struct sctp_prinfo));
@@ -1456,7 +1455,7 @@
     cmsg->cmsg_type = SCTP_SNDRCV;
     cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo));
     sndrcvinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg);
-    memset(sndrcvinfo, 0, sizeof(struct sctp_sndrcvinfo));
+    memset(sndrcvinfo, 0, sizeof(*sndrcvinfo));
     sndrcvinfo->sinfo_stream = sinfo->snd_sid;
     sndrcvinfo->sinfo_flags = sinfo->snd_flags;
 #   ifdef __FreeBSD__
@@ -1553,7 +1552,7 @@
             ret = -1;
             break;
         }
-        memset(authkey, 0x00, sockopt_len);
+        memset(authkey, 0, sockopt_len);
         authkey->sca_keynumber = authkeyid.scact_keynumber + 1;
 #  ifndef __FreeBSD__
         /*
@@ -1750,7 +1749,7 @@
 
     /* set sender dry event */
 #  ifdef SCTP_EVENT
-    memset(&event, 0, sizeof(struct sctp_event));
+    memset(&event, 0, sizeof(event));
     event.se_assoc_id = 0;
     event.se_type = SCTP_SENDER_DRY_EVENT;
     event.se_on = 1;
@@ -1773,7 +1772,7 @@
         return -1;
 
     /* peek for notification */
-    memset(&snp, 0x00, sizeof(union sctp_notification));
+    memset(&snp, 0, sizeof(snp));
     iov.iov_base = (char *)&snp;
     iov.iov_len = sizeof(union sctp_notification);
     msg.msg_name = NULL;
@@ -1795,7 +1794,7 @@
 
     /* if we find a notification, process it and try again if necessary */
     while (msg.msg_flags & MSG_NOTIFICATION) {
-        memset(&snp, 0x00, sizeof(union sctp_notification));
+        memset(&snp, 0, sizeof(snp));
         iov.iov_base = (char *)&snp;
         iov.iov_len = sizeof(union sctp_notification);
         msg.msg_name = NULL;
@@ -1820,7 +1819,7 @@
 
             /* disable sender dry event */
 #  ifdef SCTP_EVENT
-            memset(&event, 0, sizeof(struct sctp_event));
+            memset(&event, 0, sizeof(event));
             event.se_assoc_id = 0;
             event.se_type = SCTP_SENDER_DRY_EVENT;
             event.se_on = 0;
@@ -1854,7 +1853,7 @@
                                        (void *)&snp);
 
         /* found notification, peek again */
-        memset(&snp, 0x00, sizeof(union sctp_notification));
+        memset(&snp, 0, sizeof(snp));
         iov.iov_base = (char *)&snp;
         iov.iov_len = sizeof(union sctp_notification);
         msg.msg_name = NULL;
@@ -1900,7 +1899,7 @@
 
     /* Check if there are any messages waiting to be read */
     do {
-        memset(&snp, 0x00, sizeof(union sctp_notification));
+        memset(&snp, 0, sizeof(snp));
         iov.iov_base = (char *)&snp;
         iov.iov_len = sizeof(union sctp_notification);
         msg.msg_name = NULL;
@@ -1923,7 +1922,7 @@
                 dgram_sctp_handle_auth_free_key_event(b, &snp);
 #  endif
 
-            memset(&snp, 0x00, sizeof(union sctp_notification));
+            memset(&snp, 0, sizeof(snp));
             iov.iov_base = (char *)&snp;
             iov.iov_len = sizeof(union sctp_notification);
             msg.msg_name = NULL;
diff --git a/crypto/bn/bn_blind.c b/crypto/bn/bn_blind.c
index 9338cdd..52f74d1 100644
--- a/crypto/bn/bn_blind.c
+++ b/crypto/bn/bn_blind.c
@@ -141,7 +141,7 @@
         BNerr(BN_F_BN_BLINDING_NEW, ERR_R_MALLOC_FAILURE);
         return (NULL);
     }
-    memset(ret, 0, sizeof(BN_BLINDING));
+    memset(ret, 0, sizeof(*ret));
     if (A != NULL) {
         if ((ret->A = BN_dup(A)) == NULL)
             goto err;
diff --git a/crypto/bn/bn_intern.c b/crypto/bn/bn_intern.c
index 139d11b..c3ea561 100644
--- a/crypto/bn/bn_intern.c
+++ b/crypto/bn/bn_intern.c
@@ -211,8 +211,8 @@
     if (in->top > size)
         return 0;
 
-    memset(out, 0, sizeof(BN_ULONG) * size);
-    memcpy(out, in->d, sizeof(BN_ULONG) * in->top);
+    memset(out, 0, sizeof(*out) * size);
+    memcpy(out, in->d, sizeof(*out) * in->top);
     return 1;
 }
 
diff --git a/crypto/bn/bn_lcl.h b/crypto/bn/bn_lcl.h
index a24ae7f..196df7e 100644
--- a/crypto/bn/bn_lcl.h
+++ b/crypto/bn/bn_lcl.h
@@ -167,10 +167,10 @@
                          * *genuinely* constant variables that aren't mutable \
                          * wouldn't be constructed with top!=dmax. */ \
                         BN_ULONG *_not_const; \
-                        memcpy(&_not_const, &_bnum1->d, sizeof(BN_ULONG*)); \
+                        memcpy(&_not_const, &_bnum1->d, sizeof(_not_const)); \
                         RAND_bytes(&_tmp_char, 1); /* Debug only - safe to ignore error return */\
-                        memset((unsigned char *)(_not_const + _bnum1->top), _tmp_char, \
-                                (_bnum1->dmax - _bnum1->top) * sizeof(BN_ULONG)); \
+                        memset(_not_const + _bnum1->top, _tmp_char, \
+                                sizeof(*_not_const) * (_bnum1->dmax - _bnum1->top)); \
                 } \
         } while(0)
 #   ifdef BN_DEBUG_TRIX
diff --git a/crypto/bn/bn_lib.c b/crypto/bn/bn_lib.c
index 6fc0e39..fec70a5 100644
--- a/crypto/bn/bn_lib.c
+++ b/crypto/bn/bn_lib.c
@@ -260,7 +260,7 @@
 
 void BN_init(BIGNUM *a)
 {
-    memset(a, 0, sizeof(BIGNUM));
+    memset(a, 0, sizeof(*a));
     bn_check_top(a);
 }
 
@@ -311,7 +311,7 @@
      * function - what's important is constant time operation (we're not
      * actually going to use the data)
      */
-    memset(a, 0, sizeof(BN_ULONG) * words);
+    memset(a, 0, sizeof(*a) * words);
 #endif
 
 #if 1
@@ -355,7 +355,7 @@
         }
     }
 #else
-    memset(A, 0, sizeof(BN_ULONG) * words);
+    memset(A, 0, sizeof(*A) * words);
     memcpy(A, b->d, sizeof(b->d[0]) * b->top);
 #endif
 
@@ -492,7 +492,7 @@
 {
     bn_check_top(a);
     if (a->d != NULL)
-        memset(a->d, 0, a->dmax * sizeof(a->d[0]));
+        memset(a->d, 0, sizeof(*a->d) * a->dmax);
     a->top = 0;
     a->neg = 0;
 }
diff --git a/crypto/bn/bn_mont.c b/crypto/bn/bn_mont.c
index d07afcc..613a384 100644
--- a/crypto/bn/bn_mont.c
+++ b/crypto/bn/bn_mont.c
@@ -196,7 +196,7 @@
     rp = r->d;
 
     /* clear the top words of T */
-    memset(&(rp[r->top]), 0, (max - r->top) * sizeof(BN_ULONG));
+    memset(&rp[r->top], 0, sizeof(*rp) * (max - r->top));
 
     r->top = max;
     n0 = mont->n0[0];
diff --git a/crypto/bn/bn_mul.c b/crypto/bn/bn_mul.c
index 9b66e66..f3b4859 100644
--- a/crypto/bn/bn_mul.c
+++ b/crypto/bn/bn_mul.c
@@ -458,7 +458,7 @@
         if (!zero)
             bn_mul_comba4(&(t[n2]), t, &(t[n]));
         else
-            memset(&(t[n2]), 0, 8 * sizeof(BN_ULONG));
+            memset(&t[n2], 0, sizeof(*t) * 8);
 
         bn_mul_comba4(r, a, b);
         bn_mul_comba4(&(r[n2]), &(a[n]), &(b[n]));
@@ -468,7 +468,7 @@
         if (!zero)
             bn_mul_comba8(&(t[n2]), t, &(t[n]));
         else
-            memset(&(t[n2]), 0, 16 * sizeof(BN_ULONG));
+            memset(&t[n2], 0, sizeof(*t) * 16);
 
         bn_mul_comba8(r, a, b);
         bn_mul_comba8(&(r[n2]), &(a[n]), &(b[n]));
@@ -479,7 +479,7 @@
         if (!zero)
             bn_mul_recursive(&(t[n2]), t, &(t[n]), n, 0, 0, p);
         else
-            memset(&(t[n2]), 0, n2 * sizeof(BN_ULONG));
+            memset(&t[n2], 0, sizeof(*t) * n2);
         bn_mul_recursive(r, a, b, n, 0, 0, p);
         bn_mul_recursive(&(r[n2]), &(a[n]), &(b[n]), n, dna, dnb, p);
     }
@@ -584,14 +584,14 @@
         bn_mul_comba4(&(t[n2]), t, &(t[n]));
         bn_mul_comba4(r, a, b);
         bn_mul_normal(&(r[n2]), &(a[n]), tn, &(b[n]), tn);
-        memset(&(r[n2 + tn * 2]), 0, sizeof(BN_ULONG) * (n2 - tn * 2));
+        memset(&r[n2 + tn * 2], 0, sizeof(*r) * (n2 - tn * 2));
     } else
 # endif
     if (n == 8) {
         bn_mul_comba8(&(t[n2]), t, &(t[n]));
         bn_mul_comba8(r, a, b);
         bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);
-        memset(&(r[n2 + tna + tnb]), 0, sizeof(BN_ULONG) * (n2 - tna - tnb));
+        memset(&r[n2 + tna + tnb], 0, sizeof(*r) * (n2 - tna - tnb));
     } else {
         p = &(t[n2 * 2]);
         bn_mul_recursive(&(t[n2]), t, &(t[n]), n, 0, 0, p);
@@ -607,7 +607,7 @@
         if (j == 0) {
             bn_mul_recursive(&(r[n2]), &(a[n]), &(b[n]),
                              i, tna - i, tnb - i, p);
-            memset(&(r[n2 + i * 2]), 0, sizeof(BN_ULONG) * (n2 - i * 2));
+            memset(&r[n2 + i * 2], 0, sizeof(*r) * (n2 - i * 2));
         } else if (j > 0) {     /* eg, n == 16, i == 8 and tn == 11 */
             bn_mul_part_recursive(&(r[n2]), &(a[n]), &(b[n]),
                                   i, tna - i, tnb - i, p);
@@ -615,7 +615,7 @@
                    sizeof(BN_ULONG) * (n2 - tna - tnb));
         } else {                /* (j < 0) eg, n == 16, i == 8 and tn == 5 */
 
-            memset(&(r[n2]), 0, sizeof(BN_ULONG) * n2);
+            memset(&r[n2], 0, sizeof(*r) * n2);
             if (tna < BN_MUL_RECURSIVE_SIZE_NORMAL
                 && tnb < BN_MUL_RECURSIVE_SIZE_NORMAL) {
                 bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);
diff --git a/crypto/bn/bn_shift.c b/crypto/bn/bn_shift.c
index b6cd0d9..9895646 100644
--- a/crypto/bn/bn_shift.c
+++ b/crypto/bn/bn_shift.c
@@ -154,10 +154,7 @@
             t[nw + i + 1] |= (l >> rb) & BN_MASK2;
             t[nw + i] = (l << lb) & BN_MASK2;
         }
-    memset(t, 0, nw * sizeof(t[0]));
-    /*
-     * for (i=0; i<nw; i++) t[i]=0;
-     */
+    memset(t, 0, sizeof(*t) * nw);
     r->top = a->top + nw + 1;
     bn_correct_top(r);
     bn_check_top(r);
diff --git a/crypto/bn/bn_sqr.c b/crypto/bn/bn_sqr.c
index f794c10..aa31f6e 100644
--- a/crypto/bn/bn_sqr.c
+++ b/crypto/bn/bn_sqr.c
@@ -238,7 +238,7 @@
     if (!zero)
         bn_sqr_recursive(&(t[n2]), t, n, p);
     else
-        memset(&(t[n2]), 0, n2 * sizeof(BN_ULONG));
+        memset(&t[n2], 0, sizeof(*t) * n2);
     bn_sqr_recursive(r, a, n, p);
     bn_sqr_recursive(&(r[n2]), &(a[n]), n, p);
 
diff --git a/crypto/comp/comp_lib.c b/crypto/comp/comp_lib.c
index 9feb0af..42d9936 100644
--- a/crypto/comp/comp_lib.c
+++ b/crypto/comp/comp_lib.c
@@ -12,7 +12,7 @@
         /* ZZZZZZZZZZZZZZZZ */
         return (NULL);
     }
-    memset(ret, 0, sizeof(COMP_CTX));
+    memset(ret, 0, sizeof(*ret));
     ret->meth = meth;
     if ((ret->meth->init != NULL) && !ret->meth->init(ret)) {
         OPENSSL_free(ret);
diff --git a/crypto/dso/dso_lib.c b/crypto/dso/dso_lib.c
index a0e711c..c555398 100644
--- a/crypto/dso/dso_lib.c
+++ b/crypto/dso/dso_lib.c
@@ -109,7 +109,7 @@
         DSOerr(DSO_F_DSO_NEW_METHOD, ERR_R_MALLOC_FAILURE);
         return (NULL);
     }
-    memset(ret, 0, sizeof(DSO));
+    memset(ret, 0, sizeof(*ret));
     ret->meth_data = sk_void_new_null();
     if (ret->meth_data == NULL) {
         /* sk_new doesn't generate any errors so we do */
diff --git a/crypto/dso/dso_win32.c b/crypto/dso/dso_win32.c
index bd96c5d..81c983c 100644
--- a/crypto/dso/dso_win32.c
+++ b/crypto/dso/dso_win32.c
@@ -310,7 +310,7 @@
         return (NULL);
     }
 
-    memset(result, 0, sizeof(struct file_st));
+    memset(result, 0, sizeof(*result));
     position = IN_DEVICE;
 
     if ((filename[0] == '\\' && filename[1] == '\\')
diff --git a/crypto/ec/ecp_nistp224.c b/crypto/ec/ecp_nistp224.c
index c79e6da..0e40db4 100644
--- a/crypto/ec/ecp_nistp224.c
+++ b/crypto/ec/ecp_nistp224.c
@@ -317,7 +317,7 @@
     unsigned num_bytes;
 
     /* BN_bn2bin eats leading zeroes */
-    memset(b_out, 0, sizeof b_out);
+    memset(b_out, 0, sizeof(b_out));
     num_bytes = BN_num_bytes(bn);
     if (num_bytes > sizeof b_out) {
         ECerr(EC_F_BN_TO_FELEM, EC_R_BIGNUM_OUT_OF_RANGE);
@@ -1069,8 +1069,8 @@
 {
     unsigned i, j;
     limb *outlimbs = &out[0][0];
-    memset(outlimbs, 0, 3 * sizeof(felem));
 
+    memset(out 0, sizeof(out));
     for (i = 0; i < size; i++) {
         const limb *inlimbs = &pre_comp[i][0][0];
         u64 mask = i ^ idx;
@@ -1113,7 +1113,7 @@
     u8 sign, digit;
 
     /* set nq to the point at infinity */
-    memset(nq, 0, 3 * sizeof(felem));
+    memset(nq, 0, sizeof(nq));
 
     /*
      * Loop over all scalars msb-to-lsb, interleaving additions of multiples
@@ -1390,7 +1390,7 @@
     BIGNUM *x, *y, *z, *tmp_scalar;
     felem_bytearray g_secret;
     felem_bytearray *secrets = NULL;
-    felem(*pre_comp)[17][3] = NULL;
+    felem (*pre_comp)[17][3] = NULL;
     felem *tmp_felems = NULL;
     felem_bytearray tmp;
     unsigned num_bytes;
@@ -1457,11 +1457,11 @@
              */
             mixed = 1;
         }
-        secrets = OPENSSL_malloc(num_points * sizeof(felem_bytearray));
-        pre_comp = OPENSSL_malloc(num_points * 17 * 3 * sizeof(felem));
+        secrets = OPENSSL_malloc(sizeof(*secrets) * num_points);
+        pre_comp = OPENSSL_malloc(sizeof(*pre_comp) * num_points);
         if (mixed)
             tmp_felems =
-                OPENSSL_malloc((num_points * 17 + 1) * sizeof(felem));
+                OPENSSL_malloc(sizeof(felem) * (num_points * 17 + 1));
         if ((secrets == NULL) || (pre_comp == NULL)
             || (mixed && (tmp_felems == NULL))) {
             ECerr(EC_F_EC_GFP_NISTP224_POINTS_MUL, ERR_R_MALLOC_FAILURE);
@@ -1472,8 +1472,8 @@
          * we treat NULL scalars as 0, and NULL points as points at infinity,
          * i.e., they contribute nothing to the linear combination
          */
-        memset(secrets, 0, num_points * sizeof(felem_bytearray));
-        memset(pre_comp, 0, num_points * 17 * 3 * sizeof(felem));
+        memset(secrets, 0, sizeof(*secrets) * num_points);
+        memset(pre_comp, 0, sizeof(*pre_comp) * num_points);
         for (i = 0; i < num_points; ++i) {
             if (i == num)
                 /* the generator */
@@ -1533,7 +1533,7 @@
 
     /* the scalar for the generator */
     if ((scalar != NULL) && (have_pre_comp)) {
-        memset(g_secret, 0, sizeof g_secret);
+        memset(g_secret, 0, sizeof(g_secret));
         /* reduce scalar to 0 <= scalar < 2^224 */
         if ((BN_num_bits(scalar) > 224) || (BN_is_negative(scalar))) {
             /*
diff --git a/crypto/ec/ecp_nistp256.c b/crypto/ec/ecp_nistp256.c
index 6ec5692..b4cd24d 100644
--- a/crypto/ec/ecp_nistp256.c
+++ b/crypto/ec/ecp_nistp256.c
@@ -156,7 +156,7 @@
     unsigned num_bytes;
 
     /* BN_bn2bin eats leading zeroes */
-    memset(b_out, 0, sizeof b_out);
+    memset(b_out, 0, sizeof(b_out));
     num_bytes = BN_num_bytes(bn);
     if (num_bytes > sizeof b_out) {
         ECerr(EC_F_BN_TO_FELEM, EC_R_BIGNUM_OUT_OF_RANGE);
@@ -1624,7 +1624,8 @@
 {
     unsigned i, j;
     u64 *outlimbs = &out[0][0];
-    memset(outlimbs, 0, 3 * sizeof(smallfelem));
+
+    memset(out, 0, sizeof(out));
 
     for (i = 0; i < size; i++) {
         const u64 *inlimbs = (u64 *)&pre_comp[i][0][0];
@@ -1668,7 +1669,7 @@
     u8 sign, digit;
 
     /* set nq to the point at infinity */
-    memset(nq, 0, 3 * sizeof(felem));
+    memset(nq, 0, sizeof(nq));
 
     /*
      * Loop over all scalars msb-to-lsb, interleaving additions of multiples
@@ -2005,7 +2006,7 @@
     BIGNUM *x, *y, *z, *tmp_scalar;
     felem_bytearray g_secret;
     felem_bytearray *secrets = NULL;
-    smallfelem(*pre_comp)[17][3] = NULL;
+    smallfelem (*pre_comp)[17][3] = NULL;
     smallfelem *tmp_smallfelems = NULL;
     felem_bytearray tmp;
     unsigned i, num_bytes;
@@ -2072,11 +2073,11 @@
              */
             mixed = 1;
         }
-        secrets = OPENSSL_malloc(num_points * sizeof(felem_bytearray));
-        pre_comp = OPENSSL_malloc(num_points * 17 * 3 * sizeof(smallfelem));
+        secrets = OPENSSL_malloc(sizeof(*secrets) * num_points);
+        pre_comp = OPENSSL_malloc(sizeof(*pre_comp) * num_points);
         if (mixed)
             tmp_smallfelems =
-                OPENSSL_malloc((num_points * 17 + 1) * sizeof(smallfelem));
+              OPENSSL_malloc(sizeof(*tmp_smallfelems) * (num_points * 17 + 1));
         if ((secrets == NULL) || (pre_comp == NULL)
             || (mixed && (tmp_smallfelems == NULL))) {
             ECerr(EC_F_EC_GFP_NISTP256_POINTS_MUL, ERR_R_MALLOC_FAILURE);
@@ -2087,8 +2088,8 @@
          * we treat NULL scalars as 0, and NULL points as points at infinity,
          * i.e., they contribute nothing to the linear combination
          */
-        memset(secrets, 0, num_points * sizeof(felem_bytearray));
-        memset(pre_comp, 0, num_points * 17 * 3 * sizeof(smallfelem));
+        memset(secrets, 0, sizeof(*secrets) * num_points);
+        memset(pre_comp, 0, sizeof(*pre_comp) * num_points);
         for (i = 0; i < num_points; ++i) {
             if (i == num)
                 /*
diff --git a/crypto/ec/ecp_nistp521.c b/crypto/ec/ecp_nistp521.c
index e208a83..6e572f1 100644
--- a/crypto/ec/ecp_nistp521.c
+++ b/crypto/ec/ecp_nistp521.c
@@ -185,7 +185,7 @@
     unsigned num_bytes;
 
     /* BN_bn2bin eats leading zeroes */
-    memset(b_out, 0, sizeof b_out);
+    memset(b_out, 0, sizeof(b_out));
     num_bytes = BN_num_bytes(bn);
     if (num_bytes > sizeof b_out) {
         ECerr(EC_F_BN_TO_FELEM, EC_R_BIGNUM_OUT_OF_RANGE);
@@ -1470,7 +1470,8 @@
 {
     unsigned i, j;
     limb *outlimbs = &out[0][0];
-    memset(outlimbs, 0, 3 * sizeof(felem));
+
+    memset(out, 0, sizeof(out));
 
     for (i = 0; i < size; i++) {
         const limb *inlimbs = &pre_comp[i][0][0];
@@ -1513,7 +1514,7 @@
     u8 sign, digit;
 
     /* set nq to the point at infinity */
-    memset(nq, 0, 3 * sizeof(felem));
+    memset(nq, 0, sizeof(nq));
 
     /*
      * Loop over all scalars msb-to-lsb, interleaving additions of multiples
@@ -1834,7 +1835,7 @@
     BIGNUM *x, *y, *z, *tmp_scalar;
     felem_bytearray g_secret;
     felem_bytearray *secrets = NULL;
-    felem(*pre_comp)[17][3] = NULL;
+    felem (*pre_comp)[17][3] = NULL;
     felem *tmp_felems = NULL;
     felem_bytearray tmp;
     unsigned i, num_bytes;
@@ -1901,11 +1902,11 @@
              */
             mixed = 1;
         }
-        secrets = OPENSSL_malloc(num_points * sizeof(felem_bytearray));
-        pre_comp = OPENSSL_malloc(num_points * 17 * 3 * sizeof(felem));
+        secrets = OPENSSL_malloc(sizeof(*secrets) * num_points);
+        pre_comp = OPENSSL_malloc(sizeof(*pre_comp) * num_points);
         if (mixed)
             tmp_felems =
-                OPENSSL_malloc((num_points * 17 + 1) * sizeof(felem));
+                OPENSSL_malloc(sizeof(*tmp_felemts) * (num_points * 17 + 1));
         if ((secrets == NULL) || (pre_comp == NULL)
             || (mixed && (tmp_felems == NULL))) {
             ECerr(EC_F_EC_GFP_NISTP521_POINTS_MUL, ERR_R_MALLOC_FAILURE);
@@ -1916,8 +1917,8 @@
          * we treat NULL scalars as 0, and NULL points as points at infinity,
          * i.e., they contribute nothing to the linear combination
          */
-        memset(secrets, 0, num_points * sizeof(felem_bytearray));
-        memset(pre_comp, 0, num_points * 17 * 3 * sizeof(felem));
+        memset(secrets, 0, sizeof(*secrets) * num_points);
+        memset(pre_comp, 0, sizseof(*pre_comp) * num_points);
         for (i = 0; i < num_points; ++i) {
             if (i == num)
                 /*
diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c
index d801ae8..49a3989 100644
--- a/crypto/engine/eng_cryptodev.c
+++ b/crypto/engine/eng_cryptodev.c
@@ -478,7 +478,7 @@
         return (0);
     }
 
-    memset(sess, 0, sizeof(struct session_op));
+    memset(sess, 0, sizeof(*sess));
 
     if ((state->d_fd = get_dev_crypto()) < 0)
         return (0);
@@ -770,7 +770,7 @@
         return (0);
     }
 
-    memset(state, 0, sizeof(struct dev_crypto_state));
+    memset(state, 0, sizeof(*state));
 
     if ((state->d_fd = get_dev_crypto()) < 0) {
         printf("cryptodev_digest_init: Can't get Dev \n");
@@ -1115,7 +1115,7 @@
         return (ret);
     }
 
-    memset(&kop, 0, sizeof kop);
+    memset(&kop, 0, sizeof(kop));
     kop.crk_op = CRK_MOD_EXP;
 
     /* inputs: a^p % m */
@@ -1166,7 +1166,7 @@
         return (0);
     }
 
-    memset(&kop, 0, sizeof kop);
+    memset(&kop, 0, sizeof(kop));
     kop.crk_op = CRK_MOD_EXP_CRT;
     /* inputs: rsa->p rsa->q I rsa->dmp1 rsa->dmq1 rsa->iqmp */
     if (bn2crparam(rsa->p, &kop.crk_param[0]))
@@ -1269,7 +1269,7 @@
         goto err;
     }
 
-    memset(&kop, 0, sizeof kop);
+    memset(&kop, 0, sizeof(kop));
     kop.crk_op = CRK_DSA_SIGN;
 
     /* inputs: dgst dsa->p dsa->q dsa->g dsa->priv_key */
@@ -1309,7 +1309,7 @@
     struct crypt_kop kop;
     int dsaret = 1;
 
-    memset(&kop, 0, sizeof kop);
+    memset(&kop, 0, sizeof(kop));
     kop.crk_op = CRK_DSA_VERIFY;
 
     /* inputs: dgst dsa->p dsa->q dsa->g dsa->pub_key sig->r sig->s */
@@ -1382,7 +1382,7 @@
 
     keylen = BN_num_bits(dh->p);
 
-    memset(&kop, 0, sizeof kop);
+    memset(&kop, 0, sizeof(kop));
     kop.crk_op = CRK_DH_COMPUTE_KEY;
 
     /* inputs: dh->priv_key pub_key dh->p key */
diff --git a/crypto/engine/eng_dyn.c b/crypto/engine/eng_dyn.c
index ed1c220..06a7018 100644
--- a/crypto/engine/eng_dyn.c
+++ b/crypto/engine/eng_dyn.c
@@ -208,7 +208,7 @@
         ENGINEerr(ENGINE_F_DYNAMIC_SET_DATA_CTX, ERR_R_MALLOC_FAILURE);
         return 0;
     }
-    memset(c, 0, sizeof(dynamic_data_ctx));
+    memset(c, 0, sizeof(*c));
     c->dynamic_dso = NULL;
     c->v_check = NULL;
     c->bind_engine = NULL;
diff --git a/crypto/engine/eng_lib.c b/crypto/engine/eng_lib.c
index 3bf06bb..c477c7e 100644
--- a/crypto/engine/eng_lib.c
+++ b/crypto/engine/eng_lib.c
@@ -71,7 +71,7 @@
         ENGINEerr(ENGINE_F_ENGINE_NEW, ERR_R_MALLOC_FAILURE);
         return NULL;
     }
-    memset(ret, 0, sizeof(ENGINE));
+    memset(ret, 0, sizeof(*ret));
     ret->struct_ref = 1;
     engine_ref_debug(ret, 0, 1)
         CRYPTO_new_ex_data(CRYPTO_EX_INDEX_ENGINE, ret, &ret->ex_data);
diff --git a/crypto/evp/bio_ok.c b/crypto/evp/bio_ok.c
index 9a65a9d..7a38cd9 100644
--- a/crypto/evp/bio_ok.c
+++ b/crypto/evp/bio_ok.c
@@ -337,8 +337,7 @@
         n = (inl + ctx->buf_len > OK_BLOCK_SIZE + OK_BLOCK_BLOCK) ?
             (int)(OK_BLOCK_SIZE + OK_BLOCK_BLOCK - ctx->buf_len) : inl;
 
-        memcpy((unsigned char *)(&(ctx->buf[ctx->buf_len])),
-               (unsigned char *)in, n);
+        memcpy(&ctx->buf[ctx->buf_len], in, n);
         ctx->buf_len += n;
         inl -= n;
         in += n;
diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c
index 04ab3a0..c7856c6 100644
--- a/crypto/evp/digest.c
+++ b/crypto/evp/digest.c
@@ -119,7 +119,7 @@
 
 void EVP_MD_CTX_init(EVP_MD_CTX *ctx)
 {
-    memset(ctx, '\0', sizeof(*ctx));
+    memset(ctx, 0, sizeof(*ctx));
 }
 
 EVP_MD_CTX *EVP_MD_CTX_create(void)
@@ -360,7 +360,7 @@
          */
         ENGINE_finish(ctx->engine);
 #endif
-    memset(ctx, '\0', sizeof(*ctx));
+    memset(ctx, 0, sizeof(*ctx));
 
     return 1;
 }
diff --git a/crypto/evp/e_null.c b/crypto/evp/e_null.c
index 488add4..a585128 100644
--- a/crypto/evp/e_null.c
+++ b/crypto/evp/e_null.c
@@ -86,7 +86,6 @@
 static int null_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
                          const unsigned char *iv, int enc)
 {
-    /*      memset(&(ctx->c),0,sizeof(ctx->c)); */
     return 1;
 }
 
@@ -94,6 +93,6 @@
                        const unsigned char *in, size_t inl)
 {
     if (in != out)
-        memcpy((char *)out, (const char *)in, inl);
+        memcpy(out, in, inl);
     return 1;
 }
diff --git a/crypto/evp/evp_enc.c b/crypto/evp/evp_enc.c
index 4dfc159..242874c 100644
--- a/crypto/evp/evp_enc.c
+++ b/crypto/evp/evp_enc.c
@@ -70,8 +70,7 @@
 
 void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx)
 {
-    memset(ctx, 0, sizeof(EVP_CIPHER_CTX));
-    /* ctx->cipher=NULL; */
+    memset(ctx, 0, sizeof(*ctx));
 }
 
 EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void)
@@ -546,7 +545,7 @@
          */
         ENGINE_finish(c->engine);
 #endif
-    memset(c, 0, sizeof(EVP_CIPHER_CTX));
+    memset(c, 0, sizeof(*c));
     return 1;
 }
 
diff --git a/crypto/evp/pmeth_lib.c b/crypto/evp/pmeth_lib.c
index 397d342..eeee53a 100644
--- a/crypto/evp/pmeth_lib.c
+++ b/crypto/evp/pmeth_lib.c
@@ -202,7 +202,7 @@
     if (!pmeth)
         return NULL;
 
-    memset(pmeth, 0, sizeof(EVP_PKEY_METHOD));
+    memset(pmeth, 0, sizeof(*pmeth));
 
     pmeth->pkey_id = id;
     pmeth->flags = flags | EVP_PKEY_FLAG_DYNAMIC;
diff --git a/crypto/jpake/jpake.c b/crypto/jpake/jpake.c
index b494ac0..a8aa87d 100644
--- a/crypto/jpake/jpake.c
+++ b/crypto/jpake/jpake.c
@@ -107,7 +107,7 @@
     OPENSSL_free(ctx->p.peer_name);
     OPENSSL_free(ctx->p.name);
 
-    memset(ctx, '\0', sizeof(*ctx));
+    memset(ctx, 0, sizeof(*ctx));
 }
 
 JPAKE_CTX *JPAKE_CTX_new(const char *name, const char *peer_name,
diff --git a/crypto/md2/md2_dgst.c b/crypto/md2/md2_dgst.c
index e206b3f..70c19fb 100644
--- a/crypto/md2/md2_dgst.c
+++ b/crypto/md2/md2_dgst.c
@@ -122,9 +122,9 @@
 int MD2_Init(MD2_CTX *c)
 {
     c->num = 0;
-    memset(c->state, 0, sizeof c->state);
-    memset(c->cksm, 0, sizeof c->cksm);
-    memset(c->data, 0, sizeof c->data);
+    memset(c->state, 0, sizeof(c->state));
+    memset(c->cksm, 0, sizeof(c->cksm));
+    memset(c->data, 0, sizeof(c->data));
     return 1;
 }
 
@@ -219,6 +219,6 @@
 
     for (i = 0; i < 16; i++)
         md[i] = (UCHAR) (p1[i] & 0xff);
-    memset((char *)&c, 0, sizeof(c));
+    memset(&c, 0, sizeof(c));
     return 1;
 }
diff --git a/crypto/modes/ocb128.c b/crypto/modes/ocb128.c
index 79b7862..ed48460 100644
--- a/crypto/modes/ocb128.c
+++ b/crypto/modes/ocb128.c
@@ -226,9 +226,7 @@
 int CRYPTO_ocb128_init(OCB128_CONTEXT *ctx, void *keyenc, void *keydec,
                        block128_f encrypt, block128_f decrypt)
 {
-    /* Clear everything to NULLs */
     memset(ctx, 0, sizeof(*ctx));
-
     ctx->l_index = 0;
     ctx->max_l_index = 1;
     ctx->l = OPENSSL_malloc(ctx->max_l_index * 16);
@@ -374,8 +372,8 @@
         ocb_block16_xor(&ctx->offset_aad, &ctx->l_star, &ctx->offset_aad);
 
         /* CipherInput = (A_* || 1 || zeros(127-bitlen(A_*))) xor Offset_* */
-        memset((void *)&tmp1, 0, 16);
-        memcpy((void *)&tmp1, aad + (num_blocks * 16), last_len);
+        memset(&tmp1, 0, 16);
+        memcpy(&tmp1, aad + (num_blocks * 16), last_len);
         ((unsigned char *)&tmp1)[last_len] = 0x80;
         ocb_block16_xor(&ctx->offset_aad, &tmp1, &tmp2);
 
@@ -453,8 +451,8 @@
                       out + (num_blocks * 16));
 
         /* Checksum_* = Checksum_m xor (P_* || 1 || zeros(127-bitlen(P_*))) */
-        memset((void *)&tmp1, 0, 16);
-        memcpy((void *)&tmp1, in + (len / 16) * 16, last_len);
+        memset(&tmp1, 0, 16);
+        memcpy(&tmp1, in + (len / 16) * 16, last_len);
         ((unsigned char *)(&tmp1))[last_len] = 0x80;
         ocb_block16_xor(&ctx->checksum, &tmp1, &ctx->checksum);
     }
@@ -526,8 +524,8 @@
                       out + (num_blocks * 16));
 
         /* Checksum_* = Checksum_m xor (P_* || 1 || zeros(127-bitlen(P_*))) */
-        memset((void *)&tmp1, 0, 16);
-        memcpy((void *)&tmp1, out + (len / 16) * 16, last_len);
+        memset(&tmp1, 0, 16);
+        memcpy(&tmp1, out + (len / 16) * 16, last_len);
         ((unsigned char *)(&tmp1))[last_len] = 0x80;
         ocb_block16_xor(&ctx->checksum, &tmp1, &ctx->checksum);
     }
diff --git a/crypto/pqueue/pqueue.c b/crypto/pqueue/pqueue.c
index d66efe1..1378abc 100644
--- a/crypto/pqueue/pqueue.c
+++ b/crypto/pqueue/pqueue.c
@@ -91,7 +91,7 @@
     if (pq == NULL)
         return NULL;
 
-    memset(pq, 0x00, sizeof(pqueue_s));
+    memset(pq, 0, sizeof(*pq));
     return pq;
 }
 
diff --git a/crypto/rsa/rsa_lib.c b/crypto/rsa/rsa_lib.c
index 7d8fd39..f4aaa29 100644
--- a/crypto/rsa/rsa_lib.c
+++ b/crypto/rsa/rsa_lib.c
@@ -293,14 +293,14 @@
         RSAerr(RSA_F_RSA_MEMORY_LOCK, ERR_R_MALLOC_FAILURE);
         return (0);
     }
-    memset(p, 0, (off + j) * sizeof(BN_ULONG));
+    memset(p, 0, sizeof(*p) * (off + j));
     bn = (BIGNUM *)p;
     ul = (BN_ULONG *)&(p[off]);
     for (i = 0; i < 6; i++) {
         b = *(t[i]);
         *(t[i]) = bn_array_el(bn, i);
-        memcpy((char *)bn_array_el(bn, i), (char *)b, bn_sizeof_BIGNUM());
-        memcpy((char *)ul, bn_get_words(b), sizeof(BN_ULONG) * bn_get_top(b));
+        memcpy(bn_array_el(bn, i), b, bn_sizeof_BIGNUM());
+        memcpy(ul, bn_get_words(b), sizeof(*ul) * bn_get_top(b));
         bn_set_static_words(bn_array_el(bn, i), ul, bn_get_top(b));
         ul += bn_get_top(b);
         BN_clear_free(b);
diff --git a/crypto/sha/sha512.c b/crypto/sha/sha512.c
index f934c74..c58cc1b 100644
--- a/crypto/sha/sha512.c
+++ b/crypto/sha/sha512.c
@@ -107,9 +107,11 @@
 
     p[n] = 0x80;                /* There always is a room for one */
     n++;
-    if (n > (sizeof(c->u) - 16))
-        memset(p + n, 0, sizeof(c->u) - n), n = 0,
-            sha512_block_data_order(c, p, 1);
+    if (n > (sizeof(c->u) - 16)) {
+        memset(p + n, 0, sizeof(c->u) - n);
+        n = 0;
+        sha512_block_data_order(c, p, 1);
+    }
 
     memset(p + n, 0, sizeof(c->u) - 16 - n);
 #ifdef  B_ENDIAN
diff --git a/crypto/stack/stack.c b/crypto/stack/stack.c
index efabe16..c395d58 100644
--- a/crypto/stack/stack.c
+++ b/crypto/stack/stack.c
@@ -296,7 +296,7 @@
         return;
     if (st->num <= 0)
         return;
-    memset((char *)st->data, 0, sizeof(*st->data) * st->num);
+    memset(st->data, 0, sizeof(*st->data) * st->num);
     st->num = 0;
 }
 
diff --git a/crypto/store/str_mem.c b/crypto/store/str_mem.c
index 632ada8..b14e289 100644
--- a/crypto/store/str_mem.c
+++ b/crypto/store/str_mem.c
@@ -252,7 +252,7 @@
         STOREerr(STORE_F_MEM_LIST_START, ERR_R_MALLOC_FAILURE);
         return 0;
     }
-    memset(context, 0, sizeof(struct mem_ctx_st));
+    memset(context, 0, sizeof(*context));
 
     attribute_context = STORE_parse_attrs_start(attributes);
     if (!attribute_context) {
diff --git a/crypto/ts/ts_rsp_sign.c b/crypto/ts/ts_rsp_sign.c
index 2d1e438..077d03d 100644
--- a/crypto/ts/ts_rsp_sign.c
+++ b/crypto/ts/ts_rsp_sign.c
@@ -173,7 +173,7 @@
         TSerr(TS_F_TS_RESP_CTX_NEW, ERR_R_MALLOC_FAILURE);
         return NULL;
     }
-    memset(ctx, 0, sizeof(TS_RESP_CTX));
+    memset(ctx, 0, sizeof(*ctx));
 
     /* Setting default callbacks. */
     ctx->serial_cb = def_serial_cb;
diff --git a/crypto/ts/ts_verify_ctx.c b/crypto/ts/ts_verify_ctx.c
index 651b1d1..75bf2df 100644
--- a/crypto/ts/ts_verify_ctx.c
+++ b/crypto/ts/ts_verify_ctx.c
@@ -66,7 +66,7 @@
     TS_VERIFY_CTX *ctx = OPENSSL_malloc(sizeof(*ctx));
 
     if (ctx)
-        memset(ctx, 0, sizeof(TS_VERIFY_CTX));
+        memset(ctx, 0, sizeof(*ctx));
     else
         TSerr(TS_F_TS_VERIFY_CTX_NEW, ERR_R_MALLOC_FAILURE);
     return ctx;
@@ -75,7 +75,7 @@
 void TS_VERIFY_CTX_init(TS_VERIFY_CTX *ctx)
 {
     OPENSSL_assert(ctx != NULL);
-    memset(ctx, 0, sizeof(TS_VERIFY_CTX));
+    memset(ctx, 0, sizeof(*ctx));
 }
 
 void TS_VERIFY_CTX_free(TS_VERIFY_CTX *ctx)
diff --git a/crypto/ui/ui_openssl.c b/crypto/ui/ui_openssl.c
index 2ee9658..0696341 100644
--- a/crypto/ui/ui_openssl.c
+++ b/crypto/ui/ui_openssl.c
@@ -585,7 +585,7 @@
 # ifdef SIGACTION
     struct sigaction sa;
 
-    memset(&sa, 0, sizeof sa);
+    memset(&sa, 0, sizeof(sa));
     sa.sa_handler = recsig;
 # endif
 
diff --git a/crypto/x509/x509_vfy.c b/crypto/x509/x509_vfy.c
index 8c0680b..40a1e61 100644
--- a/crypto/x509/x509_vfy.c
+++ b/crypto/x509/x509_vfy.c
@@ -2217,7 +2217,7 @@
         X509err(X509_F_X509_STORE_CTX_NEW, ERR_R_MALLOC_FAILURE);
         return NULL;
     }
-    memset(ctx, 0, sizeof(X509_STORE_CTX));
+    memset(ctx, 0, sizeof(*ctx));
     return ctx;
 }
 
@@ -2337,11 +2337,9 @@
     ctx->check_policy = check_policy;
 
     /*
-     * This memset() can't make any sense anyway, so it's removed. As
-     * X509_STORE_CTX_cleanup does a proper "free" on the ex_data, we put a
-     * corresponding "new" here and remove this bogus initialisation.
+     * Since X509_STORE_CTX_cleanup does a proper "free" on the ex_data, we
+     * put a corresponding "new" here.
      */
-    /* memset(&(ctx->ex_data),0,sizeof(CRYPTO_EX_DATA)); */
     if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509_STORE_CTX, ctx,
                             &(ctx->ex_data))) {
         OPENSSL_free(ctx);
@@ -2376,7 +2374,7 @@
     sk_X509_pop_free(ctx->chain, X509_free);
     ctx->chain = NULL;
     CRYPTO_free_ex_data(CRYPTO_EX_INDEX_X509_STORE_CTX, ctx, &(ctx->ex_data));
-    memset(&ctx->ex_data, 0, sizeof(CRYPTO_EX_DATA));
+    memset(&ctx->ex_data, 0, sizeof(ctx->ex_data));
 }
 
 void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth)
diff --git a/crypto/x509v3/pcy_tree.c b/crypto/x509v3/pcy_tree.c
index 8870ec2..6b0167b 100644
--- a/crypto/x509v3/pcy_tree.c
+++ b/crypto/x509v3/pcy_tree.c
@@ -235,14 +235,11 @@
         return 0;
     }
 
-    memset(tree->levels, 0, n * sizeof(X509_POLICY_LEVEL));
-
+    memset(tree->levels, 0, sizeof(*tree->levels) * n);
     tree->nlevel = n;
-
     level = tree->levels;
 
     /* Root data: initialize to anyPolicy */
-
     data = policy_data_new(NULL, OBJ_nid2obj(NID_any_policy), 0);
 
     if (!data || !level_add_node(level, data, NULL, tree))