diff options
author | iphydf <iphydf@users.noreply.github.com> | 2016-09-05 16:10:48 +0100 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2016-09-06 11:54:37 +0100 |
commit | ad2656051697899e960694bb68ac104fcc5e92f1 (patch) | |
tree | 7e69fcd03db88b3839ee523f5d1b51ef9a38c372 /testing/Messenger_test.c | |
parent | 4e6c86d1cb228308678f89ff6e4e09b3f46347aa (diff) |
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.
Diffstat (limited to 'testing/Messenger_test.c')
-rw-r--r-- | testing/Messenger_test.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c index 668f046a..84508621 100644 --- a/testing/Messenger_test.c +++ b/testing/Messenger_test.c | |||
@@ -56,18 +56,18 @@ | |||
56 | 56 | ||
57 | #endif | 57 | #endif |
58 | 58 | ||
59 | void print_message(Messenger *m, uint32_t friendnumber, unsigned int type, const uint8_t *string, size_t length, | 59 | static void print_message(Messenger *m, uint32_t friendnumber, unsigned int type, const uint8_t *string, size_t length, |
60 | void *userdata) | 60 | void *userdata) |
61 | { | 61 | { |
62 | printf("Message with length %lu received from %u: %s \n", length, friendnumber, string); | 62 | printf("Message with length %lu received from %u: %s \n", length, friendnumber, string); |
63 | m_send_message_generic(m, friendnumber, type, (uint8_t *)"Test1", 6, 0); | 63 | m_send_message_generic(m, friendnumber, type, (const uint8_t *)"Test1", 6, 0); |
64 | } | 64 | } |
65 | 65 | ||
66 | /* FIXME needed as print_request has to match the interface expected by | 66 | /* FIXME needed as print_request has to match the interface expected by |
67 | * networking_requesthandler and so cannot take a Messenger * */ | 67 | * networking_requesthandler and so cannot take a Messenger * */ |
68 | static Messenger *m; | 68 | static Messenger *m; |
69 | 69 | ||
70 | void print_request(Messenger *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) | 70 | static void print_request(Messenger *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) |
71 | { | 71 | { |
72 | printf("Friend request received from: \n"); | 72 | printf("Friend request received from: \n"); |
73 | printf("ClientID: "); | 73 | printf("ClientID: "); |
@@ -164,7 +164,7 @@ int main(int argc, char *argv[]) | |||
164 | printf("%hhX", address[i]); | 164 | printf("%hhX", address[i]); |
165 | } | 165 | } |
166 | 166 | ||
167 | setname(m, (uint8_t *)"Anon", 5); | 167 | setname(m, (const uint8_t *)"Anon", 5); |
168 | 168 | ||
169 | char temp_hex_id[128]; | 169 | char temp_hex_id[128]; |
170 | printf("\nEnter the address of the friend you wish to add (38 bytes HEX format):\n"); | 170 | printf("\nEnter the address of the friend you wish to add (38 bytes HEX format):\n"); |
@@ -178,7 +178,7 @@ int main(int argc, char *argv[]) | |||
178 | } | 178 | } |
179 | 179 | ||
180 | uint8_t *bin_id = hex_string_to_bin(temp_hex_id); | 180 | uint8_t *bin_id = hex_string_to_bin(temp_hex_id); |
181 | int num = m_addfriend(m, bin_id, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo")); | 181 | int num = m_addfriend(m, bin_id, (const uint8_t *)"Install Gentoo", sizeof("Install Gentoo")); |
182 | free(bin_id); | 182 | free(bin_id); |
183 | 183 | ||
184 | perror("Initialization"); | 184 | perror("Initialization"); |
@@ -188,7 +188,7 @@ int main(int argc, char *argv[]) | |||
188 | getname(m, num, name); | 188 | getname(m, num, name); |
189 | printf("%s\n", name); | 189 | printf("%s\n", name); |
190 | 190 | ||
191 | m_send_message_generic(m, num, MESSAGE_NORMAL, (uint8_t *)"Test", 5, 0); | 191 | m_send_message_generic(m, num, MESSAGE_NORMAL, (const uint8_t *)"Test", 5, 0); |
192 | do_messenger(m, NULL); | 192 | do_messenger(m, NULL); |
193 | c_sleep(30); | 193 | c_sleep(30); |
194 | FILE *file = fopen("Save.bak", "wb"); | 194 | FILE *file = fopen("Save.bak", "wb"); |