public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox•com>
To: Martin Koegler <martin.koegler@chello•at>
Cc: git@vger•kernel.org, Johannes.Schindelin@gmx•de
Subject: Re: [Patch size_t V3 15/19] Convert archive functions to size_t
Date: Sun, 20 Aug 2017 23:42:35 -0700	[thread overview]
Message-ID: <xmqqvalh5smc.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <1502914591-26215-16-git-send-email-martin@mail.zuhause> (Martin Koegler's message of "Wed, 16 Aug 2017 22:16:27 +0200")

Martin Koegler <martin.koegler@chello•at> writes:

> From: Martin Koegler <martin.koegler@chello•at>
>
> Signed-off-by: Martin Koegler <martin.koegler@chello•at>
> ---
>  archive-tar.c | 16 ++++++++--------
>  archive-zip.c | 22 +++++++++++-----------
>  2 files changed, 19 insertions(+), 19 deletions(-)

I feel that this needs a careful review from somebody who knows the
definition of archive formats well.

I am reasonably confident to say that the part of this patch that
updates the variable used to interact with zlib to size_t.  Use of
fixed-width uint32_t for CRC32 may also be correct, I would think.

But for all the other changes, it makes me nervous to see that
size_t is used to describe size of things in an archive, and makes
me suspect that some may want to be off_t, because an archive is a
concatenation of files, whose sizes are better measured in off_t
rather than size_t.



> diff --git a/archive-tar.c b/archive-tar.c
> index 719673d..ee56b2b 100644
> --- a/archive-tar.c
> +++ b/archive-tar.c
> @@ -12,7 +12,7 @@
>  #define BLOCKSIZE	(RECORDSIZE * 20)
>  
>  static char block[BLOCKSIZE];
> -static unsigned long offset;
> +static size_t offset;
>  
>  static int tar_umask = 002;
>  
> @@ -50,12 +50,12 @@ static void write_if_needed(void)
>   * queues up writes, so that all our write(2) calls write exactly one
>   * full block; pads writes to RECORDSIZE
>   */
> -static void do_write_blocked(const void *data, unsigned long size)
> +static void do_write_blocked(const void *data, size_t size)
>  {
>  	const char *buf = data;
>  
>  	if (offset) {
> -		unsigned long chunk = BLOCKSIZE - offset;
> +		size_t chunk = BLOCKSIZE - offset;
>  		if (size < chunk)
>  			chunk = size;
>  		memcpy(block + offset, buf, chunk);
> @@ -77,7 +77,7 @@ static void do_write_blocked(const void *data, unsigned long size)
>  
>  static void finish_record(void)
>  {
> -	unsigned long tail;
> +	size_t tail;
>  	tail = offset % RECORDSIZE;
>  	if (tail)  {
>  		memset(block + offset, 0, RECORDSIZE - tail);
> @@ -86,7 +86,7 @@ static void finish_record(void)
>  	write_if_needed();
>  }
>  
> -static void write_blocked(const void *data, unsigned long size)
> +static void write_blocked(const void *data, size_t size)
>  {
>  	do_write_blocked(data, size);
>  	finish_record();
> @@ -198,10 +198,10 @@ static size_t get_path_prefix(const char *path, size_t pathlen, size_t maxlen)
>  
>  static void prepare_header(struct archiver_args *args,
>  			   struct ustar_header *header,
> -			   unsigned int mode, unsigned long size)
> +			   unsigned int mode, size_t size)
>  {
>  	xsnprintf(header->mode, sizeof(header->mode), "%07o", mode & 07777);
> -	xsnprintf(header->size, sizeof(header->size), "%011lo", S_ISREG(mode) ? size : 0);
> +	xsnprintf(header->size, sizeof(header->size), "%011lo", S_ISREG(mode) ? (unsigned long)size : 0);
>  	xsnprintf(header->mtime, sizeof(header->mtime), "%011lo", (unsigned long) args->time);
>  
>  	xsnprintf(header->uid, sizeof(header->uid), "%07o", 0);
> @@ -219,7 +219,7 @@ static void prepare_header(struct archiver_args *args,
>  
>  static void write_extended_header(struct archiver_args *args,
>  				  const unsigned char *sha1,
> -				  const void *buffer, unsigned long size)
> +				  const void *buffer, size_t size)
>  {
>  	struct ustar_header header;
>  	unsigned int mode;
> diff --git a/archive-zip.c b/archive-zip.c
> index 4492d64..3a54d80 100644
> --- a/archive-zip.c
> +++ b/archive-zip.c
> @@ -186,12 +186,12 @@ static uint32_t clamp32(uintmax_t n)
>  	return (n < max) ? n : max;
>  }
>  
> -static void *zlib_deflate_raw(void *data, unsigned long size,
> +static void *zlib_deflate_raw(void *data, size_t size,
>  			      int compression_level,
> -			      unsigned long *compressed_size)
> +			      size_t *compressed_size)
>  {
>  	git_zstream stream;
> -	unsigned long maxsize;
> +	size_t maxsize;
>  	void *buffer;
>  	int result;
>  
> @@ -219,9 +219,9 @@ static void *zlib_deflate_raw(void *data, unsigned long size,
>  	return buffer;
>  }
>  
> -static void write_zip_data_desc(unsigned long size,
> -				unsigned long compressed_size,
> -				unsigned long crc)
> +static void write_zip_data_desc(size_t size,
> +				size_t compressed_size,
> +				uint32_t crc)
>  {
>  	if (size >= 0xffffffff || compressed_size >= 0xffffffff) {
>  		struct zip64_data_desc trailer;
> @@ -243,9 +243,9 @@ static void write_zip_data_desc(unsigned long size,
>  }
>  
>  static void set_zip_header_data_desc(struct zip_local_header *header,
> -				     unsigned long size,
> -				     unsigned long compressed_size,
> -				     unsigned long crc)
> +				     size_t size,
> +				     size_t compressed_size,
> +				     uint32_t crc)
>  {
>  	copy_le32(header->crc32, crc);
>  	copy_le32(header->compressed_size, compressed_size);
> @@ -287,8 +287,8 @@ static int write_zip_entry(struct archiver_args *args,
>  	size_t header_extra_size = ZIP_EXTRA_MTIME_SIZE;
>  	int need_zip64_extra = 0;
>  	unsigned long attr2;
> -	unsigned long compressed_size;
> -	unsigned long crc;
> +	size_t compressed_size;
> +	uint32_t crc;
>  	int method;
>  	unsigned char *out;
>  	void *deflated = NULL;

  reply	other threads:[~2017-08-21  6:42 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-16 20:16 [Patch size_t V3 00/19] use size_t Martin Koegler
2017-08-16 20:16 ` [Patch size_t V3 01/19] delta: fix enconding size larger than an "uint" can hold Martin Koegler
2017-08-17 20:28   ` Torsten Bögershausen
2017-08-16 20:16 ` [Patch size_t V3 02/19] Convert size datatype to size_t Martin Koegler
2017-08-16 20:16 ` [Patch size_t V3 03/19] Convert zlib.c " Martin Koegler
2017-08-16 20:16 ` [Patch size_t V3 04/19] delta: Fix offset overflows Martin Koegler
2017-08-16 20:16 ` [Patch size_t V3 05/19] Convert sha1_file.c to size_t Martin Koegler
2017-08-16 20:16 ` [Patch size_t V3 06/19] Use size_t for sha1 Martin Koegler
2017-08-16 20:16 ` [Patch size_t V3 07/19] Convert parse_X_buffer to size_t Martin Koegler
2017-08-16 20:16 ` [Patch size_t V3 08/19] Convert fsck.c & commit.c " Martin Koegler
2017-08-16 20:16 ` [Patch size_t V3 09/19] Convert cache functions " Martin Koegler
2017-08-16 20:16 ` [Patch size_t V3 10/19] Add overflow check to get_delta_hdr_size Martin Koegler
2017-08-16 20:16 ` [Patch size_t V3 11/19] Use size_t for config parsing Martin Koegler
2017-08-24 20:29   ` Johannes Sixt
2017-08-16 20:16 ` [Patch size_t V3 12/19] Convert pack-objects to size_t Martin Koegler
2017-08-16 20:16 ` [Patch size_t V3 13/19] Convert index-pack " Martin Koegler
2017-08-16 21:42   ` Ramsay Jones
2017-08-16 20:16 ` [Patch size_t V3 14/19] Convert unpack-objects " Martin Koegler
2017-08-16 20:16 ` [Patch size_t V3 15/19] Convert archive functions " Martin Koegler
2017-08-21  6:42   ` Junio C Hamano [this message]
2017-08-22  1:19     ` brian m. carlson
2017-08-16 20:16 ` [Patch size_t V3 16/19] Convert various things " Martin Koegler
2017-08-21  6:34   ` Junio C Hamano
2017-08-16 20:16 ` [Patch size_t V3 17/19] Convert ref-filter " Martin Koegler
2017-08-17 18:03   ` Junio C Hamano
2017-08-17 18:04     ` Junio C Hamano
2017-08-16 20:16 ` [Patch size_t V3 18/19] Convert tree-walk " Martin Koegler
2017-08-17 17:53   ` Junio C Hamano
2017-08-16 20:16 ` [Patch size_t V3 19/19] Convert xdiff-interface " Martin Koegler
2017-08-17 17:49   ` Junio C Hamano
2017-08-16 21:33 ` [Patch size_t V3 00/19] use size_t Junio C Hamano
2017-08-17 20:35 ` Torsten Bögershausen
2017-08-18  7:08   ` Martin Koegler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqvalh5smc.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox$(echo .)com \
    --cc=Johannes.Schindelin@gmx$(echo .)de \
    --cc=git@vger$(echo .)kernel.org \
    --cc=martin.koegler@chello$(echo .)at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox