diff options
author | iphydf <iphydf@users.noreply.github.com> | 2020-05-02 00:34:13 +0100 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2020-05-02 22:00:09 +0100 |
commit | f8ab32aaa4efce2c9a310a14d10b19fb8544cfd9 (patch) | |
tree | 4dbc49882d6af0954c533b2482b2100d312d2bc7 | |
parent | 2570ddcb17fdf5bea56c6bc1c5c2d04ba2068ee7 (diff) |
Add a check that we don't have any unused functions.
This check puts all of our code in a C++ anonymous namespace, which is
effectively making all functions `static`. This allows the compiler to
determine that a function is unused, so we can delete it.
-rw-r--r-- | other/analysis/gen-file.sh | 35 | ||||
-rw-r--r-- | other/bootstrap_daemon/docker/tox-bootstrapd.sha256 | 2 | ||||
-rw-r--r-- | other/cpufeatures.c | 2 | ||||
-rw-r--r-- | testing/DHT_test.c | 1 | ||||
-rw-r--r-- | toxcore/LAN_discovery.api.h | 2 | ||||
-rw-r--r-- | toxcore/LAN_discovery.h | 2 | ||||
-rw-r--r-- | toxcore/Messenger.c | 32 | ||||
-rw-r--r-- | toxcore/Messenger.h | 9 | ||||
-rw-r--r-- | toxcore/crypto_core.c | 3 | ||||
-rw-r--r-- | toxcore/group.c | 30 | ||||
-rw-r--r-- | toxcore/group.h | 13 | ||||
-rw-r--r-- | toxcore/list.c | 10 | ||||
-rw-r--r-- | toxcore/list.h | 8 | ||||
-rw-r--r-- | toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c | 2 |
14 files changed, 28 insertions, 123 deletions
diff --git a/other/analysis/gen-file.sh b/other/analysis/gen-file.sh index 019bd8f9..ad8df3b8 100644 --- a/other/analysis/gen-file.sh +++ b/other/analysis/gen-file.sh | |||
@@ -17,20 +17,20 @@ put() { | |||
17 | if [ "$SKIP_LINES" = "" ]; then | 17 | if [ "$SKIP_LINES" = "" ]; then |
18 | echo "#line 1 \"$1\"" >> amalgamation.cc | 18 | echo "#line 1 \"$1\"" >> amalgamation.cc |
19 | fi | 19 | fi |
20 | cat $1 >> amalgamation.cc | 20 | cat "$1" >> amalgamation.cc |
21 | } | 21 | } |
22 | 22 | ||
23 | putmain() { | 23 | putmain() { |
24 | echo "namespace $(echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g') {" >> amalgamation.cc | 24 | echo "namespace $(echo "$1" | sed -e 's/[^a-zA-Z0-9_]/_/g') {" >> amalgamation.cc |
25 | if [ "$SKIP_LINES" = "" ]; then | 25 | if [ "$SKIP_LINES" = "" ]; then |
26 | echo "#line 1 \"$1\"" >> amalgamation.cc | 26 | echo "#line 1 \"$1\"" >> amalgamation.cc |
27 | fi | 27 | fi |
28 | sed -e 's/^int main(/static &/' $1 >> amalgamation.cc | 28 | sed -e 's/^int main(/static &/' "$1" >> amalgamation.cc |
29 | echo "} // namespace $(echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g')" >> amalgamation.cc | 29 | echo "} // namespace $(echo "$1" | sed -e 's/[^a-zA-Z0-9_]/_/g')" >> amalgamation.cc |
30 | } | 30 | } |
31 | 31 | ||
32 | callmain() { | 32 | callmain() { |
33 | echo " call($(echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g')::main, argc, argv);" >> amalgamation.cc | 33 | echo " call($(echo "$1" | sed -e 's/[^a-zA-Z0-9_]/_/g')::main, argc, argv);" >> amalgamation.cc |
34 | } | 34 | } |
35 | 35 | ||
36 | :> amalgamation.cc | 36 | :> amalgamation.cc |
@@ -53,25 +53,32 @@ FIND_QUERY="$FIND_QUERY -and -not -name av_test.c" | |||
53 | FIND_QUERY="$FIND_QUERY -and -not -name dht_test.c" | 53 | FIND_QUERY="$FIND_QUERY -and -not -name dht_test.c" |
54 | FIND_QUERY="$FIND_QUERY -and -not -name version_test.c" | 54 | FIND_QUERY="$FIND_QUERY -and -not -name version_test.c" |
55 | 55 | ||
56 | for i in $(eval $FIND_QUERY); do | 56 | (for i in $(eval "$FIND_QUERY"); do |
57 | if ! grep -q '^int main(' $i; then | 57 | grep -o '#include <[^>]*>' "$i" \ |
58 | put $i | 58 | | grep -E -v '<win|<ws|<iphlp|<libc|<mach/|<crypto_|<randombytes|<u.h>|<sys/filio|<linux' |
59 | done) | sort -u >> amalgamation.cc | ||
60 | |||
61 | echo 'namespace {' >> amalgamation.cc | ||
62 | for i in $(eval "$FIND_QUERY"); do | ||
63 | if ! grep -q '^int main(' "$i"; then | ||
64 | put "$i" | ||
59 | fi | 65 | fi |
60 | done | 66 | done |
61 | 67 | ||
62 | for i in $(eval $FIND_QUERY); do | 68 | for i in $(eval "$FIND_QUERY"); do |
63 | if grep -q '^int main(' $i; then | 69 | if grep -q '^int main(' "$i"; then |
64 | putmain $i | 70 | putmain "$i" |
65 | fi | 71 | fi |
66 | done | 72 | done |
67 | 73 | ||
68 | echo "static void call(int m(), int argc, char **argv) { m(); }" >> amalgamation.cc | 74 | echo "static void call(int m(), int argc, char **argv) { m(); }" >> amalgamation.cc |
69 | echo "static void call(int m(int, char **), int argc, char **argv) { m(argc, argv); }" >> amalgamation.cc | 75 | echo "static void call(int m(int, char **), int argc, char **argv) { m(argc, argv); }" >> amalgamation.cc |
76 | echo '} // namespace' >> amalgamation.cc | ||
70 | 77 | ||
71 | echo "int main(int argc, char **argv) {" >> amalgamation.cc | 78 | echo "int main(int argc, char **argv) {" >> amalgamation.cc |
72 | for i in $(eval $FIND_QUERY); do | 79 | for i in $(eval "$FIND_QUERY"); do |
73 | if grep -q '^int main(' $i; then | 80 | if grep -q '^int main(' "$i"; then |
74 | callmain $i | 81 | callmain "$i" |
75 | fi | 82 | fi |
76 | done | 83 | done |
77 | echo " return 0;" >> amalgamation.cc | 84 | echo " return 0;" >> amalgamation.cc |
diff --git a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 index 5287541b..4d02d38f 100644 --- a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 +++ b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 | |||
@@ -1 +1 @@ | |||
e7b6d31485b5e1561659be08f3e3ef003cef186042d7e0fe2ef48cf341932b5a /usr/local/bin/tox-bootstrapd | 89df21d6a19a1b6652db5b7e6e9f65ad5f8be8abdca9f58645548b9e0c9383e3 /usr/local/bin/tox-bootstrapd | ||
diff --git a/other/cpufeatures.c b/other/cpufeatures.c index 3da06e58..38c97059 100644 --- a/other/cpufeatures.c +++ b/other/cpufeatures.c | |||
@@ -3,4 +3,4 @@ | |||
3 | #include ANDROID_CPU_FEATURES | 3 | #include ANDROID_CPU_FEATURES |
4 | #endif | 4 | #endif |
5 | 5 | ||
6 | extern int unused_declaration; | 6 | typedef int unused_declaration; |
diff --git a/testing/DHT_test.c b/testing/DHT_test.c index 8ba61ec2..5f28eb99 100644 --- a/testing/DHT_test.c +++ b/testing/DHT_test.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #define _XOPEN_SOURCE 600 | 17 | #define _XOPEN_SOURCE 600 |
18 | #endif | 18 | #endif |
19 | 19 | ||
20 | #include <assert.h> | ||
20 | #include <stdlib.h> | 21 | #include <stdlib.h> |
21 | #include <stdio.h> | 22 | #include <stdio.h> |
22 | #include <string.h> | 23 | #include <string.h> |
diff --git a/toxcore/LAN_discovery.api.h b/toxcore/LAN_discovery.api.h index 5c25b67b..ad3d60ed 100644 --- a/toxcore/LAN_discovery.api.h +++ b/toxcore/LAN_discovery.api.h | |||
@@ -21,7 +21,7 @@ namespace lan_discovery { | |||
21 | /** | 21 | /** |
22 | * Interval in seconds between LAN discovery packet sending. | 22 | * Interval in seconds between LAN discovery packet sending. |
23 | */ | 23 | */ |
24 | const INTERVAL = 10; | 24 | #define LAN_DISCOVERY_INTERVAL 10 |
25 | 25 | ||
26 | /** | 26 | /** |
27 | * Send a LAN discovery pcaket to the broadcast address with port port. | 27 | * Send a LAN discovery pcaket to the broadcast address with port port. |
diff --git a/toxcore/LAN_discovery.h b/toxcore/LAN_discovery.h index 7e049b99..6b55e319 100644 --- a/toxcore/LAN_discovery.h +++ b/toxcore/LAN_discovery.h | |||
@@ -26,8 +26,6 @@ typedef struct IP IP; | |||
26 | */ | 26 | */ |
27 | #define LAN_DISCOVERY_INTERVAL 10 | 27 | #define LAN_DISCOVERY_INTERVAL 10 |
28 | 28 | ||
29 | uint32_t lan_discovery_interval(void); | ||
30 | |||
31 | /** | 29 | /** |
32 | * Send a LAN discovery pcaket to the broadcast address with port port. | 30 | * Send a LAN discovery pcaket to the broadcast address with port port. |
33 | */ | 31 | */ |
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 82c31147..556acc27 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -1450,38 +1450,6 @@ int file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uin | |||
1450 | return -6; | 1450 | return -6; |
1451 | } | 1451 | } |
1452 | 1452 | ||
1453 | /* Give the number of bytes left to be sent/received. | ||
1454 | * | ||
1455 | * send_receive is 0 if we want the sending files, 1 if we want the receiving. | ||
1456 | * | ||
1457 | * return number of bytes remaining to be sent/received on success | ||
1458 | * return 0 on failure | ||
1459 | */ | ||
1460 | uint64_t file_dataremaining(const Messenger *m, int32_t friendnumber, uint8_t filenumber, uint8_t send_receive) | ||
1461 | { | ||
1462 | if (!friend_is_valid(m, friendnumber)) { | ||
1463 | return 0; | ||
1464 | } | ||
1465 | |||
1466 | const struct File_Transfers *const sending = &m->friendlist[friendnumber].file_sending[filenumber]; | ||
1467 | |||
1468 | if (send_receive == 0) { | ||
1469 | if (sending->status == FILESTATUS_NONE) { | ||
1470 | return 0; | ||
1471 | } | ||
1472 | |||
1473 | return sending->size - sending->transferred; | ||
1474 | } | ||
1475 | |||
1476 | const struct File_Transfers *const receiving = &m->friendlist[friendnumber].file_receiving[filenumber]; | ||
1477 | |||
1478 | if (receiving->status == FILESTATUS_NONE) { | ||
1479 | return 0; | ||
1480 | } | ||
1481 | |||
1482 | return receiving->size - receiving->transferred; | ||
1483 | } | ||
1484 | |||
1485 | /** | 1453 | /** |
1486 | * Iterate over all file transfers and request chunks (from the client) for each | 1454 | * Iterate over all file transfers and request chunks (from the client) for each |
1487 | * of them. | 1455 | * of them. |
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index 74c19e09..31526b63 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h | |||
@@ -651,15 +651,6 @@ int file_seek(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uin | |||
651 | int file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uint64_t position, const uint8_t *data, | 651 | int file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uint64_t position, const uint8_t *data, |
652 | uint16_t length); | 652 | uint16_t length); |
653 | 653 | ||
654 | /* Give the number of bytes left to be sent/received. | ||
655 | * | ||
656 | * send_receive is 0 if we want the sending files, 1 if we want the receiving. | ||
657 | * | ||
658 | * return number of bytes remaining to be sent/received on success | ||
659 | * return 0 on failure | ||
660 | */ | ||
661 | uint64_t file_dataremaining(const Messenger *m, int32_t friendnumber, uint8_t filenumber, uint8_t send_receive); | ||
662 | |||
663 | /** A/V related */ | 654 | /** A/V related */ |
664 | 655 | ||
665 | /* Set the callback for msi packets. | 656 | /* Set the callback for msi packets. |
diff --git a/toxcore/crypto_core.c b/toxcore/crypto_core.c index 403e0872..2fa4750f 100644 --- a/toxcore/crypto_core.c +++ b/toxcore/crypto_core.c | |||
@@ -12,11 +12,12 @@ | |||
12 | #include "config.h" | 12 | #include "config.h" |
13 | #endif | 13 | #endif |
14 | 14 | ||
15 | #include "crypto_core.h" | ||
16 | |||
15 | #include <stdlib.h> | 17 | #include <stdlib.h> |
16 | #include <string.h> | 18 | #include <string.h> |
17 | 19 | ||
18 | #include "ccompat.h" | 20 | #include "ccompat.h" |
19 | #include "crypto_core.h" | ||
20 | 21 | ||
21 | #ifndef VANILLA_NACL | 22 | #ifndef VANILLA_NACL |
22 | /* We use libsodium by default. */ | 23 | /* We use libsodium by default. */ |
diff --git a/toxcore/group.c b/toxcore/group.c index 3e04f181..a946e7b8 100644 --- a/toxcore/group.c +++ b/toxcore/group.c | |||
@@ -1301,36 +1301,6 @@ int group_set_max_frozen(const Group_Chats *g_c, uint32_t groupnumber, uint32_t | |||
1301 | return 0; | 1301 | return 0; |
1302 | } | 1302 | } |
1303 | 1303 | ||
1304 | /* List all the (frozen, if frozen is true) peers in the group chat. | ||
1305 | * | ||
1306 | * Copies the names of the peers to the `name[length][MAX_NAME_LENGTH]` array. | ||
1307 | * | ||
1308 | * Copies the lengths of the names to `lengths[length]` | ||
1309 | * | ||
1310 | * returns the number of peers on success. | ||
1311 | * | ||
1312 | * return -1 on failure. | ||
1313 | */ | ||
1314 | int group_names(const Group_Chats *g_c, uint32_t groupnumber, uint8_t names[][MAX_NAME_LENGTH], uint16_t lengths[], | ||
1315 | uint16_t length, bool frozen) | ||
1316 | { | ||
1317 | const Group_c *g = get_group_c(g_c, groupnumber); | ||
1318 | |||
1319 | if (!g) { | ||
1320 | return -1; | ||
1321 | } | ||
1322 | |||
1323 | const uint32_t num = frozen ? g->numfrozen : g->numpeers; | ||
1324 | |||
1325 | unsigned int i; | ||
1326 | |||
1327 | for (i = 0; i < num && i < length; ++i) { | ||
1328 | lengths[i] = group_peername(g_c, groupnumber, i, names[i], frozen); | ||
1329 | } | ||
1330 | |||
1331 | return i; | ||
1332 | } | ||
1333 | |||
1334 | /* Return the number of (frozen, if frozen is true) peers in the group chat on | 1304 | /* Return the number of (frozen, if frozen is true) peers in the group chat on |
1335 | * success. | 1305 | * success. |
1336 | * return -1 if groupnumber is invalid. | 1306 | * return -1 if groupnumber is invalid. |
diff --git a/toxcore/group.h b/toxcore/group.h index 1e054de3..eb8db55f 100644 --- a/toxcore/group.h +++ b/toxcore/group.h | |||
@@ -355,19 +355,6 @@ int group_number_peers(const Group_Chats *g_c, uint32_t groupnumber, bool frozen | |||
355 | */ | 355 | */ |
356 | int group_peernumber_is_ours(const Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber); | 356 | int group_peernumber_is_ours(const Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber); |
357 | 357 | ||
358 | /* List all the (frozen, if frozen is true) peers in the group chat. | ||
359 | * | ||
360 | * Copies the names of the peers to the `name[length][MAX_NAME_LENGTH]` array. | ||
361 | * | ||
362 | * Copies the lengths of the names to `lengths[length]` | ||
363 | * | ||
364 | * returns the number of peers on success. | ||
365 | * | ||
366 | * return -1 on failure. | ||
367 | */ | ||
368 | int group_names(const Group_Chats *g_c, uint32_t groupnumber, uint8_t names[][MAX_NAME_LENGTH], uint16_t lengths[], | ||
369 | uint16_t length, bool frozen); | ||
370 | |||
371 | /* Set handlers for custom lossy packets. */ | 358 | /* Set handlers for custom lossy packets. */ |
372 | void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, lossy_packet_cb *function); | 359 | void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, lossy_packet_cb *function); |
373 | 360 | ||
diff --git a/toxcore/list.c b/toxcore/list.c index cb3c71cc..fca8cea8 100644 --- a/toxcore/list.c +++ b/toxcore/list.c | |||
@@ -248,13 +248,3 @@ int bs_list_remove(BS_List *list, const uint8_t *data, int id) | |||
248 | 248 | ||
249 | return 1; | 249 | return 1; |
250 | } | 250 | } |
251 | |||
252 | int bs_list_trim(BS_List *list) | ||
253 | { | ||
254 | if (!resize(list, list->n)) { | ||
255 | return 0; | ||
256 | } | ||
257 | |||
258 | list->capacity = list->n; | ||
259 | return 1; | ||
260 | } | ||
diff --git a/toxcore/list.h b/toxcore/list.h index 9d65b53f..afe4240b 100644 --- a/toxcore/list.h +++ b/toxcore/list.h | |||
@@ -57,12 +57,4 @@ int bs_list_add(BS_List *list, const uint8_t *data, int id); | |||
57 | */ | 57 | */ |
58 | int bs_list_remove(BS_List *list, const uint8_t *data, int id); | 58 | int bs_list_remove(BS_List *list, const uint8_t *data, int id); |
59 | 59 | ||
60 | /* Removes the memory overhead | ||
61 | * | ||
62 | * return value: | ||
63 | * 1 : success | ||
64 | * 0 : failure | ||
65 | */ | ||
66 | int bs_list_trim(BS_List *list); | ||
67 | |||
68 | #endif | 60 | #endif |
diff --git a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c index 7f015238..38a536a6 100644 --- a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c +++ b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c | |||
@@ -398,4 +398,4 @@ escrypt_kdf_sse(escrypt_local_t * local, | |||
398 | #endif | 398 | #endif |
399 | 399 | ||
400 | /* ISO C requires a translation unit to contain at least one declaration */ | 400 | /* ISO C requires a translation unit to contain at least one declaration */ |
401 | extern int non_empty_tu_decl; | 401 | typedef int non_empty_tu_decl; |