From 32e30ac30ce3e4833062c1f32026cd64182418d5 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com> Date: Sat, 31 Jul 2021 09:27:11 +0200 Subject: [PATCH] Fix Linux kernel coding style error and warnings "foo * bar" should be "foo *bar" "foo* bar" should be "foo *bar" "(foo * )" should be "(foo *)" Use the name ARRAY_SIZE() for a macro (as in Linux kernel). Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com> --- library.c | 4 ++-- openconnect-internal.h | 2 +- tests/bad_dtls_test.c | 6 ++++-- tests/buftest.c | 21 +++++++++++++-------- tests/lzstest.c | 5 +---- tun.c | 2 +- 6 files changed, 22 insertions(+), 18 deletions(-) diff --git a/library.c b/library.c index 1f78ea14..05340365 100644 --- a/library.c +++ b/library.c @@ -1356,7 +1356,7 @@ static const char *compr_name_map[] = { [COMPR_LZO] = "LZO", }; -const char *openconnect_get_cstp_compression(struct openconnect_info * vpninfo) +const char *openconnect_get_cstp_compression(struct openconnect_info *vpninfo) { if (vpninfo->cstp_compr <= 0 || vpninfo->cstp_compr > COMPR_MAX) return NULL; @@ -1364,7 +1364,7 @@ const char *openconnect_get_cstp_compression(struct openconnect_info * vpninfo) return compr_name_map[vpninfo->cstp_compr]; } -const char *openconnect_get_dtls_compression(struct openconnect_info * vpninfo) +const char *openconnect_get_dtls_compression(struct openconnect_info *vpninfo) { if (vpninfo->dtls_compr <= 0 || vpninfo->dtls_compr > COMPR_MAX) return NULL; diff --git a/openconnect-internal.h b/openconnect-internal.h index 644f51bf..5b11d76d 100644 --- a/openconnect-internal.h +++ b/openconnect-internal.h @@ -1333,7 +1333,7 @@ int lzs_decompress(unsigned char *dst, int dstlen, const unsigned char *src, int int lzs_compress(unsigned char *dst, int dstlen, const unsigned char *src, int srclen); /* ssl.c */ -unsigned string_is_hostname(const char* str); +unsigned string_is_hostname(const char *str); int connect_https_socket(struct openconnect_info *vpninfo); int __attribute__ ((format(printf, 4, 5))) request_passphrase(struct openconnect_info *vpninfo, const char *label, diff --git a/tests/bad_dtls_test.c b/tests/bad_dtls_test.c index 6fcc1eb4..db1f7c87 100644 --- a/tests/bad_dtls_test.c +++ b/tests/bad_dtls_test.c @@ -293,12 +293,14 @@ static EVP_MD_CTX *handshake_md5; static EVP_MD_CTX *handshake_sha1; #if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER) -static inline HMAC_CTX *HMAC_CTX_new(void) { +static inline HMAC_CTX *HMAC_CTX_new(void) +{ HMAC_CTX *ret = malloc(sizeof(*ret)); HMAC_CTX_init(ret); return ret; } -static inline void HMAC_CTX_free(HMAC_CTX *ctx) { +static inline void HMAC_CTX_free(HMAC_CTX *ctx) +{ HMAC_CTX_cleanup(ctx); free(ctx); } diff --git a/tests/buftest.c b/tests/buftest.c index c3e69243..01bf5f58 100644 --- a/tests/buftest.c +++ b/tests/buftest.c @@ -29,11 +29,11 @@ /* I always coded as if it worked like this. Now it does. */ #define realloc_inplace(p, size) do { \ - void *__realloc_old = p; \ - p = realloc(p, size); \ - if (size && !p) \ - free(__realloc_old); \ - } while (0) + void *__realloc_old = p; \ + p = realloc(p, size); \ + if (size && !p) \ + free(__realloc_old); \ + } while (0) struct oc_packed_uint32_t { uint32_t d; @@ -104,9 +104,14 @@ struct oc_text_buf { #define BUFTEST #include "../textbuf.c" -#define assert(x) if (!(x)) { \ - fprintf(stderr, "assert(%s) failed at line %d\n", #x, __LINE__); \ - exit(1); } +#define assert(x) do { \ + if (!(x)) { \ + fprintf(stderr, \ + "assert(%s) failed at line %d\n", \ + #x, __LINE__); \ + exit(1); \ + } \ + } while (0) static char testbytes[OC_BUF_MAX]; diff --git a/tests/lzstest.c b/tests/lzstest.c index 29f3f936..7edc4792 100644 --- a/tests/lzstest.c +++ b/tests/lzstest.c @@ -21,10 +21,7 @@ struct oc_packed_uint16_t { unsigned short d; } __attribute__((packed)); -int lzs_decompress(unsigned char *dst, int dstlen, const unsigned char *src, int srclen); -int lzs_compress(unsigned char *dst, int dstlen, const unsigned char *src, int srclen); - -#include "../lzs.c" +#include "../lzs.c" /* lzs_decompress() / lzs_compress() */ #include #include diff --git a/tun.c b/tun.c index 98f59991..2a4cab47 100644 --- a/tun.c +++ b/tun.c @@ -351,7 +351,7 @@ intptr_t os_setup_tun(struct openconnect_info *vpninfo) do { sc.sc_unit = unit_nr + 1; - if (!connect(tun_fd, (struct sockaddr * )&sc, sizeof(sc))) { + if (!connect(tun_fd, (struct sockaddr *)&sc, sizeof(sc))) { if (!vpninfo->ifname && asprintf(&vpninfo->ifname, "utun%d", unit_nr) == -1) { vpn_progress(vpninfo, PRG_ERR, -- 2.49.0