From ad2656051697899e960694bb68ac104fcc5e92f1 Mon Sep 17 00:00:00 2001 From: iphydf Date: Mon, 5 Sep 2016 16:10:48 +0100 Subject: Improve static and const correctness. - Any non-externally-visible declarations should be `static`. - Casting away the `const` qualifier from pointers-to-const is dangerous. All but one instance of this are now correct. The one instance where we can't keep `const` is one where toxav code actually writes to a chunk of memory marked as `const`. This code also assumes 4 byte alignment of data packets. I don't know whether that is a valid assumption, but it's likely unportable, and *not* obviously correct. - Replaced empty parameter lists with `(void)` to avoid passing parameters to it. Empty parameter lists are old style declarations for unknown number and type of arguments. - Commented out (as `#if DHT_HARDENING` block) the hardening code that was never executed. - Minor style fix: don't use `default` in enum-switches unless the number of enumerators in the default case is very large. In this case, it was 2, so we want to list them both explicitly to be warned about missing one if we add one in the future. - Removed the only two function declarations from nTox.h and put them into nTox.c. They are not used outside and nTox is not a library. --- auto_tests/toxav_basic_test.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'auto_tests/toxav_basic_test.c') diff --git a/auto_tests/toxav_basic_test.c b/auto_tests/toxav_basic_test.c index e3c4447e..399eac68 100644 --- a/auto_tests/toxav_basic_test.c +++ b/auto_tests/toxav_basic_test.c @@ -6,7 +6,7 @@ # include # define ck_assert(X) assert(X); -# define START_TEST(NAME) void NAME () +# define START_TEST(NAME) static void NAME (void) # define END_TEST #else # include "helpers.h" @@ -66,7 +66,7 @@ typedef struct { /** * Callbacks */ -void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data) +static void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data) { (void) av; (void) friend_number; @@ -76,7 +76,7 @@ void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool printf("Handling CALL callback\n"); ((CallControl *)user_data)->incoming = true; } -void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data) +static void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data) { (void) av; (void) friend_number; @@ -84,11 +84,11 @@ void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, vo printf("Handling CALL STATE callback: %d\n", state); ((CallControl *)user_data)->state = state; } -void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, - uint16_t width, uint16_t height, - uint8_t const *y, uint8_t const *u, uint8_t const *v, - int32_t ystride, int32_t ustride, int32_t vstride, - void *user_data) +static void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, + uint16_t width, uint16_t height, + uint8_t const *y, uint8_t const *u, uint8_t const *v, + int32_t ystride, int32_t ustride, int32_t vstride, + void *user_data) { (void) av; (void) friend_number; @@ -103,12 +103,12 @@ void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, (void) user_data; printf("Received video payload\n"); } -void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, - int16_t const *pcm, - size_t sample_count, - uint8_t channels, - uint32_t sampling_rate, - void *user_data) +static void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, + int16_t const *pcm, + size_t sample_count, + uint8_t channels, + uint32_t sampling_rate, + void *user_data) { (void) av; (void) friend_number; @@ -119,7 +119,8 @@ void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, (void) user_data; printf("Received audio payload\n"); } -void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) +static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, + void *userdata) { (void) userdata; @@ -132,7 +133,7 @@ void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t /** * Iterate helper */ -int iterate_tox(Tox *bootstrap, Tox *Alice, Tox *Bob) +static int iterate_tox(Tox *bootstrap, Tox *Alice, Tox *Bob) { c_sleep(100); tox_iterate(bootstrap, NULL); @@ -175,7 +176,7 @@ START_TEST(test_AV_flows) tox_self_get_address(Alice, address); - ck_assert(tox_friend_add(Bob, address, (uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); + ck_assert(tox_friend_add(Bob, address, (const uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); uint8_t off = 1; @@ -601,7 +602,7 @@ int main(int argc, char *argv[]) return 0; } #else -Suite *tox_suite(void) +static Suite *tox_suite(void) { Suite *s = suite_create("ToxAV"); -- cgit v1.2.3