summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorteor <teor@torproject.org>2019-03-25 14:01:20 +1000
committerteor <teor@torproject.org>2019-03-25 14:01:20 +1000
commitd4d541c53c209370ae33f5f6caad2ec13743a4ba (patch)
treea1430960358386b53007e22f5b12eeaf7ad32f45
parent9d0ce0afcce9bbf969d11ba081f829aef5071e9c (diff)
parent065b74fa36344295a12f53e7399e7b20c6d887e0 (diff)
downloadtor-d4d541c53c209370ae33f5f6caad2ec13743a4ba.tar.gz
tor-d4d541c53c209370ae33f5f6caad2ec13743a4ba.zip
Merge remote-tracking branch 'tor-github/pr/785'
-rw-r--r--changes/ticket297563
-rwxr-xr-xscripts/maint/checkSpace.pl32
-rw-r--r--src/feature/control/btrack_orconn_cevent.h1
-rw-r--r--src/feature/control/btrack_orconn_maps.h1
-rw-r--r--src/feature/hs/hs_stats.h4
-rw-r--r--src/lib/log/log.h2
-rw-r--r--src/test/test_connection.h4
-rw-r--r--src/test/test_dir_common.h4
8 files changed, 50 insertions, 1 deletions
diff --git a/changes/ticket29756 b/changes/ticket29756
new file mode 100644
index 0000000000..79995b4995
--- /dev/null
+++ b/changes/ticket29756
@@ -0,0 +1,3 @@
+ o Minor features (developer tools):
+ - Add a script to check that each header has a well-formed and unique
+ guard marco. Closes ticket 29756.
diff --git a/scripts/maint/checkSpace.pl b/scripts/maint/checkSpace.pl
index 633b47e314..433ae62807 100755
--- a/scripts/maint/checkSpace.pl
+++ b/scripts/maint/checkSpace.pl
@@ -18,6 +18,8 @@ if ($ARGV[0] =~ /^-/) {
our %basenames = ();
+our %guardnames = ();
+
for my $fn (@ARGV) {
open(F, "$fn");
my $lastnil = 0;
@@ -31,6 +33,10 @@ for my $fn (@ARGV) {
} else {
$basenames{$basename} = $fn;
}
+ my $isheader = ($fn =~ /\.h/);
+ my $seenguard = 0;
+ my $guardname = "<none>";
+
while (<F>) {
## Warn about windows-style newlines.
# (We insist on lines that end with a single LF character, not
@@ -112,6 +118,23 @@ for my $fn (@ARGV) {
next;
}
}
+
+ if ($isheader) {
+ if ($seenguard == 0) {
+ if (/ifndef\s+(\S+)/) {
+ ++$seenguard;
+ $guardname = $1;
+ }
+ } elsif ($seenguard == 1) {
+ if (/^\#define (\S+)/) {
+ ++$seenguard;
+ if ($1 ne $guardname) {
+ msg "GUARD:$fn:$.: Header guard macro mismatch.\n";
+ }
+ }
+ }
+ }
+
if (m!/\*.*?\*/!) {
s!\s*/\*.*?\*/!!;
} elsif (m!/\*!) {
@@ -201,6 +224,15 @@ for my $fn (@ARGV) {
}
}
}
+ if ($isheader && $C) {
+ if ($seenguard < 2) {
+ msg "$fn:No #ifndef/#define header guard pair found.\n";
+ } elsif ($guardnames{$guardname}) {
+ msg "$fn:Guard macro $guardname also used in $guardnames{$guardname}\n";
+ } else {
+ $guardnames{$guardname} = $fn;
+ }
+ }
close(F);
}
diff --git a/src/feature/control/btrack_orconn_cevent.h b/src/feature/control/btrack_orconn_cevent.h
index f9d24633aa..954b452451 100644
--- a/src/feature/control/btrack_orconn_cevent.h
+++ b/src/feature/control/btrack_orconn_cevent.h
@@ -7,6 +7,7 @@
**/
#ifndef TOR_BTRACK_ORCONN_CEVENT_H
+#define TOR_BTRACK_ORCONN_CEVENT_H
#include "feature/control/btrack_orconn.h"
diff --git a/src/feature/control/btrack_orconn_maps.h b/src/feature/control/btrack_orconn_maps.h
index 3ead40984c..2065eb61b2 100644
--- a/src/feature/control/btrack_orconn_maps.h
+++ b/src/feature/control/btrack_orconn_maps.h
@@ -7,6 +7,7 @@
**/
#ifndef TOR_BTRACK_ORCONN_MAPS_H
+#define TOR_BTRACK_ORCONN_MAPS_H
void bto_delete(uint64_t);
bt_orconn_t *bto_find_or_new(uint64_t, uint64_t);
diff --git a/src/feature/hs/hs_stats.h b/src/feature/hs/hs_stats.h
index d89440faca..ca048e2123 100644
--- a/src/feature/hs/hs_stats.h
+++ b/src/feature/hs/hs_stats.h
@@ -6,9 +6,13 @@
* \brief Header file for hs_stats.c
**/
+#ifndef TOR_HS_STATS_H
+#define TOR_HS_STATS_H
+
void hs_stats_note_introduce2_cell(int is_hsv3);
uint32_t hs_stats_get_n_introduce2_v3_cells(void);
uint32_t hs_stats_get_n_introduce2_v2_cells(void);
void hs_stats_note_service_rendezvous_launch(void);
uint32_t hs_stats_get_n_rendezvous_launches(void);
+#endif
diff --git a/src/lib/log/log.h b/src/lib/log/log.h
index dbc1c47021..0420f35ee0 100644
--- a/src/lib/log/log.h
+++ b/src/lib/log/log.h
@@ -11,6 +11,7 @@
**/
#ifndef TOR_TORLOG_H
+#define TOR_TORLOG_H
#include <stdarg.h>
#include "lib/cc/torint.h"
@@ -278,5 +279,4 @@ MOCK_DECL(STATIC void, logv, (int severity, log_domain_mask_t domain,
va_list ap) CHECK_PRINTF(5,0));
#endif
-# define TOR_TORLOG_H
#endif /* !defined(TOR_TORLOG_H) */
diff --git a/src/test/test_connection.h b/src/test/test_connection.h
index 47a5599e5f..027e405d89 100644
--- a/src/test/test_connection.h
+++ b/src/test/test_connection.h
@@ -1,6 +1,9 @@
/* Copyright (c) 2014-2019, The Tor Project, Inc. */
/* See LICENSE for licensing information */
+#ifndef TOR_TEST_CONNECTION_H
+#define TOR_TEST_CONNECTION_H
+
/** Some constants used by test_connection and helpers */
#define TEST_CONN_FAMILY (AF_INET)
#define TEST_CONN_ADDRESS "127.0.0.1"
@@ -11,3 +14,4 @@
void test_conn_lookup_addr_helper(const char *address,
int family, tor_addr_t *addr);
+#endif
diff --git a/src/test/test_dir_common.h b/src/test/test_dir_common.h
index d6c5241b14..ab99ed36f4 100644
--- a/src/test/test_dir_common.h
+++ b/src/test/test_dir_common.h
@@ -3,6 +3,9 @@
* Copyright (c) 2007-2019, The Tor Project, Inc. */
/* See LICENSE for licensing information */
+#ifndef TOR_TEST_DIR_COMMON_H
+#define TOR_TEST_DIR_COMMON_H
+
#include "core/or/or.h"
#include "feature/nodelist/networkstatus.h"
@@ -49,3 +52,4 @@ int dir_common_construct_vote_3(networkstatus_t **vote,
networkstatus_t **vote_out, int *n_vrs, time_t now,
int clear_rl);
+#endif