{"thread":{"id":"49796","subject":"[PATCH v2 1/1] Upcast size_t variables to uintmax_t when printing","startedAt":"2018-11-11T07:10:16Z","lastAt":"2018-11-12T12:26:03Z","messageCount":4,"participants":["tboegi@web.de","Jeff King","Torsten Bögershausen"],"isPatch":true,"patchVersion":2,"patchTotal":1},"messages":[{"id":"362918","messageId":"20181111070504.12858-1-tboegi@web.de","threadId":"49796","inReplyTo":null,"subject":"[PATCH v2 1/1] Upcast size_t variables to uintmax_t when printing","fromName":"","fromEmail":"tboegi@web.de","sentAt":"2018-11-11T07:05:04Z","receivedAt":"2018-11-11T07:10:16Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"From: Torsten Bögershausen <tboegi@web.de>\n\nWhen printing variables which contain a size, today \"unsigned long\"\nis used at many places.\nIn order to be able to change the type from \"unsigned long\" into size_t\nsome day in the future, we need to have a way to print 64 bit variables\non a system that has \"unsigned long\" defined to be 32 bit, like Win64.\n\nUpcast all those variables into uintmax_t before they are printed.\nThis is to prepare for a bigger change, when \"unsigned long\"\nwill be converted into size_t for variables which may be > 4Gib.\n\nSigned-off-by: Torsten Bögershausen <tboegi@web.de>\n---\n\nChanges since V1:\n- fixed typos in the commit message, thanks to Eric  Sunshime for careful reading\n\nApplying it on pu  gives 1 conflict from the index/repo changes,\nShould be easy to fix.\n\narchive-tar.c          |  2 +-\n builtin/cat-file.c     |  4 ++--\n builtin/fast-export.c  |  2 +-\n builtin/index-pack.c   |  9 +++++----\n builtin/ls-tree.c      |  2 +-\n builtin/pack-objects.c | 12 ++++++------\n diff.c                 |  2 +-\n fast-import.c          |  4 ++--\n http-push.c            |  2 +-\n ref-filter.c           |  2 +-\n sha1-file.c            |  6 +++---\n 11 files changed, 24 insertions(+), 23 deletions(-)\n\ndiff --git a/archive-tar.c b/archive-tar.c\nindex 7a535cba24..a58e1a8ebf 100644\n--- a/archive-tar.c\n+++ b/archive-tar.c\n@@ -202,7 +202,7 @@ static void prepare_header(struct archiver_args *args,\n \t\t\t   unsigned int mode, unsigned long size)\n {\n \txsnprintf(header->mode, sizeof(header->mode), \"%07o\", mode & 07777);\n-\txsnprintf(header->size, sizeof(header->size), \"%011lo\", S_ISREG(mode) ? size : 0);\n+\txsnprintf(header->size, sizeof(header->size), \"%011\"PRIoMAX , S_ISREG(mode) ? (uintmax_t)size : (uintmax_t)0);\n \txsnprintf(header->mtime, sizeof(header->mtime), \"%011lo\", (unsigned long) args->time);\n \n \txsnprintf(header->uid, sizeof(header->uid), \"%07o\", 0);\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 8d97c84725..05decee33f 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -92,7 +92,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,\n \t\toi.sizep = &size;\n \t\tif (oid_object_info_extended(the_repository, &oid, &oi, flags) < 0)\n \t\t\tdie(\"git cat-file: could not get object info\");\n-\t\tprintf(\"%lu\\n\", size);\n+\t\tprintf(\"%\"PRIuMAX\"\\n\", (uintmax_t)size);\n \t\treturn 0;\n \n \tcase 'e':\n@@ -238,7 +238,7 @@ static void expand_atom(struct strbuf *sb, const char *atom, int len,\n \t\tif (data->mark_query)\n \t\t\tdata->info.sizep = &data->size;\n \t\telse\n-\t\t\tstrbuf_addf(sb, \"%lu\", data->size);\n+\t\t\tstrbuf_addf(sb, \"%\"PRIuMAX , (uintmax_t)data->size);\n \t} else if (is_atom(\"objectsize:disk\", atom, len)) {\n \t\tif (data->mark_query)\n \t\t\tdata->info.disk_sizep = &data->disk_size;\ndiff --git a/builtin/fast-export.c b/builtin/fast-export.c\nindex 456797c12a..5790f0d554 100644\n--- a/builtin/fast-export.c\n+++ b/builtin/fast-export.c\n@@ -253,7 +253,7 @@ static void export_blob(const struct object_id *oid)\n \n \tmark_next_object(object);\n \n-\tprintf(\"blob\\nmark :%\"PRIu32\"\\ndata %lu\\n\", last_idnum, size);\n+\tprintf(\"blob\\nmark :%\"PRIu32\"\\ndata %\"PRIuMAX\"\\n\", last_idnum, (uintmax_t)size);\n \tif (size && fwrite(buf, size, 1, stdout) != 1)\n \t\tdie_errno(\"could not write blob '%s'\", oid_to_hex(oid));\n \tprintf(\"\\n\");\ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex 2004e25da2..2a8ada432b 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -450,7 +450,8 @@ static void *unpack_entry_data(off_t offset, unsigned long size,\n \tint hdrlen;\n \n \tif (!is_delta_type(type)) {\n-\t\thdrlen = xsnprintf(hdr, sizeof(hdr), \"%s %lu\", type_name(type), size) + 1;\n+\t\thdrlen = xsnprintf(hdr, sizeof(hdr), \"%s %\"PRIuMAX,\n+\t\t\t\t   type_name(type),(uintmax_t)size) + 1;\n \t\tthe_hash_algo->init_fn(&c);\n \t\tthe_hash_algo->update_fn(&c, hdr, hdrlen);\n \t} else\n@@ -1628,10 +1629,10 @@ static void show_pack_info(int stat_only)\n \t\t\tchain_histogram[obj_stat[i].delta_depth - 1]++;\n \t\tif (stat_only)\n \t\t\tcontinue;\n-\t\tprintf(\"%s %-6s %lu %lu %\"PRIuMAX,\n+\t\tprintf(\"%s %-6s %\"PRIuMAX\" %\"PRIuMAX\" %\"PRIuMAX,\n \t\t       oid_to_hex(&obj->idx.oid),\n-\t\t       type_name(obj->real_type), obj->size,\n-\t\t       (unsigned long)(obj[1].idx.offset - obj->idx.offset),\n+\t\t       type_name(obj->real_type), (uintmax_t)obj->size,\n+\t\t       (uintmax_t)(obj[1].idx.offset - obj->idx.offset),\n \t\t       (uintmax_t)obj->idx.offset);\n \t\tif (is_delta_type(obj->type)) {\n \t\t\tstruct object_entry *bobj = &objects[obj_stat[i].base_object_no];\ndiff --git a/builtin/ls-tree.c b/builtin/ls-tree.c\nindex fe3b952cb3..7d581d6463 100644\n--- a/builtin/ls-tree.c\n+++ b/builtin/ls-tree.c\n@@ -100,7 +100,7 @@ static int show_tree(const struct object_id *oid, struct strbuf *base,\n \t\t\t\t\t\t  \"BAD\");\n \t\t\t\telse\n \t\t\t\t\txsnprintf(size_text, sizeof(size_text),\n-\t\t\t\t\t\t  \"%lu\", size);\n+\t\t\t\t\t\t  \"%\"PRIuMAX, (uintmax_t)size);\n \t\t\t} else\n \t\t\t\txsnprintf(size_text, sizeof(size_text), \"-\");\n \t\t\tprintf(\"%06o %s %s %7s\\t\", mode, type,\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex c99ee79c31..0d3921e009 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -2095,9 +2095,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,\n \t\t\tdie(_(\"object %s cannot be read\"),\n \t\t\t    oid_to_hex(&trg_entry->idx.oid));\n \t\tif (sz != trg_size)\n-\t\t\tdie(_(\"object %s inconsistent object length (%lu vs %lu)\"),\n-\t\t\t    oid_to_hex(&trg_entry->idx.oid), sz,\n-\t\t\t    trg_size);\n+\t\t\tdie(_(\"object %s inconsistent object length (%\"PRIuMAX\" vs %\"PRIuMAX\")\"),\n+\t\t\t    oid_to_hex(&trg_entry->idx.oid), (uintmax_t)sz,\n+\t\t\t    (uintmax_t)trg_size);\n \t\t*mem_usage += sz;\n \t}\n \tif (!src->data) {\n@@ -2122,9 +2122,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,\n \t\t\t    oid_to_hex(&src_entry->idx.oid));\n \t\t}\n \t\tif (sz != src_size)\n-\t\t\tdie(_(\"object %s inconsistent object length (%lu vs %lu)\"),\n-\t\t\t    oid_to_hex(&src_entry->idx.oid), sz,\n-\t\t\t    src_size);\n+\t\t\tdie(_(\"object %s inconsistent object length (%\"PRIuMAX\" vs %\"PRIuMAX\")\"),\n+\t\t\t    oid_to_hex(&src_entry->idx.oid), (uintmax_t)sz,\n+\t\t\t    (uintmax_t)src_size);\n \t\t*mem_usage += sz;\n \t}\n \tif (!src->index) {\ndiff --git a/diff.c b/diff.c\nindex 8647db3d30..88aaed7d49 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -3227,7 +3227,7 @@ static void emit_binary_diff_body(struct diff_options *o,\n \t}\n \n \tif (delta && delta_size < deflate_size) {\n-\t\tchar *s = xstrfmt(\"%lu\", orig_size);\n+\t\tchar *s = xstrfmt(\"%\"PRIuMAX , (uintmax_t)orig_size);\n \t\temit_diff_symbol(o, DIFF_SYMBOL_BINARY_DIFF_HEADER_DELTA,\n \t\t\t\t s, strlen(s), 0);\n \t\tfree(s);\ndiff --git a/fast-import.c b/fast-import.c\nindex 95600c78e0..69886687ce 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -2955,8 +2955,8 @@ static void cat_blob(struct object_entry *oe, struct object_id *oid)\n \t\tdie(\"Object %s is a %s but a blob was expected.\",\n \t\t    oid_to_hex(oid), type_name(type));\n \tstrbuf_reset(&line);\n-\tstrbuf_addf(&line, \"%s %s %lu\\n\", oid_to_hex(oid),\n-\t\t\t\t\t\ttype_name(type), size);\n+\tstrbuf_addf(&line, \"%s %s %\"PRIuMAX\"\\n\", oid_to_hex(oid),\n+\t\t    type_name(type), (uintmax_t)size);\n \tcat_blob_write(line.buf, line.len);\n \tstrbuf_release(&line);\n \tcat_blob_write(buf, size);\ndiff --git a/http-push.c b/http-push.c\nindex d1f52cbdf6..cd48590912 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -365,7 +365,7 @@ static void start_put(struct transfer_request *request)\n \tgit_zstream stream;\n \n \tunpacked = read_object_file(&request->obj->oid, &type, &len);\n-\thdrlen = xsnprintf(hdr, sizeof(hdr), \"%s %lu\", type_name(type), len) + 1;\n+\thdrlen = xsnprintf(hdr, sizeof(hdr), \"%s %\"PRIuMAX , type_name(type), (uintmax_t)len) + 1;\n \n \t/* Set it up */\n \tgit_deflate_init(&stream, zlib_compression_level);\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 0c45ed9d94..aaac48ad14 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -878,7 +878,7 @@ static void grab_common_values(struct atom_value *val, int deref, struct expand_\n \t\t\tv->s = xstrdup(type_name(oi->type));\n \t\telse if (!strcmp(name, \"objectsize\")) {\n \t\t\tv->value = oi->size;\n-\t\t\tv->s = xstrfmt(\"%lu\", oi->size);\n+\t\t\tv->s = xstrfmt(\"%\"PRIuMAX , (uintmax_t)oi->size);\n \t\t}\n \t\telse if (deref)\n \t\t\tgrab_objectname(name, &oi->oid, v, &used_atom[i]);\ndiff --git a/sha1-file.c b/sha1-file.c\nindex dd0b6aa873..4a67e0e759 100644\n--- a/sha1-file.c\n+++ b/sha1-file.c\n@@ -833,7 +833,7 @@ int check_object_signature(const struct object_id *oid, void *map,\n \t\treturn -1;\n \n \t/* Generate the header */\n-\thdrlen = xsnprintf(hdr, sizeof(hdr), \"%s %lu\", type_name(obj_type), size) + 1;\n+\thdrlen = xsnprintf(hdr, sizeof(hdr), \"%s %\"PRIuMAX , type_name(obj_type), (uintmax_t)size) + 1;\n \n \t/* Sha1.. */\n \tthe_hash_algo->init_fn(&c);\n@@ -1492,7 +1492,7 @@ static void write_object_file_prepare(const void *buf, unsigned long len,\n \tgit_hash_ctx c;\n \n \t/* Generate the header */\n-\t*hdrlen = xsnprintf(hdr, *hdrlen, \"%s %lu\", type, len)+1;\n+\t*hdrlen = xsnprintf(hdr, *hdrlen, \"%s %\"PRIuMAX , type, (uintmax_t)len)+1;\n \n \t/* Sha1.. */\n \tthe_hash_algo->init_fn(&c);\n@@ -1758,7 +1758,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime)\n \tbuf = read_object(oid->hash, &type, &len);\n \tif (!buf)\n \t\treturn error(_(\"cannot read sha1_file for %s\"), oid_to_hex(oid));\n-\thdrlen = xsnprintf(hdr, sizeof(hdr), \"%s %lu\", type_name(type), len) + 1;\n+\thdrlen = xsnprintf(hdr, sizeof(hdr), \"%s %\"PRIuMAX , type_name(type), (uintmax_t)len) + 1;\n \tret = write_loose_object(oid, hdr, hdrlen, buf, len, mtime);\n \tfree(buf);\n \n-- \n2.19.0.271.gfe8321ec05\n\n"},{"id":"362924","messageId":"20181111072835.GL30850@sigill.intra.peff.net","threadId":"49796","inReplyTo":"20181111070504.12858-1-tboegi@web.de","subject":"Re: [PATCH v2 1/1] Upcast size_t variables to uintmax_t when printing","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2018-11-11T07:28:35Z","receivedAt":"2018-11-11T07:28:38Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Nov 11, 2018 at 08:05:04AM +0100, tboegi@web.de wrote:\n\n> From: Torsten Bögershausen <tboegi@web.de>\n> \n> When printing variables which contain a size, today \"unsigned long\"\n> is used at many places.\n> In order to be able to change the type from \"unsigned long\" into size_t\n> some day in the future, we need to have a way to print 64 bit variables\n> on a system that has \"unsigned long\" defined to be 32 bit, like Win64.\n> \n> Upcast all those variables into uintmax_t before they are printed.\n> This is to prepare for a bigger change, when \"unsigned long\"\n> will be converted into size_t for variables which may be > 4Gib.\n\nI like the overall direction. I feel a little funny doing this step now,\nand not as part of a series to convert individual variables. But I\ncannot offhand think of any reason that it would behave badly even if\nthe other part does not materialize\n\n-Peff\n"},{"id":"362936","messageId":"20181111101650.GA4471@tor.lan","threadId":"49796","inReplyTo":"20181111072835.GL30850@sigill.intra.peff.net","subject":"Re: [PATCH v2 1/1] Upcast size_t variables to uintmax_t when printing","fromName":"Torsten Bögershausen","fromEmail":"tboegi@web.de","sentAt":"2018-11-11T10:16:50Z","receivedAt":"2018-11-11T10:17:00Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"On Sun, Nov 11, 2018 at 02:28:35AM -0500, Jeff King wrote:\n> On Sun, Nov 11, 2018 at 08:05:04AM +0100, tboegi@web.de wrote:\n> \n> > From: Torsten Bögershausen <tboegi@web.de>\n> > \n> > When printing variables which contain a size, today \"unsigned long\"\n> > is used at many places.\n> > In order to be able to change the type from \"unsigned long\" into size_t\n> > some day in the future, we need to have a way to print 64 bit variables\n> > on a system that has \"unsigned long\" defined to be 32 bit, like Win64.\n> > \n> > Upcast all those variables into uintmax_t before they are printed.\n> > This is to prepare for a bigger change, when \"unsigned long\"\n> > will be converted into size_t for variables which may be > 4Gib.\n> \n> I like the overall direction. I feel a little funny doing this step now,\n> and not as part of a series to convert individual variables. But I\n> cannot offhand think of any reason that it would behave badly even if\n> the other part does not materialize\n> \n\nHej all,\nThere may be some background information missing:\n- I did a 2-patch series based on this commit in pu:\n    commit 37c59c3e8fac8bae7ccc5baa148b0e9bae0c8d65\n    Author: Junio C Hamano <gitster@pobox.com>\n    Date:   Sat Oct 27 16:42:25 2018 +0900\n\n        treewide: apply cocci patch\n\n(that patch was never send out, see below)\n....\nThe week later, I tried to apply it on pu, but that was nearly hopeless,\nas too much things had changed on pu.\nI had the chance to compile & test it, but decided to take \"part2\" before\n\"part1\", so to say:\nFix all the printing, and wait for the master branch to settle,\nand then do the \"unsigned long\" -> size_t conversion.\nThat will probably happen after 2.20.\n\nAt the moment, the big \"unsigned long\" -> size_t conversion is dependend on\n - mk/use-size-t-in-zlib\n - sb/more-repo-in-api,\n - jk/xdiff-interface'\n (and probably more stuff from Duy and others)\n\nHow should we handle the big makeover ?\n\n> -Peff\n\nAnd thanks for reading my stuff\n"},{"id":"362999","messageId":"20181112122600.GD3956@sigill.intra.peff.net","threadId":"49796","inReplyTo":"20181111101650.GA4471@tor.lan","subject":"Re: [PATCH v2 1/1] Upcast size_t variables to uintmax_t when printing","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2018-11-12T12:26:00Z","receivedAt":"2018-11-12T12:26:03Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Nov 11, 2018 at 11:16:50AM +0100, Torsten Bögershausen wrote:\n\n> > I like the overall direction. I feel a little funny doing this step now,\n> > and not as part of a series to convert individual variables. But I\n> > cannot offhand think of any reason that it would behave badly even if\n> > the other part does not materialize\n> > \n> \n> Hej all,\n> There may be some background information missing:\n> - I did a 2-patch series based on this commit in pu:\n>     commit 37c59c3e8fac8bae7ccc5baa148b0e9bae0c8d65\n>     Author: Junio C Hamano <gitster@pobox.com>\n>     Date:   Sat Oct 27 16:42:25 2018 +0900\n> \n>         treewide: apply cocci patch\n> \n> (that patch was never send out, see below)\n> ....\n> The week later, I tried to apply it on pu, but that was nearly hopeless,\n> as too much things had changed on pu.\n> I had the chance to compile & test it, but decided to take \"part2\" before\n> \"part1\", so to say:\n> Fix all the printing, and wait for the master branch to settle,\n> and then do the \"unsigned long\" -> size_t conversion.\n> That will probably happen after 2.20.\n\nAh, OK. I am fine with that approach. My thinking was that we'd see\nindividual functions and their callers converted, which is another way\nto do it incrementally. But sometimes that ends up cascading and you end\nup having to change quite a bit of the callstack anyway.\n\n-Peff\n"}]}