Work around a GCC bug that causes inet_checksum() to give wrong results.
[tinc] / src / route.c
index a3e9202..4d71279 100644 (file)
@@ -59,6 +59,7 @@ static const size_t opt_size = sizeof(struct nd_opt_hdr);
 #define MAX(a, b) ((a) > (b) ? (a) : (b))
 #endif
 
+volatile int dummy;
 static timeout_t age_subnets_timeout;
 
 /* RFC 1071 */
@@ -80,6 +81,11 @@ static uint16_t inet_checksum(void *data, int len, uint16_t prevsum) {
                checksum = (checksum & 0xFFFF) + (checksum >> 16);
        }
 
+       // Work around a compiler optimization bug.
+       if(checksum) {
+               dummy = 1;
+       }
+
        return ~checksum;
 }