[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-dev] [PATCH] fix GCC 7 implicit fallthroug warnings



Hello,

6 patches that fix -Wimplicit-fallthrough in GCC 7 on master, by adding

 __attribute__ ((fallthrough));

or break, as required.


Additionally, the patch fixes the same on maint-0.3.0, the warning is no
longer present in master.
0001-Fix-implicit-fallthrough-warning-in-GCC-7-in-tor_gzi.patch

Please review,
Andreas

-- 
Andreas Stieger <astieger@xxxxxxxx>
Project Manager Security
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton,
HRB 21284 (AG Nürnberg)


From 089c07448260fb9df1aed6cafd36334d64f8dfe7 Mon Sep 17 00:00:00 2001
From: Andreas Stieger <astieger@xxxxxxxx>
Date: Sun, 28 May 2017 21:50:38 +0200
Subject: [PATCH 1/6] Fix implicit fallthrough warning with GCC 7 in
 siphash24()

---
 src/ext/csiphash.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/ext/csiphash.c b/src/ext/csiphash.c
index 1029bbbad..6dfa480a0 100644
--- a/src/ext/csiphash.c
+++ b/src/ext/csiphash.c
@@ -88,13 +88,13 @@ uint64_t siphash24(const void *src, unsigned long src_sz, const struct sipkey *k
 	}
 
 	switch (src_sz - blocks) {
-		case 7: last7 |= (uint64_t)m[i + 6] << 48;
-		case 6: last7 |= (uint64_t)m[i + 5] << 40;
-		case 5: last7 |= (uint64_t)m[i + 4] << 32;
-		case 4: last7 |= (uint64_t)m[i + 3] << 24;
-		case 3: last7 |= (uint64_t)m[i + 2] << 16;
-		case 2: last7 |= (uint64_t)m[i + 1] <<  8;
-		case 1: last7 |= (uint64_t)m[i + 0]      ;
+		case 7: last7 |= (uint64_t)m[i + 6] << 48; __attribute__ ((fallthrough));
+		case 6: last7 |= (uint64_t)m[i + 5] << 40; __attribute__ ((fallthrough));
+		case 5: last7 |= (uint64_t)m[i + 4] << 32; __attribute__ ((fallthrough));
+		case 4: last7 |= (uint64_t)m[i + 3] << 24; __attribute__ ((fallthrough));
+		case 3: last7 |= (uint64_t)m[i + 2] << 16; __attribute__ ((fallthrough));
+		case 2: last7 |= (uint64_t)m[i + 1] <<  8; __attribute__ ((fallthrough));
+		case 1: last7 |= (uint64_t)m[i + 0]      ; __attribute__ ((fallthrough));
 		case 0:
 		default:;
 	}
-- 
2.13.0


From d9d548d0de44b0fd46d366836c58bab383457612 Mon Sep 17 00:00:00 2001
From: Andreas Stieger <astieger@xxxxxxxx>
Date: Sun, 28 May 2017 21:50:38 +0200
Subject: [PATCH 2/6] Fix implicit fallthrough warning with GCC 7 in
 ed25519-donna

---
 src/ext/ed25519/donna/modm-donna-64bit.h | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/ext/ed25519/donna/modm-donna-64bit.h b/src/ext/ed25519/donna/modm-donna-64bit.h
