From 2e75c8ed85b8c54bf89d8ce4c42748a5cb6a403b Mon Sep 17 00:00:00 2001 From: Beat Bolli Date: Mon, 9 Jul 2018 21:25:32 +0200 Subject: [PATCH 1/8] connect.h: avoid forward declaration of an enum Include protocol.h to define enum protocol_version. Signed-off-by: Beat Bolli Signed-off-by: Junio C Hamano --- connect.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/connect.h b/connect.h index 0e69c6709c..c86f862f2f 100644 --- a/connect.h +++ b/connect.h @@ -1,6 +1,8 @@ #ifndef CONNECT_H #define CONNECT_H +#include "protocol.h" /* for enum protocol_version */ + #define CONNECT_VERBOSE (1u << 0) #define CONNECT_DIAG_URL (1u << 1) #define CONNECT_IPV4 (1u << 2) From ca5e39683a74716e287b5a227a0a574a67f5c48a Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 9 Jul 2018 14:35:39 -0700 Subject: [PATCH 2/8] fixup! connect.h: avoid forward declaration of an enum --- connect.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connect.h b/connect.h index c86f862f2f..32aff60979 100644 --- a/connect.h +++ b/connect.h @@ -1,7 +1,7 @@ #ifndef CONNECT_H #define CONNECT_H -#include "protocol.h" /* for enum protocol_version */ +#include "protocol.h" #define CONNECT_VERBOSE (1u << 0) #define CONNECT_DIAG_URL (1u << 1) From 91c2f2040ab83f11a87b271a842905d2e5c5ada4 Mon Sep 17 00:00:00 2001 From: Beat Bolli Date: Mon, 9 Jul 2018 21:25:33 +0200 Subject: [PATCH 3/8] refs/refs-internal.h: avoid forward declaration of an enum Include iterator.h to define enum iterator_selection. Signed-off-by: Beat Bolli Signed-off-by: Junio C Hamano --- refs/refs-internal.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/refs/refs-internal.h b/refs/refs-internal.h index dd834314bd..a78b5cb803 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -1,6 +1,8 @@ #ifndef REFS_REFS_INTERNAL_H #define REFS_REFS_INTERNAL_H +#include "iterator.h" /* for enum iterator_selection */ + /* * Data structures and functions for the internal use of the refs * module. Code outside of the refs module should use only the public From 13f925f3e4000ea1990e2cd7d7b1fb97597d41f5 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 9 Jul 2018 14:36:12 -0700 Subject: [PATCH 4/8] fixup! refs/refs-internal.h: avoid forward declaration of an enum --- refs/refs-internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/refs/refs-internal.h b/refs/refs-internal.h index a78b5cb803..54bde5089a 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -1,7 +1,7 @@ #ifndef REFS_REFS_INTERNAL_H #define REFS_REFS_INTERNAL_H -#include "iterator.h" /* for enum iterator_selection */ +#include "iterator.h" /* * Data structures and functions for the internal use of the refs From 8302f50e8ce687fbb09d8639ef87c0d35fd671b9 Mon Sep 17 00:00:00 2001 From: Beat Bolli Date: Mon, 9 Jul 2018 21:25:34 +0200 Subject: [PATCH 5/8] convert.c: replace "\e" escapes with "\033". The "\e" escape is not defined in ISO C. While on this line, add a missing space after the comma. Signed-off-by: Beat Bolli Signed-off-by: Junio C Hamano --- convert.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/convert.c b/convert.c index 64d0d30e08..edebb946f5 100644 --- a/convert.c +++ b/convert.c @@ -334,7 +334,7 @@ static void trace_encoding(const char *context, const char *path, strbuf_addf(&trace, "%s (%s, considered %s):\n", context, path, encoding); for (i = 0; i < len && buf; ++i) { strbuf_addf( - &trace,"| \e[2m%2i:\e[0m %2x \e[2m%c\e[0m%c", + &trace, "| \033[2m%2i:\033[0m %2x \033[2m%c\033[0m%c", i, (unsigned char) buf[i], (buf[i] > 32 && buf[i] < 127 ? buf[i] : ' '), From 9ad36356dd13b53667a51020c9aef0d4e014af01 Mon Sep 17 00:00:00 2001 From: Beat Bolli Date: Mon, 9 Jul 2018 21:25:35 +0200 Subject: [PATCH 6/8] sequencer.c: avoid empty statements at top level The macro GIT_PATH_FUNC expands to a function definition that ends with a closing brace. Remove two extra semicolons. While at it, fix the example in path.h. Signed-off-by: Beat Bolli Signed-off-by: Junio C Hamano --- path.h | 2 +- sequencer.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/path.h b/path.h index 1ccd0373c9..fc9d3487a0 100644 --- a/path.h +++ b/path.h @@ -147,7 +147,7 @@ extern void report_linked_checkout_garbage(void); /* * You can define a static memoized git path like: * - * static GIT_PATH_FUNC(git_path_foo, "FOO"); + * static GIT_PATH_FUNC(git_path_foo, "FOO") * * or use one of the global ones below. */ diff --git a/sequencer.c b/sequencer.c index 4034c0461b..0e9b1d99c9 100644 --- a/sequencer.c +++ b/sequencer.c @@ -61,12 +61,12 @@ static GIT_PATH_FUNC(rebase_path_done, "rebase-merge/done") * The file to keep track of how many commands were already processed (e.g. * for the prompt). */ -static GIT_PATH_FUNC(rebase_path_msgnum, "rebase-merge/msgnum"); +static GIT_PATH_FUNC(rebase_path_msgnum, "rebase-merge/msgnum") /* * The file to keep track of how many commands are to be processed in total * (e.g. for the prompt). */ -static GIT_PATH_FUNC(rebase_path_msgtotal, "rebase-merge/end"); +static GIT_PATH_FUNC(rebase_path_msgtotal, "rebase-merge/end") /* * The commit message that is planned to be used for any changes that * need to be committed following a user interaction. From b6d3f5a960c2b5dfe3d8d84e7f4c26e03d721d10 Mon Sep 17 00:00:00 2001 From: Beat Bolli Date: Mon, 9 Jul 2018 21:25:36 +0200 Subject: [PATCH 7/8] string-list.c: avoid conversion from void * to function pointer ISO C forbids the conversion of void pointers to function pointers. Introduce a context struct that encapsulates the function pointer. Signed-off-by: Beat Bolli Signed-off-by: Junio C Hamano --- string-list.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/string-list.c b/string-list.c index a0cf0cfe88..771c455098 100644 --- a/string-list.c +++ b/string-list.c @@ -224,18 +224,28 @@ struct string_list_item *string_list_append(struct string_list *list, list->strdup_strings ? xstrdup(string) : (char *)string); } +/* + * Encapsulate the compare function pointer because ISO C99 forbids + * casting from void * to a function pointer and vice versa. + */ +struct string_list_sort_ctx +{ + compare_strings_fn cmp; +}; + static int cmp_items(const void *a, const void *b, void *ctx) { - compare_strings_fn cmp = ctx; + struct string_list_sort_ctx *sort_ctx = ctx; const struct string_list_item *one = a; const struct string_list_item *two = b; - return cmp(one->string, two->string); + return sort_ctx->cmp(one->string, two->string); } void string_list_sort(struct string_list *list) { - QSORT_S(list->items, list->nr, cmp_items, - list->cmp ? list->cmp : strcmp); + struct string_list_sort_ctx sort_ctx = {list->cmp ? list->cmp : strcmp}; + + QSORT_S(list->items, list->nr, cmp_items, &sort_ctx); } struct string_list_item *unsorted_string_list_lookup(struct string_list *list, From 2b647a05d7223beacba076e45b3920a8621d28e7 Mon Sep 17 00:00:00 2001 From: Beat Bolli Date: Mon, 9 Jul 2018 21:25:37 +0200 Subject: [PATCH 8/8] utf8.c: avoid char overflow In ISO C, char constants must be in the range -128..127. Change the BOM constants to char literals to avoid overflow. Signed-off-by: Beat Bolli Signed-off-by: Junio C Hamano --- utf8.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/utf8.c b/utf8.c index d55e20c641..982217eec9 100644 --- a/utf8.c +++ b/utf8.c @@ -566,10 +566,10 @@ static int has_bom_prefix(const char *data, size_t len, return data && bom && (len >= bom_len) && !memcmp(data, bom, bom_len); } -static const char utf16_be_bom[] = {0xFE, 0xFF}; -static const char utf16_le_bom[] = {0xFF, 0xFE}; -static const char utf32_be_bom[] = {0x00, 0x00, 0xFE, 0xFF}; -static const char utf32_le_bom[] = {0xFF, 0xFE, 0x00, 0x00}; +static const char utf16_be_bom[] = {'\xFE', '\xFF'}; +static const char utf16_le_bom[] = {'\xFF', '\xFE'}; +static const char utf32_be_bom[] = {'\0', '\0', '\xFE', '\xFF'}; +static const char utf32_le_bom[] = {'\xFF', '\xFE', '\0', '\0'}; int has_prohibited_utf_bom(const char *enc, const char *data, size_t len) {