Commit e7bb1fe8b2ac478850ce2241c3392131dc8f3237

Patrick Steinhardt 2019-06-27T15:14:08

examples: avoid passing signed integer to `memchr` The memchr(3P) function expects a `size_t` as its last parameter, but we do pass it an object size, which is of signed type `git_off_t`. As we can be sure that the result will be non-negative, let's just cast the parameter to a `size_t`.

1
2
3
4
5
6
7
8
9
10
11
12
13
diff --git a/examples/blame.c b/examples/blame.c
index 0625dd5..76f5ed2 100644
--- a/examples/blame.c
+++ b/examples/blame.c
@@ -91,7 +91,7 @@ int lg2_blame(git_repository *repo, int argc, char *argv[])
 	i = 0;
 	break_on_null_hunk = 0;
 	while (i < rawsize) {
-		const char *eol = memchr(rawdata + i, '\n', rawsize - i);
+		const char *eol = memchr(rawdata + i, '\n', (size_t)(rawsize - i));
 		char oid[10] = {0};
 		const git_blame_hunk *hunk = git_blame_get_hunk_byline(blame, line);