Skip to content

Commit efb38ad

Browse files
pks-tgitster
authored andcommitted
builtin/patch-id: fix type of get_one_patchid()
In `get_one_patchid()` we assign either the result of `strlen()` or `remove_space()` to `len`. But while the former correctly returns a `size_t`, the latter returns an `int` to indicate the length of the stripped string even though it cannot ever return a negative value. This causes a warning with "-Wsign-conversion". In fact, even `get_one_patchid()` itself is also using an integer as return value even though it always returns the length of the patch, and this bubbles up to other callers. Adapt the function and its helpers to use `size_t` for string lengths consistently. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6411a0a commit efb38ad

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

builtin/patch-id.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#define USE_THE_REPOSITORY_VARIABLE
2-
#define DISABLE_SIGN_COMPARE_WARNINGS
32

43
#include "builtin.h"
54
#include "config.h"
@@ -10,13 +9,13 @@
109
#include "parse-options.h"
1110
#include "setup.h"
1211

13-
static void flush_current_id(int patchlen, struct object_id *id, struct object_id *result)
12+
static void flush_current_id(size_t patchlen, struct object_id *id, struct object_id *result)
1413
{
1514
if (patchlen)
1615
printf("%s %s\n", oid_to_hex(result), oid_to_hex(id));
1716
}
1817

19-
static int remove_space(char *line)
18+
static size_t remove_space(char *line)
2019
{
2120
char *src = line;
2221
char *dst = line;
@@ -63,10 +62,11 @@ static int scan_hunk_header(const char *p, int *p_before, int *p_after)
6362
return 1;
6463
}
6564

66-
static int get_one_patchid(struct object_id *next_oid, struct object_id *result,
67-
struct strbuf *line_buf, int stable, int verbatim)
65+
static size_t get_one_patchid(struct object_id *next_oid, struct object_id *result,
66+
struct strbuf *line_buf, int stable, int verbatim)
6867
{
69-
int patchlen = 0, found_next = 0;
68+
size_t patchlen = 0;
69+
int found_next = 0;
7070
int before = -1, after = -1;
7171
int diff_is_binary = 0;
7272
char pre_oid_str[GIT_MAX_HEXSZ + 1], post_oid_str[GIT_MAX_HEXSZ + 1];
@@ -78,7 +78,7 @@ static int get_one_patchid(struct object_id *next_oid, struct object_id *result,
7878
while (strbuf_getwholeline(line_buf, stdin, '\n') != EOF) {
7979
char *line = line_buf->buf;
8080
const char *p = line;
81-
int len;
81+
size_t len;
8282

8383
/* Possibly skip over the prefix added by "log" or "format-patch" */
8484
if (!skip_prefix(line, "commit ", &p) &&
@@ -179,7 +179,7 @@ static int get_one_patchid(struct object_id *next_oid, struct object_id *result,
179179
static void generate_id_list(int stable, int verbatim)
180180
{
181181
struct object_id oid, n, result;
182-
int patchlen;
182+
size_t patchlen;
183183
struct strbuf line_buf = STRBUF_INIT;
184184

185185
oidclr(&oid, the_repository->hash_algo);

0 commit comments

Comments
 (0)