From 459f8f201393ac458445aebbd14c45bf4d6f5912 Mon Sep 17 00:00:00 2001 From: iphydf Date: Tue, 9 Aug 2016 13:46:41 +0100 Subject: Check code formatting on Travis. We run astyle on Travis and check if there is a diff. The build terminates if git finds a difference. --- other/bootstrap_daemon/src/command_line_arguments.h | 3 ++- other/bootstrap_daemon/src/config.c | 5 ++--- other/bootstrap_daemon/src/config.h | 6 +++--- other/fun/strkey.c | 13 ++++++++++--- other/travis/toxcore-script | 6 ++++-- 5 files changed, 21 insertions(+), 12 deletions(-) (limited to 'other') diff --git a/other/bootstrap_daemon/src/command_line_arguments.h b/other/bootstrap_daemon/src/command_line_arguments.h index c73cd15e..1d30f428 100644 --- a/other/bootstrap_daemon/src/command_line_arguments.h +++ b/other/bootstrap_daemon/src/command_line_arguments.h @@ -37,6 +37,7 @@ * @param log_backend Sets to the provided by the user log backend option. * @param run_in_foreground Sets to the provided by the user foreground option. */ -void handle_command_line_arguments(int argc, char *argv[], char **cfg_file_path, LOG_BACKEND *log_backend, bool *run_in_foreground); +void handle_command_line_arguments(int argc, char *argv[], char **cfg_file_path, LOG_BACKEND *log_backend, + bool *run_in_foreground); #endif // COMMAND_LINE_ARGUMENTS_H diff --git a/other/bootstrap_daemon/src/config.c b/other/bootstrap_daemon/src/config.c index 12ae693d..29924ae4 100644 --- a/other/bootstrap_daemon/src/config.c +++ b/other/bootstrap_daemon/src/config.c @@ -143,9 +143,8 @@ void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int } int get_general_config(const char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port, - int *enable_ipv6, - int *enable_ipv4_fallback, int *enable_lan_discovery, int *enable_tcp_relay, uint16_t **tcp_relay_ports, - int *tcp_relay_port_count, int *enable_motd, char **motd) + int *enable_ipv6, int *enable_ipv4_fallback, int *enable_lan_discovery, int *enable_tcp_relay, + uint16_t **tcp_relay_ports, int *tcp_relay_port_count, int *enable_motd, char **motd) { config_t cfg; diff --git a/other/bootstrap_daemon/src/config.h b/other/bootstrap_daemon/src/config.h index 13cf929a..93e7fc49 100644 --- a/other/bootstrap_daemon/src/config.h +++ b/other/bootstrap_daemon/src/config.h @@ -37,9 +37,9 @@ * @return 1 on success, * 0 on failure, doesn't modify any data pointed by arguments. */ -int get_general_config(const char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port, int *enable_ipv6, - int *enable_ipv4_fallback, int *enable_lan_discovery, int *enable_tcp_relay, uint16_t **tcp_relay_ports, - int *tcp_relay_port_count, int *enable_motd, char **motd); +int get_general_config(const char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port, + int *enable_ipv6, int *enable_ipv4_fallback, int *enable_lan_discovery, int *enable_tcp_relay, + uint16_t **tcp_relay_ports, int *tcp_relay_port_count, int *enable_motd, char **motd); /** * Bootstraps off nodes listed in the config file. diff --git a/other/fun/strkey.c b/other/fun/strkey.c index 7e5a1e1c..649b26dd 100644 --- a/other/fun/strkey.c +++ b/other/fun/strkey.c @@ -46,6 +46,7 @@ void print_key(unsigned char *key) { size_t i; + for (i = 0; i < crypto_box_PUBLICKEYBYTES; i++) { if (key[i] < 16) { fprintf(stdout, "0"); @@ -67,11 +68,14 @@ int main(int argc, char *argv[]) offset = atoi(argv[1]); char *desired_hex = argv[2]; len = strlen(desired_hex); + if (len % 2 != 0) { fprintf(stderr, "Desired key should have an even number of letters\n"); exit(1); } - size_t block_length = (offset < 0 ? 0 : offset) + len/2; + + size_t block_length = (offset < 0 ? 0 : offset) + len / 2; + if (block_length > crypto_box_PUBLICKEYBYTES) { fprintf(stderr, "The given key with the given offset exceed public key's length\n"); exit(1); @@ -80,6 +84,7 @@ int main(int argc, char *argv[]) // convert hex to bin char *pos = desired_hex; size_t i; + for (i = 0; i < len; pos += 2) { sscanf(pos, "%2hhx", &desired_bin[i]); ++i; @@ -97,12 +102,14 @@ int main(int argc, char *argv[]) if (offset < 0) { int found = 0; + do { #ifdef PRINT_TRIES_COUNT tries ++; #endif crypto_box_keypair(public_key, secret_key); int i; + for (i = 0; i <= crypto_box_PUBLICKEYBYTES - len; i ++) { if (memcmp(public_key + i, desired_bin, len) == 0) { found = 1; @@ -115,7 +122,7 @@ int main(int argc, char *argv[]) do { #ifdef PRINT_TRIES_COUNT - tries ++; + tries ++; #endif crypto_box_keypair(public_key, secret_key); } while (memcmp(p, desired_bin, len) != 0); @@ -130,7 +137,7 @@ int main(int argc, char *argv[]) fprintf(stdout, "\n"); #ifdef PRINT_TRIES_COUNT - fprintf(stdout, "Found the key pair on %llu try.\n", tries); + fprintf(stdout, "Found the key pair on %llu try.\n", tries); #endif return 0; diff --git a/other/travis/toxcore-script b/other/travis/toxcore-script index b2ee5d02..b99bbe5b 100755 --- a/other/travis/toxcore-script +++ b/other/travis/toxcore-script @@ -3,8 +3,10 @@ set -e -x # Check if toxcore.h and toxav.h match apidsl tox.in.h and toxav.in.h. -../apidsl/_build/apigen.native ./other/apidsl/tox.in.h | $ASTYLE --options=./other/astyle/astylerc > toxcore/tox.h -../apidsl/_build/apigen.native ./other/apidsl/toxav.in.h | $ASTYLE --options=./other/astyle/astylerc > toxav/toxav.h +../apidsl/_build/apigen.native other/apidsl/tox.in.h | $ASTYLE --options=other/astyle/astylerc > toxcore/tox.h +../apidsl/_build/apigen.native other/apidsl/toxav.in.h | $ASTYLE --options=other/astyle/astylerc > toxav/toxav.h +# Check if the code is formatted according to the astyle configuration. +$ASTYLE --options=other/astyle/astylerc `find . -name "*.[ch]" -and -not -name "*.in.*" -and -not -wholename "*crypto_pwhash*" -and -not -wholename "./super_donators/*"` git diff --exit-code # Build toxcore and run tests. -- cgit v1.2.3