From 512bba4922032b3d132a921d7b0a914cb91820dc Mon Sep 17 00:00:00 2001
From: huitema <huitema@huitema.net>
Date: Wed, 10 Oct 2018 10:33:37 -0700
Subject: [PATCH] Fix a bunch of compilation warnings

---
 picoquic.sln                 |  1 +
 picoquic/frames.c            |  8 ++++----
 picoquic/logger.c            |  2 +-
 picoquic/packet.c            | 20 ++++++++++----------
 picoquic/picoquic_internal.h |  4 ++--
 picoquic/quicctx.c           |  2 +-
 picoquic/tls_api.c           | 20 ++++++++++----------
 picoquic/tls_api.h           |  2 +-
 picoquictest/tls_api_test.c  |  2 +-
 9 files changed, 31 insertions(+), 30 deletions(-)

diff --git a/picoquic.sln b/picoquic.sln
index 75056e50..c6d88d2d 100644
--- a/picoquic.sln
+++ b/picoquic.sln
@@ -16,6 +16,7 @@ EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "picoquicdemo", "picoquicfirst\picoquicfirst.vcxproj", "{995745F2-E8BA-48C1-AF6D-BA554B869D47}"
 	ProjectSection(ProjectDependencies) = postProject
 		{63E1E6B7-DB5F-4EDC-8AC8-7E9F5990D11F} = {63E1E6B7-DB5F-4EDC-8AC8-7E9F5990D11F}
+		{B04168BD-4D56-4DE9-B1E3-CF4C16FE21C7} = {B04168BD-4D56-4DE9-B1E3-CF4C16FE21C7}
 	EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "picoquic_t", "picoquic_t\picoquic_t.vcxproj", "{4898D6E0-6FC5-4375-99F5-4C69BB20CE94}"