index 012ea9ea0..ff2dd72a5 100644
--- a/src/ext/ed25519/donna/modm-donna-64bit.h
+++ b/src/ext/ed25519/donna/modm-donna-64bit.h
@@ -294,10 +294,10 @@ sub256_modm_batch(bignum256modm out, const bignum256modm a, const bignum256modm
 	size_t i = 0;
 	bignum256modm_element_t carry = 0;
 	switch (limbsize) {
-		case 4: out[i] = (a[i] - b[i])        ; carry = (out[i] >> 63); out[i] &= 0xffffffffffffff; i++;
-		case 3: out[i] = (a[i] - b[i]) - carry; carry = (out[i] >> 63); out[i] &= 0xffffffffffffff; i++;
-		case 2: out[i] = (a[i] - b[i]) - carry; carry = (out[i] >> 63); out[i] &= 0xffffffffffffff; i++;
-		case 1: out[i] = (a[i] - b[i]) - carry; carry = (out[i] >> 63); out[i] &= 0xffffffffffffff; i++;
+		case 4: out[i] = (a[i] - b[i])        ; carry = (out[i] >> 63); out[i] &= 0xffffffffffffff; i++; __attribute__ ((fallthrough));
+		case 3: out[i] = (a[i] - b[i]) - carry; carry = (out[i] >> 63); out[i] &= 0xffffffffffffff; i++; __attribute__ ((fallthrough));
+		case 2: out[i] = (a[i] - b[i]) - carry; carry = (out[i] >> 63); out[i] &= 0xffffffffffffff; i++; __attribute__ ((fallthrough));
+		case 1: out[i] = (a[i] - b[i]) - carry; carry = (out[i] >> 63); out[i] &= 0xffffffffffffff; i++; __attribute__ ((fallthrough));
 		case 0: 
 		default: out[i] = (a[i] - b[i]) - carry;
 	}
@@ -310,10 +310,10 @@ lt256_modm_batch(const bignum256modm a, const bignum256modm b, size_t limbsize)
 	size_t i = 0;
 	bignum256modm_element_t t, carry = 0;
 	switch (limbsize) {
-		case 4: t = (a[i] - b[i])        ; carry = (t >> 63); i++;
-		case 3: t = (a[i] - b[i]) - carry; carry = (t >> 63); i++;
-		case 2: t = (a[i] - b[i]) - carry; carry = (t >> 63); i++;
-		case 1: t = (a[i] - b[i]) - carry; carry = (t >> 63); i++;
+		case 4: t = (a[i] - b[i])        ; carry = (t >> 63); i++; __attribute__ ((fallthrough));
+		case 3: t = (a[i] - b[i]) - carry; carry = (t >> 63); i++; __attribute__ ((fallthrough));
+		case 2: t = (a[i] - b[i]) - carry; carry = (t >> 63); i++; __attribute__ ((fallthrough));
+		case 1: t = (a[i] - b[i]) - carry; carry = (t >> 63); i++; __attribute__ ((fallthrough));
 		case 0: t = (a[i] - b[i]) - carry; carry = (t >> 63);
 	}
 	return (int)carry;
@@ -325,10 +325,10 @@ lte256_modm_batch(const bignum256modm a, const bignum256modm b, size_t limbsize)
 	size_t i = 0;
 	bignum256modm_element_t t, carry = 0;
 	switch (limbsize) {
-		case 4: t = (b[i] - a[i])        ; carry = (t >> 63); i++;
-		case 3: t = (b[i] - a[i]) - carry; carry = (t >> 63); i++;
-		case 2: t = (b[i] - a[i]) - carry; carry = (t >> 63); i++;
-		case 1: t = (b[i] - a[i]) - carry; carry = (t >> 63); i++;
+		case 4: t = (b[i] - a[i])        ; carry = (t >> 63); i++; __attribute__ ((fallthrough));
+		case 3: t = (b[i] - a[i]) - carry; carry = (t >> 63); i++; __attribute__ ((fallthrough));
+		case 2: t = (b[i] - a[i]) - carry; carry = (t >> 63); i++; __attribute__ ((fallthrough));
+		case 1: t = (b[i] - a[i]) - carry; carry = (t >> 63); i++; __attribute__ ((fallthrough));
 		case 0: t = (b[i] - a[i]) - carry; carry = (t >> 63);
 	}
 	return (int)!carry;
-- 
2.13.0


From be85c79304a0eb16e50777219d296d1f7c88bbc1 Mon Sep 17 00:00:00 2001
From: Andreas Stieger <astieger@xxxxxxxx>
Date: Sun, 28 May 2017 22:27:26 +0200
Subject: [PATCH 3/6] Fix implicit fallthrough warning with GCC 7 in
 parse_socks

---
 src/or/buffers.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/or/buffers.c b/src/or/buffers.c
index 58cfdeee8..3692ed4d0 100644
--- a/src/or/buffers.c
+++ b/src/or/buffers.c
@@ -1715,6 +1715,7 @@ parse_socks(const char *data, size_t datalen, socks_request_t *req,
           return -1;
       }
       tor_assert(0);
+      break;
     case 4: { /* socks4 */
       enum {socks4, socks4a} socks4_prot = socks4a;
       const char *authstart, *authend;
-- 
2.13.0


From ed503e58894b11845f0cb5a4f0035d808c86a8e6 Mon Sep 17 00:00:00 2001
From: Andreas Stieger <astieger@xxxxxxxx>
Date: Sun, 28 May 2017 22:32:47 +0200
Subject: [PATCH 4/6] Fix implicit fallthrough warning with GCC 7 in
 connection_edge_process_inbuf

---
 src/or/connection_edge.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index fd9c97bd3..62d5d1773 100644
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@ -261,6 +261,7 @@ connection_edge_process_inbuf(edge_connection_t *conn, int package_partial)
       }
       /* Fall through if the connection is on a circuit without optimistic
        * data support. */
+      __attribute__ ((fallthrough));
     case EXIT_CONN_STATE_CONNECTING:
     case AP_CONN_STATE_RENDDESC_WAIT:
     case AP_CONN_STATE_CIRCUIT_WAIT:
-- 
2.13.0


From e79e63c7c3224b9fe2b40316b60e0f15a685c08f Mon Sep 17 00:00:00 2001
From: Andreas Stieger <astieger@xxxxxxxx>
Date: Sun, 28 May 2017 22:37:19 +0200
Subject: [PATCH 5/6] Fix implicit fallthrough warning with GCC 7 in DNS code

---
 src/or/dns.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/or/dns.c b/src/or/dns.c
index 8a40a70d7..f5b86bf78 100644
--- a/src/or/dns.c
+++ b/src/or/dns.c
@@ -523,6 +523,7 @@ send_resolved_cell,(edge_connection_t *conn, uint8_t answer_type,
         answer_type = RESOLVED_TYPE_ERROR;
         /* fall through. */
       }
+      __attribute__ ((fallthrough));
     case RESOLVED_TYPE_ERROR_TRANSIENT:
     case RESOLVED_TYPE_ERROR:
       {
-- 
2.13.0


From df72046d124fb5083bcb0067f2e3234ad5716a74 Mon Sep 17 00:00:00 2001
From: Andreas Stieger <astieger@xxxxxxxx>
Date: Sun, 28 May 2017 22:40:04 +0200
Subject: [PATCH 6/6] Fix implicit fallthrough warning with GCC 7 in relay code

---
 src/or/relay.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/or/relay.c b/src/or/relay.c
index 7082002f8..a7bf66ac2 100644
--- a/src/or/relay.c
+++ b/src/or/relay.c
@@ -994,6 +994,7 @@ connection_ap_process_end_not_open(
           break; /* break means it'll close, below */
         /* Else fall through: expire this circuit, clear the
          * chosen_exit_name field, and try again. */
+        __attribute__ ((fallthrough));
       case END_STREAM_REASON_RESOLVEFAILED:
       case END_STREAM_REASON_TIMEOUT:
       case END_STREAM_REASON_MISC:
-- 
2.13.0


From a7400446b76977bb84b9b00fd92bd49a0694d028 Mon Sep 17 00:00:00 2001
From: Andreas Stieger <astieger@xxxxxxxx>
Date: Sun, 28 May 2017 22:08:56 +0200
Subject: [PATCH] Fix implicit fallthrough warning in GCC 7 in
 tor_gzip_compress, tor_gzip_uncompress

---
 src/common/torgzip.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/common/torgzip.c b/src/common/torgzip.c
index 04ae353cf..7f6e7deae 100644
--- a/src/common/torgzip.c
+++ b/src/common/torgzip.c
@@ -181,6 +181,7 @@ tor_gzip_compress(char **out, size_t *out_len,
         /* In case zlib doesn't work as I think .... */
         if (stream->avail_out >= stream->avail_in+16)
           break;
+        __attribute__ ((fallthrough));
       case Z_BUF_ERROR:
         offset = stream->next_out - ((unsigned char*)*out);
         old_size = out_size;
@@ -319,6 +320,7 @@ tor_gzip_uncompress(char **out, size_t *out_len,
         /* In case zlib doesn't work as I think.... */
         if (stream->avail_out >= stream->avail_in+16)
           break;
+        __attribute__ ((fallthrough));
       case Z_BUF_ERROR:
         if (stream->avail_out > 0) {
           log_fn(protocol_warn_level, LD_PROTOCOL,
-- 
2.13.0


_______________________________________________
tor-dev mailing list
tor-dev@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-dev