@matheusbsbs / matheus-bagliano / commits / 4049b9cfc0
Fork 0

fix const issues with some functions

Two functions, namely write_idx_file() and open_pack_file(), currently return a const pointer. However that pointer is either a copy of the first argument, or set to a malloc'd buffer when that first argument is null. In the later case it is wrong to qualify that pointer as const since ownership of the buffer is transferred to the caller to dispose of, and obviously the free() function is not meant to be passed const pointers. Making the return pointer not const causes a warning when the first argument is returned since that argument is also marked const. The correct thing to do is therefore to remove the const qualifiers, avoiding the need for ugly casts only to silence some warnings. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Nicolas Pitre committed Oct 16, 2007 at 21:55 UTC 4049b9cfc082affc6365539138f6f5c546bb5685
4 files changed +8 -7
builtin-pack-objects.c
+1 -1
@@ -652,7 +652,7 @@ static void write_pack_file(void)
652 umask(mode);
653 mode = 0444 & ~mode;
654
655 - idx_tmp_name = (char *) write_idx_file(NULL,
655 + idx_tmp_name = write_idx_file(NULL,
656 (struct pack_idx_entry **) written_list,
657 nr_written, sha1);
658 snprintf(tmpname, sizeof(tmpname), "%s-%s.pack",
index-pack.c
+4 -4
@@ -106,7 +106,7 @@ static void use(int bytes)
106 consumed_bytes += bytes;
107 }
108
109 -static const char *open_pack_file(const char *pack_name)
109 +static char *open_pack_file(char *pack_name)
110 {
111 if (from_stdin) {
112 input_fd = 0;
@@ -686,15 +686,15 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
686 int main(int argc, char **argv)
687 {
688 int i, fix_thin_pack = 0;
689 - const char *curr_pack, *pack_name = NULL;
690 - const char *curr_index, *index_name = NULL;
689 + char *curr_pack, *pack_name = NULL;
690 + char *curr_index, *index_name = NULL;
691 const char *keep_name = NULL, *keep_msg = NULL;
692 char *index_name_buf = NULL, *keep_name_buf = NULL;
693 struct pack_idx_entry **idx_objects;
694 unsigned char sha1[20];
695
696 for (i = 1; i < argc; i++) {
697 - const char *arg = argv[i];
697 + char *arg = argv[i];
698
699 if (*arg == '-') {
700 if (!strcmp(arg, "--stdin")) {
pack-write.c
+2 -1
@@ -17,7 +17,8 @@ static int sha1_compare(const void *_a, const void *_b)
17 * the SHA1 hash of sorted object names. The objects array passed in
18 * will be sorted by SHA1 on exit.
19 */
20 -const char *write_idx_file(const char *index_name, struct pack_idx_entry **objects, int nr_objects, unsigned char *sha1)
20 +char *write_idx_file(char *index_name, struct pack_idx_entry **objects,
21 + int nr_objects, unsigned char *sha1)
22 {
23 struct sha1file *f;
24 struct pack_idx_entry **sorted_by_sha, **list, **last;
pack.h
+1 -1
@@ -55,7 +55,7 @@ struct pack_idx_entry {
55 off_t offset;
56 };
57
58 -extern const char *write_idx_file(const char *index_name, struct pack_idx_entry **objects, int nr_objects, unsigned char *sha1);
58 +extern char *write_idx_file(char *index_name, struct pack_idx_entry **objects, int nr_objects, unsigned char *sha1);
59
60 extern int verify_pack(struct packed_git *, int);
61 extern void fixup_pack_header_footer(int, unsigned char *, const char *, uint32_t);