Skip to content

Commit 6e1c234

Browse files
Ramsay Jonesgitster
authored andcommitted
Fix some warnings (on cygwin) to allow -Werror
When printing valuds of type uint32_t, we should use PRIu32, and should not assume that it is unsigned int. On 32-bit platforms, it could be defined as unsigned long. The same caution applies to ntohl(). Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent db5d666 commit 6e1c234

File tree

9 files changed

+32
-21
lines changed

9 files changed

+32
-21
lines changed

builtin-fast-export.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static void handle_object(const unsigned char *sha1)
116116

117117
mark_next_object(object);
118118

119-
printf("blob\nmark :%d\ndata %lu\n", last_idnum, size);
119+
printf("blob\nmark :%"PRIu32"\ndata %lu\n", last_idnum, size);
120120
if (size && fwrite(buf, size, 1, stdout) != 1)
121121
die ("Could not write blob %s", sha1_to_hex(sha1));
122122
printf("\n");
@@ -204,7 +204,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev)
204204
reencoded = reencode_string(message, "UTF-8", encoding);
205205
if (!commit->parents)
206206
printf("reset %s\n", (const char*)commit->util);
207-
printf("commit %s\nmark :%d\n%.*s\n%.*s\ndata %u\n%s",
207+
printf("commit %s\nmark :%"PRIu32"\n%.*s\n%.*s\ndata %u\n%s",
208208
(const char *)commit->util, last_idnum,
209209
(int)(author_end - author), author,
210210
(int)(committer_end - committer), committer,

builtin-fetch-pack.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,8 @@ static int get_pack(int xd[2], char **pack_lockfile)
520520

521521
if (read_pack_header(demux.out, &header))
522522
die("protocol error: bad pack header");
523-
snprintf(hdr_arg, sizeof(hdr_arg), "--pack_header=%u,%u",
523+
snprintf(hdr_arg, sizeof(hdr_arg),
524+
"--pack_header=%"PRIu32",%"PRIu32,
524525
ntohl(header.hdr_version), ntohl(header.hdr_entries));
525526
if (ntohl(header.hdr_entries) < unpack_limit)
526527
do_keep = 0;

builtin-pack-objects.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,8 @@ static void write_pack_file(void)
568568
free(written_list);
569569
stop_progress(&progress_state);
570570
if (written != nr_result)
571-
die("wrote %u objects while expecting %u", written, nr_result);
571+
die("wrote %"PRIu32" objects while expecting %"PRIu32,
572+
written, nr_result);
572573
/*
573574
* We have scanned through [0 ... i). Since we have written
574575
* the correct number of objects, the remaining [i ... nr_objects)
@@ -580,7 +581,8 @@ static void write_pack_file(void)
580581
j += !e->idx.offset && !e->preferred_base;
581582
}
582583
if (j)
583-
die("wrote %u objects as expected but %u unwritten", written, j);
584+
die("wrote %"PRIu32" objects as expected but %"PRIu32
585+
" unwritten", written, j);
584586
}
585587

586588
static int locate_object_entry_hash(const unsigned char *sha1)
@@ -1694,7 +1696,8 @@ static int add_ref_tag(const char *path, const unsigned char *sha1, int flag, vo
16941696
static void prepare_pack(int window, int depth)
16951697
{
16961698
struct object_entry **delta_list;
1697-
uint32_t i, n, nr_deltas;
1699+
uint32_t i, nr_deltas;
1700+
unsigned n;
16981701

16991702
get_object_details();
17001703

@@ -1785,7 +1788,8 @@ static int git_pack_config(const char *k, const char *v, void *cb)
17851788
if (!strcmp(k, "pack.indexversion")) {
17861789
pack_idx_default_version = git_config_int(k, v);
17871790
if (pack_idx_default_version > 2)
1788-
die("bad pack.indexversion=%d", pack_idx_default_version);
1791+
die("bad pack.indexversion=%"PRIu32,
1792+
pack_idx_default_version);
17891793
return 0;
17901794
}
17911795
if (!strcmp(k, "pack.packsizelimit")) {
@@ -2219,7 +2223,8 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
22192223
prepare_pack(window, depth);
22202224
write_pack_file();
22212225
if (progress)
2222-
fprintf(stderr, "Total %u (delta %u), reused %u (delta %u)\n",
2226+
fprintf(stderr, "Total %"PRIu32" (delta %"PRIu32"),"
2227+
" reused %"PRIu32" (delta %"PRIu32")\n",
22232228
written, written_delta, reused, reused_delta);
22242229
return 0;
22252230
}

builtin-unpack-objects.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,8 @@ static void unpack_all(void)
471471
if (ntohl(hdr->hdr_signature) != PACK_SIGNATURE)
472472
die("bad pack file");
473473
if (!pack_version_ok(hdr->hdr_version))
474-
die("unknown pack file version %d", ntohl(hdr->hdr_version));
474+
die("unknown pack file version %"PRIu32,
475+
ntohl(hdr->hdr_version));
475476
use(sizeof(struct pack_header));
476477

477478
if (!quiet)

builtin-verify-pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ static void show_pack_info(struct packed_git *p)
4646
for (i = 0; i <= MAX_CHAIN; i++) {
4747
if (!chain_histogram[i])
4848
continue;
49-
printf("chain length = %d: %d object%s\n", i,
49+
printf("chain length = %"PRIu32": %"PRIu32" object%s\n", i,
5050
chain_histogram[i], chain_histogram[i] > 1 ? "s" : "");
5151
}
5252
if (chain_histogram[0])
53-
printf("chain length > %d: %d object%s\n", MAX_CHAIN,
53+
printf("chain length > %d: %"PRIu32" object%s\n", MAX_CHAIN,
5454
chain_histogram[0], chain_histogram[0] > 1 ? "s" : "");
5555
}
5656

index-pack.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ static void parse_pack_header(void)
190190
if (hdr->hdr_signature != htonl(PACK_SIGNATURE))
191191
die("pack signature mismatch");
192192
if (!pack_version_ok(hdr->hdr_version))
193-
die("pack version %d unsupported", ntohl(hdr->hdr_version));
193+
die("pack version %"PRIu32" unsupported",
194+
ntohl(hdr->hdr_version));
194195

195196
nr_objects = ntohl(hdr->hdr_entries);
196197
use(sizeof(struct pack_header));
@@ -771,7 +772,8 @@ static int git_index_pack_config(const char *k, const char *v, void *cb)
771772
if (!strcmp(k, "pack.indexversion")) {
772773
pack_idx_default_version = git_config_int(k, v);
773774
if (pack_idx_default_version > 2)
774-
die("bad pack.indexversion=%d", pack_idx_default_version);
775+
die("bad pack.indexversion=%"PRIu32,
776+
pack_idx_default_version);
775777
return 0;
776778
}
777779
return git_default_config(k, v, cb);

receive-pack.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,8 @@ static const char *unpack(void)
370370
hdr_err = parse_pack_header(&hdr);
371371
if (hdr_err)
372372
return hdr_err;
373-
snprintf(hdr_arg, sizeof(hdr_arg), "--pack_header=%u,%u",
373+
snprintf(hdr_arg, sizeof(hdr_arg),
374+
"--pack_header=%"PRIu32",%"PRIu32,
374375
ntohl(hdr.hdr_version), ntohl(hdr.hdr_entries));
375376

376377
if (ntohl(hdr.hdr_entries) < unpack_limit) {

sha1_file.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ static int check_packed_git_idx(const char *path, struct packed_git *p)
484484
version = ntohl(hdr->idx_version);
485485
if (version < 2 || version > 2) {
486486
munmap(idx_map, idx_size);
487-
return error("index file %s is version %d"
487+
return error("index file %s is version %"PRIu32
488488
" and is not supported by this binary"
489489
" (try upgrading GIT to a newer version)",
490490
path, version);
@@ -695,14 +695,14 @@ static int open_packed_git_1(struct packed_git *p)
695695
if (hdr.hdr_signature != htonl(PACK_SIGNATURE))
696696
return error("file %s is not a GIT packfile", p->pack_name);
697697
if (!pack_version_ok(hdr.hdr_version))
698-
return error("packfile %s is version %u and not supported"
699-
" (try upgrading GIT to a newer version)",
698+
return error("packfile %s is version %"PRIu32" and not"
699+
" supported (try upgrading GIT to a newer version)",
700700
p->pack_name, ntohl(hdr.hdr_version));
701701

702702
/* Verify the pack matches its index. */
703703
if (p->num_objects != ntohl(hdr.hdr_entries))
704-
return error("packfile %s claims to have %u objects"
705-
" while index indicates %u objects",
704+
return error("packfile %s claims to have %"PRIu32" objects"
705+
" while index indicates %"PRIu32" objects",
706706
p->pack_name, ntohl(hdr.hdr_entries),
707707
p->num_objects);
708708
if (lseek(p->pack_fd, p->pack_size - sizeof(sha1), SEEK_SET) == -1)
@@ -1769,7 +1769,7 @@ off_t find_pack_entry_one(const unsigned char *sha1,
17691769
}
17701770

17711771
if (debug_lookup)
1772-
printf("%02x%02x%02x... lo %u hi %u nr %u\n",
1772+
printf("%02x%02x%02x... lo %u hi %u nr %"PRIu32"\n",
17731773
sha1[0], sha1[1], sha1[2], lo, hi, p->num_objects);
17741774

17751775
if (use_lookup < 0)

show-index.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ int main(int argc, char **argv)
6868
ntohl(off64[1]);
6969
off64_nr++;
7070
}
71-
printf("%" PRIuMAX " %s (%08x)\n", (uintmax_t) offset,
71+
printf("%" PRIuMAX " %s (%08"PRIx32")\n",
72+
(uintmax_t) offset,
7273
sha1_to_hex(entries[i].sha1),
7374
ntohl(entries[i].crc));
7475
}

0 commit comments

Comments
 (0)