diff options
author | iphydf <iphydf@users.noreply.github.com> | 2016-09-05 14:43:58 +0100 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2016-09-06 11:09:10 +0100 |
commit | 5b57ab6332edc407524a353d3965a4870c33fe00 (patch) | |
tree | 238659ca8e218307fff1476d427c94194bc24fad /testing | |
parent | aad1e0ad3f96786e0fb10d8dd144e5e6ebe93258 (diff) |
Improve C standard compliance.
- Don't cast between object and function pointers.
- Use standard compliant `__VA_ARGS__` in macros.
- Add explicit `__extension__` on unnamed union in struct (it's a GNU
extension).
- Remove ; after function definitions.
- Replace `const T foo = 3;` for integral types `T` with `enum { foo = 3 };`.
Folding integral constants like that as compile time constants is a GNU
extension. Arrays allocated with `foo` as dimension are VLAs on strictly
compliant C99 compilers.
- Replace empty initialiser list `{}` with zero-initialiser-list `{0}`.
The former is a GNU extension meaning the latter.
- Cast `T*` (where `T != void`) to `void *` in format arguments. While any
object pointer can be implicitly converted to and from `void *`, this
conversion does not happen in variadic function calls.
- Replace arithmetic on `void *` with arithmetic on `char *`. The former
is non-compliant.
- Replace non-`int`-derived types (like `uint16_t`, which is
`short`-derived) in bit fields with `int`-derived types. Using any type
other than `int` or `unsigned int` (or any of their aliases) in bit
fields is a GNU extension.
Diffstat (limited to 'testing')
-rw-r--r-- | testing/dns3_test.c | 2 | ||||
-rw-r--r-- | testing/misc_tools.c | 2 | ||||
-rw-r--r-- | testing/nTox.c | 2 |
3 files changed, 3 insertions, 3 deletions
diff --git a/testing/dns3_test.c b/testing/dns3_test.c index 063ea8c7..830ecfd8 100644 --- a/testing/dns3_test.c +++ b/testing/dns3_test.c | |||
@@ -102,7 +102,7 @@ int main(int argc, char *argv[]) | |||
102 | return -1; | 102 | return -1; |
103 | } | 103 | } |
104 | 104 | ||
105 | uint8_t buffer[512] = {}; | 105 | uint8_t buffer[512] = {0}; |
106 | int r_len = recv(sock, buffer, sizeof(buffer), 0); | 106 | int r_len = recv(sock, buffer, sizeof(buffer), 0); |
107 | 107 | ||
108 | if (r_len < (int)p_len) { | 108 | if (r_len < (int)p_len) { |
diff --git a/testing/misc_tools.c b/testing/misc_tools.c index de246d82..b667f991 100644 --- a/testing/misc_tools.c +++ b/testing/misc_tools.c | |||
@@ -85,4 +85,4 @@ int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *ipv6enabled) | |||
85 | } | 85 | } |
86 | 86 | ||
87 | return argvoffset; | 87 | return argvoffset; |
88 | }; | 88 | } |
diff --git a/testing/nTox.c b/testing/nTox.c index ec6b152c..fcfbe004 100644 --- a/testing/nTox.c +++ b/testing/nTox.c | |||
@@ -57,7 +57,7 @@ uint8_t flag[HISTORY]; | |||
57 | char input_line[STRING_LENGTH]; | 57 | char input_line[STRING_LENGTH]; |
58 | 58 | ||
59 | /* wrap: continuation mark */ | 59 | /* wrap: continuation mark */ |
60 | const size_t wrap_cont_len = 3; | 60 | enum { wrap_cont_len = 3 }; |
61 | const char wrap_cont_str[] = "\n+ "; | 61 | const char wrap_cont_str[] = "\n+ "; |
62 | 62 | ||
63 | #define STRING_LENGTH_WRAPPED (STRING_LENGTH + 16 * (wrap_cont_len + 1)) | 63 | #define STRING_LENGTH_WRAPPED (STRING_LENGTH + 16 * (wrap_cont_len + 1)) |