git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 4/9] Convert archive functions to size_t

From
Martin Koegler <martin.koegler@chello.at>
Date
Aug 12, 2017, 08:47 UTC
Message-ID
<1502527643-21944-4-git-send-email-martin@mail.zuhause>
In-Reply-To
<1502527643-21944-1-git-send-email-martin@mail.zuhause>
From: Martin Koegler <martin.koegler@chello.at>
---
 archive-tar.c | 16 ++++++++--------
 archive-zip.c | 22 +++++++++++-----------
 2 files changed, 19 insertions(+), 19 deletions(-)
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;
-- 
2.1.4
Previous: Martin KoeglerNext: Martin Koegler
Message 2 of 27 in “Convert pack-objects to size_t”
  1. 1/9 Convert pack-objects to size_tMartin Koegler, Aug 12, 2017
  2. 4/9 Convert archive functions to size_tMartin Koegler, Aug 12, 2017
  3. 3/9 Convert unpack-objects to size_tMartin Koegler, Aug 12, 2017
  4. Martin ÅgrenAug 12, 2017
  5. Martin KoeglerAug 13, 2017
  6. 8/9 Convert tree-walk to size_tMartin Koegler, Aug 12, 2017
  7. 5/9 Convert various things to size_tMartin Koegler, Aug 12, 2017
  8. Martin ÅgrenAug 12, 2017
  9. Martin KoeglerAug 13, 2017
  10. 7/9 Convert ref-filter to size_tMartin Koegler, Aug 12, 2017
  11. 9/9 Convert xdiff-interface to size_tMartin Koegler, Aug 12, 2017
  12. 6/9 Use size_t for config parsingMartin Koegler, Aug 12, 2017
  13. 2/9 Convert index-pack to size_tMartin Koegler, Aug 12, 2017
  14. Ramsay JonesAug 12, 2017
  15. Torsten BögershausenAug 12, 2017
  16. Martin KoeglerAug 13, 2017
  17. Ramsay JonesAug 12, 2017
  18. Martin KoeglerAug 13, 2017
  19. Ramsay JonesAug 13, 2017
  20. Junio C HamanoAug 13, 2017
  21. Junio C HamanoAug 14, 2017
  22. Ramsay JonesAug 14, 2017
  23. Junio C HamanoAug 14, 2017
  24. Torsten BögershausenAug 14, 2017
  25. Ramsay JonesAug 15, 2017
  26. Martin KoeglerAug 16, 2017
  27. Torsten BögershausenAug 17, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.