aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apply.c4
-rw-r--r--builtin/backfill.c4
-rw-r--r--builtin/column.c2
-rw-r--r--builtin/grep.c4
-rw-r--r--git-compat-util.h7
-rw-r--r--parse-options.h4
6 files changed, 16 insertions, 9 deletions
diff --git a/apply.c b/apply.c
index f274a37948..a850c7d75f 100644
--- a/apply.c
+++ b/apply.c
@@ -5123,8 +5123,8 @@ int apply_parse_options(int argc, const char **argv,
/* Think twice before adding "--nul" synonym to this */
OPT_SET_INT('z', NULL, &state->line_termination,
N_("paths are separated with NUL character"), '\0'),
- OPT_INTEGER('C', NULL, &state->p_context,
- N_("ensure at least <n> lines of context match")),
+ OPT_UNSIGNED('C', NULL, &state->p_context,
+ N_("ensure at least <n> lines of context match")),
OPT_CALLBACK(0, "whitespace", state, N_("action"),
N_("detect new or modified lines that have whitespace errors"),
apply_option_parse_whitespace),
diff --git a/builtin/backfill.c b/builtin/backfill.c
index 33e1ea2f84..d95d7a2d4d 100644
--- a/builtin/backfill.c
+++ b/builtin/backfill.c
@@ -123,8 +123,8 @@ int cmd_backfill(int argc, const char **argv, const char *prefix, struct reposit
.sparse = 0,
};
struct option options[] = {
- OPT_INTEGER(0, "min-batch-size", &ctx.min_batch_size,
- N_("Minimum number of objects to request at a time")),
+ OPT_UNSIGNED(0, "min-batch-size", &ctx.min_batch_size,
+ N_("Minimum number of objects to request at a time")),
OPT_BOOL(0, "sparse", &ctx.sparse,
N_("Restrict the missing objects to the current sparse-checkout")),
OPT_END(),
diff --git a/builtin/column.c b/builtin/column.c
index 50314cc255..ce6443d5fa 100644
--- a/builtin/column.c
+++ b/builtin/column.c
@@ -31,7 +31,7 @@ int cmd_column(int argc,
struct option options[] = {
OPT_STRING(0, "command", &real_command, N_("name"), N_("lookup config vars")),
OPT_COLUMN(0, "mode", &colopts, N_("layout to use")),
- OPT_INTEGER(0, "raw-mode", &colopts, N_("layout to use")),
+ OPT_UNSIGNED(0, "raw-mode", &colopts, N_("layout to use")),
OPT_INTEGER(0, "width", &copts.width, N_("maximum width")),
OPT_STRING(0, "indent", &copts.indent, N_("string"), N_("padding space on left border")),
OPT_STRING(0, "nl", &copts.nl, N_("string"), N_("padding space on right border")),
diff --git a/builtin/grep.c b/builtin/grep.c
index c4869733e1..f23a6f1dc8 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -983,9 +983,9 @@ int cmd_grep(int argc,
OPT_CALLBACK('C', "context", &opt, N_("n"),
N_("show <n> context lines before and after matches"),
context_callback),
- OPT_INTEGER('B', "before-context", &opt.pre_context,
+ OPT_UNSIGNED('B', "before-context", &opt.pre_context,
N_("show <n> context lines before matches")),
- OPT_INTEGER('A', "after-context", &opt.post_context,
+ OPT_UNSIGNED('A', "after-context", &opt.post_context,
N_("show <n> context lines after matches")),
OPT_INTEGER(0, "threads", &num_threads,
N_("use <n> worker threads")),
diff --git a/git-compat-util.h b/git-compat-util.h
index cf733b38ac..1218fcf81a 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -110,12 +110,19 @@ DISABLE_WARNING(-Wsign-compare)
# define BARF_UNLESS_COPYABLE(dst, src) \
BUILD_ASSERT_OR_ZERO(__builtin_types_compatible_p(__typeof__(*(dst)), \
__typeof__(*(src))))
+
+# define BARF_UNLESS_SIGNED(var) BUILD_ASSERT_OR_ZERO(((__typeof__(var)) -1) < 0)
+# define BARF_UNLESS_UNSIGNED(var) BUILD_ASSERT_OR_ZERO(((__typeof__(var)) -1) > 0)
#else
# define BARF_UNLESS_AN_ARRAY(arr) 0
# define BARF_UNLESS_COPYABLE(dst, src) \
BUILD_ASSERT_OR_ZERO(0 ? ((*(dst) = *(src)), 0) : \
sizeof(*(dst)) == sizeof(*(src)))
+
+# define BARF_UNLESS_SIGNED(var) 0
+# define BARF_UNLESS_UNSIGNED(var) 0
#endif
+
/*
* ARRAY_SIZE - get the number of elements in a visible array
* @x: the array whose size you want.
diff --git a/parse-options.h b/parse-options.h
index dc460a26ff..91c3e3c29b 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -218,7 +218,7 @@ struct option {
.type = OPTION_INTEGER, \
.short_name = (s), \
.long_name = (l), \
- .value = (v), \
+ .value = (v) + BARF_UNLESS_SIGNED(*(v)), \
.precision = sizeof(*v), \
.argh = N_("n"), \
.help = (h), \
@@ -280,7 +280,7 @@ struct option {
.type = OPTION_UNSIGNED, \
.short_name = (s), \
.long_name = (l), \
- .value = (v), \
+ .value = (v) + BARF_UNLESS_UNSIGNED(*(v)), \
.precision = sizeof(*v), \
.argh = N_("n"), \
.help = (h), \