Skip to content

Commit 74e66fd

Browse files
authored
refactor: fix unread variable warnings (#4405)
1 parent 91ad940 commit 74e66fd

9 files changed

+20
-38
lines changed

tests/testlib/s2n_test_server_client.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@ int s2n_negotiate_test_server_and_client(struct s2n_connection *server_conn, str
4545
{
4646
bool server_done = false, client_done = false;
4747
s2n_blocked_status blocked = S2N_NOT_BLOCKED;
48-
bool rc = false;
4948

5049
do {
51-
rc = (s2n_negotiate(client_conn, &blocked) >= S2N_SUCCESS);
50+
bool rc = (s2n_negotiate(client_conn, &blocked) >= S2N_SUCCESS);
5251
POSIX_GUARD_RESULT(s2n_validate_negotiate_result(rc, server_done, &client_done));
5352

5453
rc = (s2n_negotiate(server_conn, &blocked) >= S2N_SUCCESS);
@@ -105,10 +104,9 @@ S2N_RESULT s2n_negotiate_test_server_and_client_until_message(struct s2n_connect
105104
{
106105
bool server_done = false, client_done = false;
107106
s2n_blocked_status blocked = S2N_NOT_BLOCKED;
108-
bool rc = false;
109107

110108
do {
111-
rc = s2n_result_is_ok(s2n_negotiate_until_message(client_conn, &blocked, message_type));
109+
bool rc = s2n_result_is_ok(s2n_negotiate_until_message(client_conn, &blocked, message_type));
112110
RESULT_GUARD(s2n_validate_negotiate_result(rc, server_done, &client_done));
113111

114112
rc = s2n_result_is_ok(s2n_negotiate_until_message(server_conn, &blocked, message_type));

tests/unit/s2n_alerts_test.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ int main(int argc, char **argv)
5353
/* Test S2N_ERR_T_PROTO */
5454
{
5555
/* Test all protocol errors are handled */
56-
int ret_val;
5756
for (size_t i = S2N_ERR_T_PROTO_START; i < S2N_ERR_T_PROTO_END; i++) {
58-
ret_val = s2n_error_get_alert(i, &alert);
57+
int ret_val = s2n_error_get_alert(i, &alert);
5958
if (ret_val != S2N_SUCCESS && s2n_errno == S2N_ERR_UNIMPLEMENTED) {
6059
fprintf(stdout, "\n\nNo alert mapping for protocol error %s\n\n", s2n_strerror_name(i));
6160
FAIL_MSG("Missing alert mapping for protocol error.");

tests/unit/s2n_mem_allocator_test.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ int main(int argc, char **argv)
149149
{
150150
s2n_blocked_status blocked;
151151
int status;
152-
pid_t pid;
153152
char *cert_chain_pem;
154153
char *private_key_pem;
155154
char *dhparams_pem;
@@ -175,7 +174,7 @@ int main(int argc, char **argv)
175174
EXPECT_SUCCESS(s2n_io_pair_init(&io_pair));
176175

177176
/* Create a child process */
178-
pid = fork();
177+
pid_t pid = fork();
179178
if (pid == 0) {
180179
/* This is the client process, close the server end of the pipe */
181180
EXPECT_SUCCESS(s2n_io_pair_close_one_end(&io_pair, S2N_SERVER));

tests/unit/s2n_self_talk_broken_pipe_test.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ int main(int argc, char **argv)
9292
struct s2n_config *config;
9393
s2n_blocked_status blocked;
9494
int status;
95-
pid_t pid;
9695
char cert_chain_pem[S2N_MAX_TEST_PEM_SIZE];
9796
char private_key_pem[S2N_MAX_TEST_PEM_SIZE];
9897
char dhparams_pem[S2N_MAX_TEST_PEM_SIZE];
@@ -107,7 +106,7 @@ int main(int argc, char **argv)
107106
EXPECT_SUCCESS(s2n_io_pair_init(&io_pair));
108107

109108
/* Create a child process */
110-
pid = fork();
109+
pid_t pid = fork();
111110
if (pid == 0) {
112111
/* This is the client process, close the server end of the pipe */
113112
EXPECT_SUCCESS(s2n_io_pair_close_one_end(&io_pair, S2N_SERVER));

tests/unit/s2n_self_talk_min_protocol_version_test.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ int main(int argc, char **argv)
6464
{
6565
s2n_blocked_status blocked;
6666
int status;
67-
pid_t pid;
6867
char cert_chain_pem[S2N_MAX_TEST_PEM_SIZE];
6968
char private_key_pem[S2N_MAX_TEST_PEM_SIZE];
7069

@@ -82,7 +81,7 @@ int main(int argc, char **argv)
8281
EXPECT_SUCCESS(s2n_io_pair_init(&io_pair));
8382

8483
/* Create a child process */
85-
pid = fork();
84+
pid_t pid = fork();
8685
if (pid == 0) {
8786
/* This is the client process, close the server end of the pipe */
8887
EXPECT_SUCCESS(s2n_io_pair_close_one_end(&io_pair, S2N_SERVER));

tests/unit/s2n_self_talk_tls12_test.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ int main(int argc, char **argv)
102102
struct s2n_config *config;
103103
s2n_blocked_status blocked;
104104
int status;
105-
pid_t pid;
106105
char *cert_chain_pem;
107106
char *private_key_pem;
108107
char *dhparams_pem;
@@ -117,7 +116,7 @@ int main(int argc, char **argv)
117116
EXPECT_SUCCESS(s2n_io_pair_init(&io_pair));
118117

119118
/* Create a child process */
120-
pid = fork();
119+
pid_t pid = fork();
121120
if (pid == 0) {
122121
/* This is the client process, close the server end of the pipe */
123122
EXPECT_SUCCESS(s2n_io_pair_close_one_end(&io_pair, S2N_SERVER));

tests/unit/s2n_tls12_handshake_test.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -492,21 +492,18 @@ int main(int argc, char **argv)
492492

493493
/* Test: A WITH_NPN form of every valid, negotiated handshake exists */
494494
{
495-
uint32_t handshake_type_original, handshake_type_npn;
496-
message_type_t *messages_original, *messages_npn;
497-
498495
for (size_t i = 0; i < valid_tls12_handshakes_size; i++) {
499-
handshake_type_original = valid_tls12_handshakes[i];
500-
messages_original = handshakes[handshake_type_original];
496+
uint32_t handshake_type_original = valid_tls12_handshakes[i];
497+
message_type_t *messages_original = handshakes[handshake_type_original];
501498

502499
/* Ignore INITIAL and WITH_NPN handshakes */
503500
if (!(handshake_type_original & NEGOTIATED) || (handshake_type_original & WITH_NPN)) {
504501
continue;
505502
}
506503

507504
/* Get the WITH_NPN form of the handshake */
508-
handshake_type_npn = handshake_type_original | WITH_NPN;
509-
messages_npn = handshakes[handshake_type_npn];
505+
uint32_t handshake_type_npn = handshake_type_original | WITH_NPN;
506+
message_type_t *messages_npn = handshakes[handshake_type_npn];
510507

511508
for (size_t j = 0, j_npn = 0; j < S2N_MAX_HANDSHAKE_LENGTH && j_npn < S2N_MAX_HANDSHAKE_LENGTH; j++, j_npn++) {
512509
/* The original handshake cannot contain the Next Protocol message */

tests/unit/s2n_tls13_handshake_state_machine_test.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -655,10 +655,6 @@ int main(int argc, char **argv)
655655
*# the TLS 1.3 handshake look more like a TLS 1.2 handshake:
656656
*/
657657
{
658-
bool change_cipher_spec_found;
659-
uint32_t handshake_type;
660-
message_type_t *messages;
661-
662658
/*
663659
*= https://tools.ietf.org/rfc/rfc8446#appendix-D.4
664660
*= type=test
@@ -668,9 +664,9 @@ int main(int argc, char **argv)
668664
*# its second ClientHello or before its encrypted handshake flight.
669665
**/
670666
for (size_t i = 0; i < valid_tls13_handshakes_size; i++) {
671-
change_cipher_spec_found = false;
672-
handshake_type = valid_tls13_handshakes[i];
673-
messages = tls13_handshakes[handshake_type];
667+
bool change_cipher_spec_found = false;
668+
uint32_t handshake_type = valid_tls13_handshakes[i];
669+
message_type_t *messages = tls13_handshakes[handshake_type];
674670

675671
/* Ignore INITIAL and non-MIDDLEBOX_COMPAT handshakes */
676672
if (!(handshake_type & NEGOTIATED)
@@ -705,8 +701,8 @@ int main(int argc, char **argv)
705701
*# first ClientHello.
706702
*/
707703
for (size_t i = 0; i < valid_tls13_handshakes_size; i++) {
708-
handshake_type = valid_tls13_handshakes[i];
709-
messages = tls13_handshakes[handshake_type];
704+
uint32_t handshake_type = valid_tls13_handshakes[i];
705+
message_type_t *messages = tls13_handshakes[handshake_type];
710706

711707
/* Ignore handshakes where early data did not trigger the change in CCS behavior */
712708
if (!(handshake_type & EARLY_CLIENT_CCS)) {
@@ -728,9 +724,9 @@ int main(int argc, char **argv)
728724
*# ServerHello or a HelloRetryRequest.
729725
**/
730726
for (size_t i = 0; i < valid_tls13_handshakes_size; i++) {
731-
change_cipher_spec_found = false;
732-
handshake_type = valid_tls13_handshakes[i];
733-
messages = tls13_handshakes[handshake_type];
727+
bool change_cipher_spec_found = false;
728+
uint32_t handshake_type = valid_tls13_handshakes[i];
729+
message_type_t *messages = tls13_handshakes[handshake_type];
734730

735731
/* Ignore INITIAL and non-MIDDLEBOX_COMPAT handshakes */
736732
if (!(handshake_type & NEGOTIATED) || !(handshake_type & MIDDLEBOX_COMPAT)) {

tls/s2n_protocol_preferences.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,7 @@ S2N_RESULT s2n_protocol_preferences_set(struct s2n_blob *application_protocols,
129129
/* update the connection/config application_protocols with the newly allocated blob */
130130
*application_protocols = new_protocols;
131131

132-
/* zero out new_protocols so the DEFER_CLEANUP from above doesn't free
133-
* the blob that we created and assigned to application_protocols
134-
*/
135-
/* cppcheck-suppress unreadVariable */
136-
new_protocols = (struct s2n_blob){ 0 };
132+
ZERO_TO_DISABLE_DEFER_CLEANUP(new_protocols);
137133

138134
return S2N_RESULT_OK;
139135
}

0 commit comments

Comments
 (0)