coverity 1462578 Resource leak
[openssl.git] / test / packettest.c
index 716dec303d4488b26883ad4a086821d0d6a887ae..2d6c2a6ef99f5c749277de6afff4dca26e5265d9 100644 (file)
@@ -1,13 +1,13 @@
 /*
- * Copyright 2015-2017 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.
  *
- * Licensed under the OpenSSL license (the "License").  You may not use
+ * Licensed under the Apache License 2.0 (the "License").  You may not use
  * this file except in compliance with the License.  You can obtain a copy
  * in the file LICENSE in the source distribution or at
  * https://www.openssl.org/source/license.html
  */
 
-#include "../ssl/packet_locl.h"
+#include "internal/packet.h"
 #include "testutil.h"
 
 #define BUF_LEN 255
@@ -47,7 +47,7 @@ static int test_PACKET_end(void)
 
 static int test_PACKET_get_1(void)
 {
-    unsigned int i;
+    unsigned int i = 0;
     PACKET pkt;
 
     if (!TEST_true(PACKET_buf_init(&pkt, smbuf, BUF_LEN))
@@ -64,7 +64,7 @@ static int test_PACKET_get_1(void)
 
 static int test_PACKET_get_4(void)
 {
-    unsigned long i;
+    unsigned long i = 0;
     PACKET pkt;
 
     if (!TEST_true(PACKET_buf_init(&pkt, smbuf, BUF_LEN))
@@ -81,7 +81,7 @@ static int test_PACKET_get_4(void)
 
 static int test_PACKET_get_net_2(void)
 {
-    unsigned int i;
+    unsigned int i = 0;
     PACKET pkt;
 
     if (!TEST_true(PACKET_buf_init(&pkt, smbuf, BUF_LEN))
@@ -98,7 +98,7 @@ static int test_PACKET_get_net_2(void)
 
 static int test_PACKET_get_net_3(void)
 {
-    unsigned long i;
+    unsigned long i = 0;
     PACKET pkt;
 
     if (!TEST_true(PACKET_buf_init(&pkt, smbuf, BUF_LEN))
@@ -115,7 +115,7 @@ static int test_PACKET_get_net_3(void)
 
 static int test_PACKET_get_net_4(void)
 {
-    unsigned long i;
+    unsigned long i = 0;
     PACKET pkt;
 
     if (!TEST_true(PACKET_buf_init(&pkt, smbuf, BUF_LEN))
@@ -133,7 +133,7 @@ static int test_PACKET_get_net_4(void)
 static int test_PACKET_get_sub_packet(void)
 {
     PACKET pkt, subpkt;
-    unsigned long i;
+    unsigned long i = 0;
 
     if (!TEST_true(PACKET_buf_init(&pkt, smbuf, BUF_LEN))
             || !TEST_true(PACKET_get_sub_packet(&pkt, &subpkt, 4))
@@ -153,7 +153,7 @@ static int test_PACKET_get_sub_packet(void)
 
 static int test_PACKET_get_bytes(void)
 {
-    const unsigned char *bytes;
+    const unsigned char *bytes = NULL;
     PACKET pkt;
 
     if (!TEST_true(PACKET_buf_init(&pkt, smbuf, BUF_LEN))
@@ -285,7 +285,7 @@ static int test_PACKET_contains_zero_byte(void)
 
 static int test_PACKET_forward(void)
 {
-    const unsigned char *byte;
+    const unsigned char *byte = NULL;
     PACKET pkt;
 
     if (!TEST_true(PACKET_buf_init(&pkt, smbuf, BUF_LEN))
@@ -350,8 +350,9 @@ static int test_PACKET_get_length_prefixed_1(void)
     unsigned char buf1[BUF_LEN];
     const size_t len = 16;
     unsigned int i;
-    PACKET pkt, short_pkt, subpkt = {0};
+    PACKET pkt, short_pkt, subpkt;
 
+    memset(&subpkt, 0, sizeof(subpkt));
     buf1[0] = (unsigned char)len;
     for (i = 1; i < BUF_LEN; i++)
         buf1[i] = (i * 2) & 0xff;
@@ -374,8 +375,9 @@ static int test_PACKET_get_length_prefixed_2(void)
     unsigned char buf1[1024];
     const size_t len = 516;  /* 0x0204 */
     unsigned int i;
-    PACKET pkt, short_pkt, subpkt = {0};
+    PACKET pkt, short_pkt, subpkt;
 
+    memset(&subpkt, 0, sizeof(subpkt));
     for (i = 1; i <= 1024; i++)
         buf1[i - 1] = (i * 2) & 0xff;
 
@@ -397,8 +399,9 @@ static int test_PACKET_get_length_prefixed_3(void)
     unsigned char buf1[1024];
     const size_t len = 516;  /* 0x000204 */
     unsigned int i;
-    PACKET pkt, short_pkt, subpkt = {0};
+    PACKET pkt, short_pkt, subpkt;
 
+    memset(&subpkt, 0, sizeof(subpkt));
     for (i = 0; i < 1024; i++)
         buf1[i] = (i * 2) & 0xff;
 
@@ -420,8 +423,9 @@ static int test_PACKET_as_length_prefixed_1(void)
     unsigned char buf1[BUF_LEN];
     const size_t len = 16;
     unsigned int i;
-    PACKET pkt, exact_pkt, subpkt = {0};
+    PACKET pkt, exact_pkt, subpkt;
 
+    memset(&subpkt, 0, sizeof(subpkt));
     buf1[0] = (unsigned char)len;
     for (i = 1; i < BUF_LEN; i++)
         buf1[i] = (i * 2) & 0xff;
@@ -443,8 +447,9 @@ static int test_PACKET_as_length_prefixed_2(void)
     unsigned char buf[1024];
     const size_t len = 516;  /* 0x0204 */
     unsigned int i;
-    PACKET pkt, exact_pkt, subpkt = {0};
+    PACKET pkt, exact_pkt, subpkt;
 
+    memset(&subpkt, 0, sizeof(subpkt));
     for (i = 1; i <= 1024; i++)
         buf[i-1] = (i * 2) & 0xff;