diff --git a/picoquic/frames.c b/picoquic/frames.c
index 4e40f8cb..b52b7f0f 100644
--- a/picoquic/frames.c
+++ b/picoquic/frames.c
@@ -452,7 +452,7 @@ int picoquic_prepare_new_connection_id_frame(picoquic_cnx_t * cnx, picoquic_path
 
 uint8_t* picoquic_skip_new_connection_id_frame(uint8_t* bytes, const uint8_t* bytes_max, int is_draft_14)
 {
-    uint8_t cid_length;
+    uint8_t cid_length = 0;
 
     if (is_draft_14) {
         if ((bytes = picoquic_frames_varint_skip(bytes + 1, bytes_max)) != NULL) {
@@ -501,7 +501,7 @@ uint8_t* picoquic_decode_new_connection_id_frame(picoquic_cnx_t* cnx, uint8_t* b
         picoquic_connection_error(cnx, (bytes == NULL) ? PICOQUIC_TRANSPORT_FRAME_FORMAT_ERROR : PICOQUIC_TRANSPORT_PROTOCOL_VIOLATION,
             picoquic_frame_type_new_connection_id);
     } else {
-        int ret = picoquic_enqueue_cnxid_stash(cnx, sequence, cid_length, cnxid_bytes, secret_bytes, NULL);
+        uint16_t ret = (uint16_t)picoquic_enqueue_cnxid_stash(cnx, sequence, cid_length, cnxid_bytes, secret_bytes, NULL);
         if (ret != 0) {
             picoquic_connection_error(cnx, ret, picoquic_frame_type_new_connection_id);
             bytes = NULL;
@@ -515,7 +515,7 @@ uint8_t* picoquic_decode_new_connection_id_frame(picoquic_cnx_t* cnx, uint8_t* b
  * Format a retire connection ID frame.
  */
 
-int picoquic_prepare_retire_connection_id_frame(picoquic_cnx_t * cnx, uint64_t sequence, 
+int picoquic_prepare_retire_connection_id_frame(uint64_t sequence, 
     uint8_t* bytes, size_t bytes_max, size_t* consumed)
 {
     int ret = 0;
@@ -557,7 +557,7 @@ int picoquic_queue_retire_connection_id_frame(picoquic_cnx_t * cnx, uint64_t seq
         return 0;
     }
 
-    int ret = picoquic_prepare_retire_connection_id_frame(cnx, sequence, frame_buffer, sizeof(frame_buffer), &consumed);
+    int ret = picoquic_prepare_retire_connection_id_frame(sequence, frame_buffer, sizeof(frame_buffer), &consumed);
 
     if (ret == 0 && consumed > 0) {
         ret = picoquic_queue_misc_frame(cnx, frame_buffer, consumed);
diff --git a/picoquic/logger.c b/picoquic/logger.c
index 925998d5..95430a8c 100644
--- a/picoquic/logger.c
+++ b/picoquic/logger.c
@@ -866,7 +866,7 @@ size_t picoquic_log_new_connection_id_frame(FILE* F, uint8_t* bytes, size_t byte
 size_t picoquic_log_retire_connection_id_frame(FILE* F, uint8_t* bytes, size_t bytes_max)
 {
     size_t byte_index = 1;
-    uint64_t sequence;
+    uint64_t sequence = 0;
     size_t l_seq = 0;
 
 
diff --git a/picoquic/packet.c b/picoquic/packet.c
index b6482521..84ff96d0 100644
--- a/picoquic/packet.c
+++ b/picoquic/packet.c
@@ -328,7 +328,7 @@ uint64_t picoquic_get_packet_number64(uint64_t highest, uint64_t mask, uint32_t
  * sequence number and the offset 
  */
 size_t  picoquic_decrypt_packet(picoquic_cnx_t* cnx,
-    uint8_t* bytes, size_t packet_length, picoquic_packet_header* ph, 
+    uint8_t* bytes, picoquic_packet_header* ph, 
     void * pn_enc, void* aead_context, int * already_received)
 {
     size_t decoded;
@@ -468,7 +468,7 @@ int picoquic_parse_header_and_decrypt(
                 /* Packet is not encrypted */
                 break;
             case picoquic_packet_initial:
-                decoded_length = picoquic_decrypt_packet(*pcnx, bytes, packet_length, ph,
+                decoded_length = picoquic_decrypt_packet(*pcnx, bytes, ph,
                     (*pcnx)->crypto_context[0].pn_dec,
                     (*pcnx)->crypto_context[0].aead_decrypt, &already_received);
                 length = ph->offset + ph->payload_length;
@@ -482,19 +482,19 @@ int picoquic_parse_header_and_decrypt(
                 decoded_length = ph->payload_length;
                 break;
             case picoquic_packet_handshake:
-                decoded_length = picoquic_decrypt_packet(*pcnx, bytes, length, ph,
+                decoded_length = picoquic_decrypt_packet(*pcnx, bytes, ph,
                     (*pcnx)->crypto_context[2].pn_dec,
                     (*pcnx)->crypto_context[2].aead_decrypt, &already_received);
                 break;
             case picoquic_packet_0rtt_protected:
-                decoded_length = picoquic_decrypt_packet(*pcnx, bytes, length, ph,
+                decoded_length = picoquic_decrypt_packet(*pcnx, bytes, ph,
                     (*pcnx)->crypto_context[1].pn_dec,
                     (*pcnx)->crypto_context[1].aead_decrypt, &already_received);
                 break;
             case picoquic_packet_1rtt_protected:
                 if (ph->key_phase == (*pcnx)->key_phase_dec) {
                     /* AEAD Decrypt, in place */
-                    decoded_length = picoquic_decrypt_packet(*pcnx, bytes, length, ph,
+                    decoded_length = picoquic_decrypt_packet(*pcnx, bytes, ph,
                         (*pcnx)->crypto_context[3].pn_dec,
                         (*pcnx)->crypto_context[3].aead_decrypt, &already_received);
                 }
@@ -504,7 +504,7 @@ int picoquic_parse_header_and_decrypt(
                         current_time < (*pcnx)->crypto_rotation_time_guard)
                     {
                         /* If there is an old key available, try decrypt with it */
-                        decoded_length = picoquic_decrypt_packet(*pcnx, bytes, length, ph,
+                        decoded_length = picoquic_decrypt_packet(*pcnx, bytes, ph,
                             (*pcnx)->crypto_context_old.pn_dec,
                             (*pcnx)->crypto_context_old.aead_decrypt, &already_received);
 
@@ -527,7 +527,7 @@ int picoquic_parse_header_and_decrypt(
                             (*pcnx)->crypto_context_new.pn_dec != NULL)
                         {
                             /* If there is an old key available, try decrypt with it */
-                            decoded_length = picoquic_decrypt_packet(*pcnx, bytes, length, ph,
+                            decoded_length = picoquic_decrypt_packet(*pcnx, bytes, ph,
                                 (*pcnx)->crypto_context_new.pn_dec,
                                 (*pcnx)->crypto_context_new.aead_decrypt, &already_received);
 
@@ -835,12 +835,12 @@ int picoquic_incoming_initial(
         uint8_t token[1 + PICOQUIC_CONNECTION_ID_MAX_SIZE + 16];
 
         /* Does the token contain a valid CID? */
-        if (ph->token_length > 1 + 8) {
+        if (ph->token_length > 1u + 8u) {
             cid_len = *(bytes + ph->token_offset);
             if (cid_len < 8 && cid_len > PICOQUIC_CONNECTION_ID_MAX_SIZE) {
                 cid_len = 0;
             }
-            else if (cid_len + 1 + 16 != ph->token_length) {
+            else if (cid_len + 1u + 16u != ph->token_length) {
                 cid_len = 0;
             }
         }
@@ -869,7 +869,7 @@ int picoquic_incoming_initial(
         }
 
         if (!is_token_ok) {
-            uint8_t token_length = 1 + ph->dest_cnx_id.id_len + 16;
+            uint32_t token_length = 1u + ph->dest_cnx_id.id_len + 16u;
 
             if (picoquic_get_retry_token((*pcnx)->quic, base, len, ph->dest_cnx_id.id, ph->dest_cnx_id.id_len,
                 token, token_length) != 0)
diff --git a/picoquic/picoquic_internal.h b/picoquic/picoquic_internal.h
index 941a8e10..ed58183f 100644
--- a/picoquic/picoquic_internal.h
+++ b/picoquic/picoquic_internal.h
@@ -704,7 +704,7 @@ picoquic_cnx_t* picoquic_cnx_by_id(picoquic_quic_t* quic, picoquic_connection_id
 picoquic_cnx_t* picoquic_cnx_by_net(picoquic_quic_t* quic, struct sockaddr* addr);
 
 int picoquic_retrieve_by_cnx_id_or_net_id(picoquic_quic_t* quic, picoquic_connection_id_t* cnx_id,
-    struct sockaddr* addr, picoquic_cnx_t ** pcnx, picoquic_path_t * path);
+    struct sockaddr* addr, picoquic_cnx_t ** pcnx);
 
 /* Reset the pacing data after CWIN is updated */
 void picoquic_update_pacing_data(picoquic_path_t * path_x);
@@ -809,7 +809,7 @@ int picoquic_parse_ack_header(
 uint64_t picoquic_get_packet_number64(uint64_t highest, uint64_t mask, uint32_t pn);
 
 size_t  picoquic_decrypt_packet(picoquic_cnx_t* cnx,
-    uint8_t* bytes, size_t length, picoquic_packet_header* ph,
+    uint8_t* bytes, picoquic_packet_header* ph,
     void * pn_enc, void* aead_context, int * already_received);
 
 uint32_t picoquic_protect_packet(picoquic_cnx_t* cnx,
diff --git a/picoquic/quicctx.c b/picoquic/quicctx.c
index d467060e..c77394bc 100644
--- a/picoquic/quicctx.c
+++ b/picoquic/quicctx.c
@@ -1944,7 +1944,7 @@ picoquic_cnx_t* picoquic_cnx_by_net(picoquic_quic_t* quic, struct sockaddr* addr
 }
 
 int picoquic_retrieve_by_cnx_id_or_net_id(picoquic_quic_t * quic, picoquic_connection_id_t * cnx_id, 
-    struct sockaddr * addr, picoquic_cnx_t ** pcnx, picoquic_path_t * path)
+    struct sockaddr * addr, picoquic_cnx_t ** pcnx)
 {
     if (cnx_id->id_len > 0) {
         *pcnx = picoquic_cnx_by_id(quic, *cnx_id);
diff --git a/picoquic/tls_api.c b/picoquic/tls_api.c
index d6e10de0..e9fd61e2 100644
--- a/picoquic/tls_api.c
+++ b/picoquic/tls_api.c
@@ -636,7 +636,7 @@ static int picoquic_set_pn_enc_from_secret(void ** v_pn_enc, ptls_cipher_suite_t
 }
 
 
-static int picoquic_set_key_from_secret(picoquic_cnx_t* cnx, ptls_cipher_suite_t * cipher, int is_enc, picoquic_crypto_context_t * ctx, const void *secret)
+static int picoquic_set_key_from_secret(ptls_cipher_suite_t * cipher, int is_enc, picoquic_crypto_context_t * ctx, const void *secret)
 {
     int ret = 0;
 
@@ -696,7 +696,7 @@ static int picoquic_update_traffic_key_callback(ptls_update_traffic_key_t * self
     debug_dump(secret, (int)cipher->hash->digest_size);
 #endif
 
-    int ret = picoquic_set_key_from_secret(cnx, cipher, is_enc, &cnx->crypto_context[epoch], secret);
+    int ret = picoquic_set_key_from_secret(cipher, is_enc, &cnx->crypto_context[epoch], secret);
 
     if (ret == 0 && epoch == 3) {
         memcpy((is_enc) ? tls_ctx->app_secret_enc : tls_ctx->app_secret_dec, secret, cipher->aead->key_size);
@@ -804,11 +804,11 @@ int picoquic_setup_initial_traffic_keys(picoquic_cnx_t* cnx)
         }
 
         if (ret == 0) {
-            ret = picoquic_set_key_from_secret(cnx, &cipher, 1, &cnx->crypto_context[0], secret1);
+            ret = picoquic_set_key_from_secret(&cipher, 1, &cnx->crypto_context[0], secret1);
         }
 
         if (ret == 0) {
-            ret = picoquic_set_key_from_secret(cnx, &cipher, 0, &cnx->crypto_context[0], secret2);
+            ret = picoquic_set_key_from_secret(&cipher, 0, &cnx->crypto_context[0], secret2);
         }
     }
 
@@ -880,7 +880,7 @@ int picoquic_compute_new_rotated_keys(picoquic_cnx_t * cnx)
     }
 
     if (ret == 0) {
-        ret = picoquic_set_key_from_secret(cnx, cipher, 1, &cnx->crypto_context_new, tls_ctx->app_secret_enc);
+        ret = picoquic_set_key_from_secret(cipher, 1, &cnx->crypto_context_new, tls_ctx->app_secret_enc);
     }
 
     if (ret == 0) {
@@ -888,7 +888,7 @@ int picoquic_compute_new_rotated_keys(picoquic_cnx_t * cnx)
     }
 
     if (ret == 0) {
-        ret = picoquic_set_key_from_secret(cnx, cipher, 0, &cnx->crypto_context_new, tls_ctx->app_secret_dec);
+        ret = picoquic_set_key_from_secret(cipher, 0, &cnx->crypto_context_new, tls_ctx->app_secret_dec);
     }
 
     return (ret == 0)?0: PICOQUIC_ERROR_CANNOT_COMPUTE_KEY;
@@ -1295,11 +1295,11 @@ static void picoquic_log_secret_call_back(ptls_log_secret_t* _self,
     /* Assume one concurrent writer for now, need locking otherwise. */
     ptls_iovec_t crandom = ptls_get_client_random(tls);
     fprintf(keylog_file, "%s ", label);
-    for (int i = 0; i < crandom.len; i++) {
+    for (size_t i = 0; i < crandom.len; i++) {
         fprintf(keylog_file, "%02x", crandom.base[i]);
     }
     fputc(' ', keylog_file);
-    for (int i = 0; i < secret.len; i++) {
+    for (size_t i = 0; i < secret.len; i++) {
         fprintf(keylog_file, "%02x", secret.base[i]);
     }
     fputc('\n', keylog_file);
@@ -1951,7 +1951,7 @@ int picoquic_tls_client_authentication_activated(picoquic_quic_t* quic) {
  */
 
 int picoquic_get_retry_token(picoquic_quic_t* quic, uint8_t * base, size_t len, uint8_t * cid, uint8_t cid_len,
-    uint8_t * token, uint8_t token_length) {
+    uint8_t * token, uint32_t token_length) {
     /*Using OpenSSL for now: ptls_hash_algorithm_t ptls_openssl_sha256 */
     int ret = 0;
     ptls_hash_algorithm_t* algo = &ptls_openssl_sha256;
@@ -1959,7 +1959,7 @@ int picoquic_get_retry_token(picoquic_quic_t* quic, uint8_t * base, size_t len,
     uint8_t final_hash[PTLS_MAX_DIGEST_SIZE];
     size_t offset;
 
-    if (hash_ctx == NULL || token_length > cid_len + algo->digest_size || token_length <= 1 + cid_len) {
+    if (hash_ctx == NULL || token_length > cid_len + algo->digest_size || token_length <= 1u + cid_len) {
         ret = -1;
     } else {
         hash_ctx->update(hash_ctx, quic->retry_seed, sizeof(quic->retry_seed));
diff --git a/picoquic/tls_api.h b/picoquic/tls_api.h
index 92f29234..600be7be 100644
--- a/picoquic/tls_api.h
+++ b/picoquic/tls_api.h
@@ -128,7 +128,7 @@ void picoquic_tls_set_client_authentication(picoquic_quic_t* quic, int client_au
 int picoquic_tls_client_authentication_activated(picoquic_quic_t* quic);
 
 int picoquic_get_retry_token(picoquic_quic_t* quic, uint8_t * base, size_t len, uint8_t * cid, uint8_t cid_len,
-    uint8_t * token, uint8_t token_length);
+    uint8_t * token, uint32_t token_length);
 
 
 #endif /* TLS_API_H */
diff --git a/picoquictest/tls_api_test.c b/picoquictest/tls_api_test.c
index 1c656a1f..3ad3ba53 100644
--- a/picoquictest/tls_api_test.c
+++ b/picoquictest/tls_api_test.c
@@ -3973,7 +3973,7 @@ static int aead_iv_check(void * aead1, void * aead2)
     if (memcmp(ctx1->static_iv, ctx2->static_iv, ctx1->algo->iv_size) != 0) {
         ret = -1;
     }
-    return;
+    return ret;
 }
 
 
-- 
GitLab