Skip to content

Commit f5f0f68

Browse files
committed
Merge branch 'tb/print-size-t-with-uintmax-format'
Code preparation to replace ulong vars with size_t vars where appropriate. * tb/print-size-t-with-uintmax-format: Upcast size_t variables to uintmax_t when printing
2 parents 502fe43 + ca473ce commit f5f0f68

File tree

11 files changed

+24
-23
lines changed

11 files changed

+24
-23
lines changed

archive-tar.c

Lines changed: 1 addition & 1 deletion
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);

builtin/cat-file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
9999
oi.sizep = &size;
100100
if (oid_object_info_extended(the_repository, &oid, &oi, flags) < 0)
101101
die("git cat-file: could not get object info");
102-
printf("%lu\n", size);
102+
printf("%"PRIuMAX"\n", (uintmax_t)size);
103103
return 0;
104104

105105
case 'e':
@@ -245,7 +245,7 @@ static void expand_atom(struct strbuf *sb, const char *atom, int len,
245245
if (data->mark_query)
246246
data->info.sizep = &data->size;
247247
else
248-
strbuf_addf(sb, "%lu", data->size);
248+
strbuf_addf(sb, "%"PRIuMAX , (uintmax_t)data->size);
249249
} else if (is_atom("objectsize:disk", atom, len)) {
250250
if (data->mark_query)
251251
data->info.disk_sizep = &data->disk_size;

builtin/fast-export.c

Lines changed: 1 addition & 1 deletion
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");

builtin/index-pack.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,8 @@ static void *unpack_entry_data(off_t offset, unsigned long size,
424424
int hdrlen;
425425

426426
if (!is_delta_type(type)) {
427-
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", type_name(type), size) + 1;
427+
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %"PRIuMAX,
428+
type_name(type),(uintmax_t)size) + 1;
428429
the_hash_algo->init_fn(&c);
429430
the_hash_algo->update_fn(&c, hdr, hdrlen);
430431
} else
@@ -1597,10 +1598,10 @@ static void show_pack_info(int stat_only)
15971598
chain_histogram[obj_stat[i].delta_depth - 1]++;
15981599
if (stat_only)
15991600
continue;
1600-
printf("%s %-6s %lu %lu %"PRIuMAX,
1601+
printf("%s %-6s %"PRIuMAX" %"PRIuMAX" %"PRIuMAX,
16011602
oid_to_hex(&obj->idx.oid),
1602-
type_name(obj->real_type), obj->size,
1603-
(unsigned long)(obj[1].idx.offset - obj->idx.offset),
1603+
type_name(obj->real_type), (uintmax_t)obj->size,
1604+
(uintmax_t)(obj[1].idx.offset - obj->idx.offset),
16041605
(uintmax_t)obj->idx.offset);
16051606
if (is_delta_type(obj->type)) {
16061607
struct object_entry *bobj = &objects[obj_stat[i].base_object_no];

builtin/ls-tree.c

Lines changed: 1 addition & 1 deletion
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,

builtin/pack-objects.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,9 +2083,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
20832083
die(_("object %s cannot be read"),
20842084
oid_to_hex(&trg_entry->idx.oid));
20852085
if (sz != trg_size)
2086-
die(_("object %s inconsistent object length (%lu vs %lu)"),
2087-
oid_to_hex(&trg_entry->idx.oid), sz,
2088-
trg_size);
2086+
die(_("object %s inconsistent object length (%"PRIuMAX" vs %"PRIuMAX")"),
2087+
oid_to_hex(&trg_entry->idx.oid), (uintmax_t)sz,
2088+
(uintmax_t)trg_size);
20892089
*mem_usage += sz;
20902090
}
20912091
if (!src->data) {
@@ -2110,9 +2110,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
21102110
oid_to_hex(&src_entry->idx.oid));
21112111
}
21122112
if (sz != src_size)
2113-
die(_("object %s inconsistent object length (%lu vs %lu)"),
2114-
oid_to_hex(&src_entry->idx.oid), sz,
2115-
src_size);
2113+
die(_("object %s inconsistent object length (%"PRIuMAX" vs %"PRIuMAX")"),
2114+
oid_to_hex(&src_entry->idx.oid), (uintmax_t)sz,
2115+
(uintmax_t)src_size);
21162116
*mem_usage += sz;
21172117
}
21182118
if (!src->index) {

diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3228,7 +3228,7 @@ static void emit_binary_diff_body(struct diff_options *o,
32283228
}
32293229

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

fast-import.c

Lines changed: 2 additions & 2 deletions
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);

http-push.c

Lines changed: 1 addition & 1 deletion
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);

ref-filter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ static void grab_common_values(struct atom_value *val, int deref, struct expand_
882882
v->s = xstrdup(type_name(oi->type));
883883
else if (!strcmp(name, "objectsize")) {
884884
v->value = oi->size;
885-
v->s = xstrfmt("%lu", oi->size);
885+
v->s = xstrfmt("%"PRIuMAX , (uintmax_t)oi->size);
886886
}
887887
else if (deref)
888888
grab_objectname(name, &oi->oid, v, &used_atom[i]);

0 commit comments

Comments
 (0)