Re: [PATCH 4/5] index-pack: report correct bad object offsets even if they are large

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Nguyễn Thái Ngọc Duy  <pclouds@xxxxxxxxx> writes:

> Use the right type for offsets in this case, off_t, which makes a
> difference on 32-bit systems with large file support, and change
> formatting code accordingly.
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
> ---
>  builtin/index-pack.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/builtin/index-pack.c b/builtin/index-pack.c
> index cafaab7..73f7cd2 100644
> --- a/builtin/index-pack.c
> +++ b/builtin/index-pack.c
> @@ -338,10 +338,10 @@ static void parse_pack_header(void)
>  	use(sizeof(struct pack_header));
>  }
>  
> -static NORETURN void bad_object(unsigned long offset, const char *format,
> +static NORETURN void bad_object(off_t offset, const char *format,
>  		       ...) __attribute__((format (printf, 2, 3)));
>  
> -static NORETURN void bad_object(unsigned long offset, const char *format, ...)
> +static NORETURN void bad_object(off_t offset, const char *format, ...)
>  {
>  	va_list params;
>  	char buf[1024];
> @@ -349,7 +349,8 @@ static NORETURN void bad_object(unsigned long offset, const char *format, ...)
>  	va_start(params, format);
>  	vsnprintf(buf, sizeof(buf), format, params);
>  	va_end(params);
> -	die(_("pack has bad object at offset %lu: %s"), offset, buf);
> +	die(_("pack has bad object at offset %"PRIiMAX": %s"),
> +	    (intmax_t)offset, buf);
>  }

We seem to have a fallback definition only for PRIuMAX.

off_t is supposed to be a signed integer type [*1*], but we know
this is a positive offset when we issue this warning, so PRIuMAX
would probably be fine.


[Reference]

*1* http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_types.h.html
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]