git/builtin
Johannes Schindelin 321854ac46 clone.c: avoid "exceeds maximum object size" error with GCC v12.x
Technically, the pointer difference `end - start` _could_ be negative,
and when cast to an (unsigned) `size_t` that would cause problems. In
this instance, the symptom is:

dir.c: In function 'git_url_basename':
dir.c:3087:13: error: 'memchr' specified bound [9223372036854775808, 0]
       exceeds maximum object size 9223372036854775807
       [-Werror=stringop-overread]
    CC ewah/bitmap.o
 3087 |         if (memchr(start, '/', end - start) == NULL
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

While it is a bit far-fetched to think that `end` (which is defined as
`repo + strlen(repo)`) and `start` (which starts at `repo` and never
steps beyond the NUL terminator) could result in such a negative
difference, GCC has no way of knowing that.

See also https://gcc.gnu.org/bugzilla//show_bug.cgi?id=85783.

Let's just add a safety check, primarily for GCC's benefit.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-03-22 17:53:32 +01:00
..
2020-09-30 12:53:47 -07:00
2021-01-06 15:10:49 -08:00
2020-07-30 19:18:06 -07:00
2021-01-06 15:10:49 -08:00
2020-08-11 18:04:11 -07:00
2021-01-06 15:10:49 -08:00
2020-10-16 12:30:45 -07:00
2020-07-30 19:18:06 -07:00
2020-11-02 13:17:39 -08:00
2021-01-06 15:10:49 -08:00
2020-03-24 15:04:43 -07:00
2021-01-06 15:10:49 -08:00
2020-08-24 14:54:30 -07:00
2019-05-13 14:22:54 +09:00
2020-04-28 10:47:10 -07:00
2020-03-24 15:04:44 -07:00
2020-05-13 12:19:18 -07:00
2020-10-27 15:09:49 -07:00
2020-07-30 19:18:06 -07:00
2020-09-02 14:39:25 -07:00
2020-11-10 13:46:27 -08:00
2021-01-06 15:10:49 -08:00
2020-04-28 10:47:10 -07:00
2020-07-30 19:18:06 -07:00
2020-08-11 18:04:11 -07:00
2019-06-19 08:19:21 -07:00