Skip to content

Commit ca473ce

Browse files
tboegigitster
authored andcommitted
Upcast size_t variables to uintmax_t when printing
When printing variables which contain a size, today "unsigned long" is used at many places. In order to be able to change the type from "unsigned long" into size_t some day in the future, we need to have a way to print 64 bit variables on a system that has "unsigned long" defined to be 32 bit, like Win64. Upcast all those variables into uintmax_t before they are printed. This is to prepare for a bigger change, when "unsigned long" will be converted into size_t for variables which may be > 4Gib. Signed-off-by: Torsten Bögershausen <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8858448 commit ca473ce

11 files changed

+24
-23
lines changed

Diff for: archive-tar.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ static void prepare_header(struct archiver_args *args,
202202
unsigned int mode, unsigned long size)
203203
{
204204
xsnprintf(header->mode, sizeof(header->mode), "%07o", mode & 07777);
205-
xsnprintf(header->size, sizeof(header->size), "%011lo", S_ISREG(mode) ? size : 0);
205+
xsnprintf(header->size, sizeof(header->size), "%011"PRIoMAX , S_ISREG(mode) ? (uintmax_t)size : (uintmax_t)0);
206206
xsnprintf(header->mtime, sizeof(header->mtime), "%011lo", (unsigned long) args->time);
207207

208208
xsnprintf(header->uid, sizeof(header->uid), "%07o", 0);

Diff for: builtin/cat-file.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
9292
oi.sizep = &size;
9393
if (oid_object_info_extended(the_repository, &oid, &oi, flags) < 0)
9494
die("git cat-file: could not get object info");
95-
printf("%lu\n", size);
95+
printf("%"PRIuMAX"\n", (uintmax_t)size);
9696
return 0;
9797

9898
case 'e':
@@ -238,7 +238,7 @@ static void expand_atom(struct strbuf *sb, const char *atom, int len,
238238
if (data->mark_query)
239239
data->info.sizep = &data->size;
240240
else
241-
strbuf_addf(sb, "%lu", data->size);
241+
strbuf_addf(sb, "%"PRIuMAX , (uintmax_t)data->size);
242242
} else if (is_atom("objectsize:disk", atom, len)) {
243243
if (data->mark_query)
244244
data->info.disk_sizep = &data->disk_size;

Diff for: builtin/fast-export.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ static void export_blob(const struct object_id *oid)
253253

254254
mark_next_object(object);
255255

256-
printf("blob\nmark :%"PRIu32"\ndata %lu\n", last_idnum, size);
256+
printf("blob\nmark :%"PRIu32"\ndata %"PRIuMAX"\n", last_idnum, (uintmax_t)size);
257257
if (size && fwrite(buf, size, 1, stdout) != 1)
258258
die_errno("could not write blob '%s'", oid_to_hex(oid));
259259
printf("\n");

Diff for: builtin/index-pack.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,8 @@ static void *unpack_entry_data(off_t offset, unsigned long size,
450450
int hdrlen;
451451

452452
if (!is_delta_type(type)) {
453-
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", type_name(type), size) + 1;
453+
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %"PRIuMAX,
454+
type_name(type),(uintmax_t)size) + 1;
454455
the_hash_algo->init_fn(&c);
455456
the_hash_algo->update_fn(&c, hdr, hdrlen);
456457
} else
@@ -1628,10 +1629,10 @@ static void show_pack_info(int stat_only)
16281629
chain_histogram[obj_stat[i].delta_depth - 1]++;
16291630
if (stat_only)
16301631
continue;
1631-
printf("%s %-6s %lu %lu %"PRIuMAX,
1632+
printf("%s %-6s %"PRIuMAX" %"PRIuMAX" %"PRIuMAX,
16321633
oid_to_hex(&obj->idx.oid),
1633-
type_name(obj->real_type), obj->size,
1634-
(unsigned long)(obj[1].idx.offset - obj->idx.offset),
1634+
type_name(obj->real_type), (uintmax_t)obj->size,
1635+
(uintmax_t)(obj[1].idx.offset - obj->idx.offset),
16351636
(uintmax_t)obj->idx.offset);
16361637
if (is_delta_type(obj->type)) {
16371638
struct object_entry *bobj = &objects[obj_stat[i].base_object_no];

Diff for: builtin/ls-tree.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static int show_tree(const struct object_id *oid, struct strbuf *base,
100100
"BAD");
101101
else
102102
xsnprintf(size_text, sizeof(size_text),
103-
"%lu", size);
103+
"%"PRIuMAX, (uintmax_t)size);
104104
} else
105105
xsnprintf(size_text, sizeof(size_text), "-");
106106
printf("%06o %s %s %7s\t", mode, type,

Diff for: builtin/pack-objects.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -2095,9 +2095,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
20952095
die(_("object %s cannot be read"),
20962096
oid_to_hex(&trg_entry->idx.oid));
20972097
if (sz != trg_size)
2098-
die(_("object %s inconsistent object length (%lu vs %lu)"),
2099-
oid_to_hex(&trg_entry->idx.oid), sz,
2100-
trg_size);
2098+
die(_("object %s inconsistent object length (%"PRIuMAX" vs %"PRIuMAX")"),
2099+
oid_to_hex(&trg_entry->idx.oid), (uintmax_t)sz,
2100+
(uintmax_t)trg_size);
21012101
*mem_usage += sz;
21022102
}
21032103
if (!src->data) {
@@ -2122,9 +2122,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
21222122
oid_to_hex(&src_entry->idx.oid));
21232123
}
21242124
if (sz != src_size)
2125-
die(_("object %s inconsistent object length (%lu vs %lu)"),
2126-
oid_to_hex(&src_entry->idx.oid), sz,
2127-
src_size);
2125+
die(_("object %s inconsistent object length (%"PRIuMAX" vs %"PRIuMAX")"),
2126+
oid_to_hex(&src_entry->idx.oid), (uintmax_t)sz,
2127+
(uintmax_t)src_size);
21282128
*mem_usage += sz;
21292129
}
21302130
if (!src->index) {

Diff for: diff.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3227,7 +3227,7 @@ static void emit_binary_diff_body(struct diff_options *o,
32273227
}
32283228

32293229
if (delta && delta_size < deflate_size) {
3230-
char *s = xstrfmt("%lu", orig_size);
3230+
char *s = xstrfmt("%"PRIuMAX , (uintmax_t)orig_size);
32313231
emit_diff_symbol(o, DIFF_SYMBOL_BINARY_DIFF_HEADER_DELTA,
32323232
s, strlen(s), 0);
32333233
free(s);

Diff for: fast-import.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2955,8 +2955,8 @@ static void cat_blob(struct object_entry *oe, struct object_id *oid)
29552955
die("Object %s is a %s but a blob was expected.",
29562956
oid_to_hex(oid), type_name(type));
29572957
strbuf_reset(&line);
2958-
strbuf_addf(&line, "%s %s %lu\n", oid_to_hex(oid),
2959-
type_name(type), size);
2958+
strbuf_addf(&line, "%s %s %"PRIuMAX"\n", oid_to_hex(oid),
2959+
type_name(type), (uintmax_t)size);
29602960
cat_blob_write(line.buf, line.len);
29612961
strbuf_release(&line);
29622962
cat_blob_write(buf, size);

Diff for: http-push.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ static void start_put(struct transfer_request *request)
365365
git_zstream stream;
366366

367367
unpacked = read_object_file(&request->obj->oid, &type, &len);
368-
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", type_name(type), len) + 1;
368+
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %"PRIuMAX , type_name(type), (uintmax_t)len) + 1;
369369

370370
/* Set it up */
371371
git_deflate_init(&stream, zlib_compression_level);

Diff for: ref-filter.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ static void grab_common_values(struct atom_value *val, int deref, struct expand_
878878
v->s = xstrdup(type_name(oi->type));
879879
else if (!strcmp(name, "objectsize")) {
880880
v->value = oi->size;
881-
v->s = xstrfmt("%lu", oi->size);
881+
v->s = xstrfmt("%"PRIuMAX , (uintmax_t)oi->size);
882882
}
883883
else if (deref)
884884
grab_objectname(name, &oi->oid, v, &used_atom[i]);

Diff for: sha1-file.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ int check_object_signature(const struct object_id *oid, void *map,
833833
return -1;
834834

835835
/* Generate the header */
836-
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", type_name(obj_type), size) + 1;
836+
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %"PRIuMAX , type_name(obj_type), (uintmax_t)size) + 1;
837837

838838
/* Sha1.. */
839839
the_hash_algo->init_fn(&c);
@@ -1492,7 +1492,7 @@ static void write_object_file_prepare(const void *buf, unsigned long len,
14921492
git_hash_ctx c;
14931493

14941494
/* Generate the header */
1495-
*hdrlen = xsnprintf(hdr, *hdrlen, "%s %lu", type, len)+1;
1495+
*hdrlen = xsnprintf(hdr, *hdrlen, "%s %"PRIuMAX , type, (uintmax_t)len)+1;
14961496

14971497
/* Sha1.. */
14981498
the_hash_algo->init_fn(&c);
@@ -1758,7 +1758,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
17581758
buf = read_object(oid->hash, &type, &len);
17591759
if (!buf)
17601760
return error(_("cannot read sha1_file for %s"), oid_to_hex(oid));
1761-
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", type_name(type), len) + 1;
1761+
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %"PRIuMAX , type_name(type), (uintmax_t)len) + 1;
17621762
ret = write_loose_object(oid, hdr, hdrlen, buf, len, mtime);
17631763
free(buf);
17641764

0 commit comments

Comments
 (0)