@matheusbsbs / matheus-bagliano / commits / 6e1c23442a
Fork 0

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>

Ramsay Jones committed Jul 3, 2008 at 16:52 UTC 6e1c23442a0315ad440bb8457703dcf1ad943b96
9 files changed +32 -21
builtin-fast-export.c
+2 -2
@@ -116,7 +116,7 @@ static void handle_object(const unsigned char *sha1)
116
117 mark_next_object(object);
118
119 - printf("blob\nmark :%d\ndata %lu\n", last_idnum, size);
119 + printf("blob\nmark :%"PRIu32"\ndata %lu\n", last_idnum, size);
120 if (size && fwrite(buf, size, 1, stdout) != 1)
121 die ("Could not write blob %s", sha1_to_hex(sha1));
122 printf("\n");
@@ -204,7 +204,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev)
204 reencoded = reencode_string(message, "UTF-8", encoding);
205 if (!commit->parents)
206 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",
208 (const char *)commit->util, last_idnum,
209 (int)(author_end - author), author,
210 (int)(committer_end - committer), committer,
builtin-fetch-pack.c
+2 -1
@@ -520,7 +520,8 @@ static int get_pack(int xd[2], char **pack_lockfile)
520
521 if (read_pack_header(demux.out, &header))
522 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,
525 ntohl(header.hdr_version), ntohl(header.hdr_entries));
526 if (ntohl(header.hdr_entries) < unpack_limit)
527 do_keep = 0;
builtin-pack-objects.c
+10 -5
@@ -568,7 +568,8 @@ static void write_pack_file(void)
568 free(written_list);
569 stop_progress(&progress_state);
570 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);
573 /*
574 * We have scanned through [0 ... i). Since we have written
575 * the correct number of objects, the remaining [i ... nr_objects)
@@ -580,7 +581,8 @@ static void write_pack_file(void)
581 j += !e->idx.offset && !e->preferred_base;
582 }
583 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);
586 }
587
588 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
1696 static void prepare_pack(int window, int depth)
1697 {
1698 struct object_entry **delta_list;
1697 - uint32_t i, n, nr_deltas;
1699 + uint32_t i, nr_deltas;
1700 + unsigned n;
1701
1702 get_object_details();
1703
@@ -1785,7 +1788,8 @@ static int git_pack_config(const char *k, const char *v, void *cb)
1788 if (!strcmp(k, "pack.indexversion")) {
1789 pack_idx_default_version = git_config_int(k, v);
1790 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);
1793 return 0;
1794 }
1795 if (!strcmp(k, "pack.packsizelimit")) {
@@ -2219,7 +2223,8 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
2223 prepare_pack(window, depth);
2224 write_pack_file();
2225 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",
2228 written, written_delta, reused, reused_delta);
2229 return 0;
2230 }
builtin-unpack-objects.c
+2 -1
@@ -471,7 +471,8 @@ static void unpack_all(void)
471 if (ntohl(hdr->hdr_signature) != PACK_SIGNATURE)
472 die("bad pack file");
473 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));
476 use(sizeof(struct pack_header));
477
478 if (!quiet)
builtin-verify-pack.c
+2 -2
@@ -46,11 +46,11 @@ static void show_pack_info(struct packed_git *p)
46 for (i = 0; i <= MAX_CHAIN; i++) {
47 if (!chain_histogram[i])
48 continue;
49 - printf("chain length = %d: %d object%s\n", i,
49 + printf("chain length = %"PRIu32": %"PRIu32" object%s\n", i,
50 chain_histogram[i], chain_histogram[i] > 1 ? "s" : "");
51 }
52 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,
54 chain_histogram[0], chain_histogram[0] > 1 ? "s" : "");
55 }
56
index-pack.c
+4 -2
@@ -190,7 +190,8 @@ static void parse_pack_header(void)
190 if (hdr->hdr_signature != htonl(PACK_SIGNATURE))
191 die("pack signature mismatch");
192 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));
195
196 nr_objects = ntohl(hdr->hdr_entries);
197 use(sizeof(struct pack_header));
@@ -771,7 +772,8 @@ static int git_index_pack_config(const char *k, const char *v, void *cb)
772 if (!strcmp(k, "pack.indexversion")) {
773 pack_idx_default_version = git_config_int(k, v);
774 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);
777 return 0;
778 }
779 return git_default_config(k, v, cb);
receive-pack.c
+2 -1
@@ -370,7 +370,8 @@ static const char *unpack(void)
370 hdr_err = parse_pack_header(&hdr);
371 if (hdr_err)
372 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,
375 ntohl(hdr.hdr_version), ntohl(hdr.hdr_entries));
376
377 if (ntohl(hdr.hdr_entries) < unpack_limit) {
sha1_file.c
+6 -6
@@ -484,7 +484,7 @@ static int check_packed_git_idx(const char *path, struct packed_git *p)
484 version = ntohl(hdr->idx_version);
485 if (version < 2 || version > 2) {
486 munmap(idx_map, idx_size);
487 - return error("index file %s is version %d"
487 + return error("index file %s is version %"PRIu32
488 " and is not supported by this binary"
489 " (try upgrading GIT to a newer version)",
490 path, version);
@@ -695,14 +695,14 @@ static int open_packed_git_1(struct packed_git *p)
695 if (hdr.hdr_signature != htonl(PACK_SIGNATURE))
696 return error("file %s is not a GIT packfile", p->pack_name);
697 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)",
700 p->pack_name, ntohl(hdr.hdr_version));
701
702 /* Verify the pack matches its index. */
703 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",
706 p->pack_name, ntohl(hdr.hdr_entries),
707 p->num_objects);
708 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,
1769 }
1770
1771 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",
1773 sha1[0], sha1[1], sha1[2], lo, hi, p->num_objects);
1774
1775 if (use_lookup < 0)
show-index.c
+2 -1
@@ -68,7 +68,8 @@ int main(int argc, char **argv)
68 ntohl(off64[1]);
69 off64_nr++;
70 }
71 - printf("%" PRIuMAX " %s (%08x)\n", (uintmax_t) offset,
71 + printf("%" PRIuMAX " %s (%08"PRIx32")\n",
72 + (uintmax_t) offset,
73 sha1_to_hex(entries[i].sha1),
74 ntohl(entries[i].crc));
75 }