Skip to content

Commit 89a0c5c

Browse files
pks-tgitster
authored andcommitted
scalar: address -Wsign-compare warnings
There are two -Wsign-compare warnings in "scalar.c", both of which are trivial: - We mistakenly use a signed integer to loop towards an upper unsigned bound in `cmd_reconfigure()`. - We subtract `path_sep - enlistment->buf`, which results in a signed integer, and use the value in a ternary expression where second value is unsigned. But as `path_sep` is being assigned the result of `find_last_dir_sep(enlistment->buf + offset)` we know that it must always be bigger than or equal to `enlistment->buf`, and thus the result will be positive. Address both of these warnings. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent efb38ad commit 89a0c5c

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

scalar.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*/
44

55
#define USE_THE_REPOSITORY_VARIABLE
6-
#define DISABLE_SIGN_COMPARE_WARNINGS
76

87
#include "git-compat-util.h"
98
#include "abspath.h"
@@ -380,7 +379,7 @@ static int delete_enlistment(struct strbuf *enlistment)
380379
offset = offset_1st_component(enlistment->buf);
381380
path_sep = find_last_dir_sep(enlistment->buf + offset);
382381
strbuf_add(&parent, enlistment->buf,
383-
path_sep ? path_sep - enlistment->buf : offset);
382+
path_sep ? (size_t) (path_sep - enlistment->buf) : offset);
384383
if (chdir(parent.buf) < 0) {
385384
int res = error_errno(_("could not switch to '%s'"), parent.buf);
386385
strbuf_release(&parent);
@@ -655,7 +654,7 @@ static int cmd_reconfigure(int argc, const char **argv)
655654
NULL
656655
};
657656
struct string_list scalar_repos = STRING_LIST_INIT_DUP;
658-
int i, res = 0;
657+
int res = 0;
659658
struct strbuf commondir = STRBUF_INIT, gitdir = STRBUF_INIT;
660659

661660
argc = parse_options(argc, argv, NULL, options,
@@ -673,7 +672,7 @@ static int cmd_reconfigure(int argc, const char **argv)
673672

674673
git_config(get_scalar_repos, &scalar_repos);
675674

676-
for (i = 0; i < scalar_repos.nr; i++) {
675+
for (size_t i = 0; i < scalar_repos.nr; i++) {
677676
int succeeded = 0;
678677
struct repository *old_repo, r = { NULL };
679678
const char *dir = scalar_repos.items[i].string;

0 commit comments

Comments
 (0)