index: fix cast warnings /home/kas/git/public/libgit2/src/index.c: In function ‘git_index_clear’: /home/kas/git/public/libgit2/src/index.c:228:8: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual] /home/kas/git/public/libgit2/src/index.c:235:8: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual] /home/kas/git/public/libgit2/src/index.c: In function ‘index_insert’: /home/kas/git/public/libgit2/src/index.c:392:7: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual] /home/kas/git/public/libgit2/src/index.c:399:7: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual] /home/kas/git/public/libgit2/src/index.c: In function ‘read_unmerged’: /home/kas/git/public/libgit2/src/index.c:681:35: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual] /home/kas/git/public/libgit2/src/index.c: In function ‘read_entry’: /home/kas/git/public/libgit2/src/index.c:716:33: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual] Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
diff --git a/include/git2/index.h b/include/git2/index.h
index d34ed0a..18ab9b8 100644
--- a/include/git2/index.h
+++ b/include/git2/index.h
@@ -98,14 +98,14 @@ typedef struct git_index_entry {
unsigned short flags;
unsigned short flags_extended;
- const char *path;
+ char *path;
} git_index_entry;
/** Representation of an unmerged file entry in the index. */
typedef struct git_index_entry_unmerged {
unsigned int mode[3];
git_oid oid[3];
- const char *path;
+ char *path;
} git_index_entry_unmerged;
/**
diff --git a/src/index.c b/src/index.c
index 6390da3..bdae26c 100644
--- a/src/index.c
+++ b/src/index.c
@@ -227,14 +227,14 @@ void git_index_clear(git_index *index)
for (i = 0; i < index->entries.length; ++i) {
git_index_entry *e;
e = git_vector_get(&index->entries, i);
- free((char *)e->path);
+ free(e->path);
free(e);
}
for (i = 0; i < index->unmerged.length; ++i) {
git_index_entry_unmerged *e;
e = git_vector_get(&index->unmerged, i);
- free((char *)e->path);
+ free(e->path);
free(e);
}
@@ -391,14 +391,14 @@ static int index_insert(git_index *index, const git_index_entry *source_entry, i
/* exists, replace it */
entry_array = (git_index_entry **) index->entries.contents;
- free((char *)entry_array[position]->path);
+ free(entry_array[position]->path);
free(entry_array[position]);
entry_array[position] = entry;
return GIT_SUCCESS;
cleanup_oom:
- free((char *)entry->path);
+ free(entry->path);
free(entry);
return GIT_ENOMEM;;
}
@@ -680,7 +680,7 @@ static int read_unmerged(git_index *index, const char *buffer, size_t size)
continue;
if (size < 20)
return git__throw(GIT_ERROR, "Failed to read unmerged entries");
- git_oid_fromraw(&lost->oid[i], (unsigned char *) buffer);
+ git_oid_fromraw(&lost->oid[i], (const unsigned char *) buffer);
size -= 20;
buffer += 20;
}
@@ -715,7 +715,7 @@ static size_t read_entry(git_index_entry *dest, const void *buffer, size_t buffe
dest->flags = ntohs(source->flags);
if (dest->flags & GIT_IDXENTRY_EXTENDED) {
- struct entry_long *source_l = (struct entry_long *)source;
+ const struct entry_long *source_l = (const struct entry_long *)source;
path_ptr = source_l->path;
flags_raw = ntohs(source_l->flags_extended);