Skip to content

Commit

Permalink
Remove all void-pointer arithmetic.
Browse files Browse the repository at this point in the history
ANSI C99 doesn't allow void-pointer arithmetic. This patch fixes this in
various ways. Usually the strategy that required the least changes was used.

Signed-off-by: Florian Forster <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
Florian Forster authored and Junio C Hamano committed Jun 20, 2006
1 parent 2bda77e commit 1d7f171
Show file tree
Hide file tree
Showing 19 changed files with 72 additions and 69 deletions.
6 changes: 3 additions & 3 deletions builtin-apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ static void *read_patch_file(int fd, unsigned long *sizep)
buffer = xrealloc(buffer, alloc);
nr = alloc - size;
}
nr = xread(fd, buffer + size, nr);
nr = xread(fd, (char *) buffer + size, nr);
if (!nr)
break;
if (nr < 0)
Expand All @@ -164,7 +164,7 @@ static void *read_patch_file(int fd, unsigned long *sizep)
*/
if (alloc < size + SLOP)
buffer = xrealloc(buffer, size + SLOP);
memset(buffer + size, 0, SLOP);
memset((char *) buffer + size, 0, SLOP);
return buffer;
}

Expand Down Expand Up @@ -1194,7 +1194,7 @@ static int read_old_data(struct stat *st, const char *path, void *buf, unsigned
return error("unable to open %s", path);
got = 0;
for (;;) {
int ret = xread(fd, buf + got, size - got);
int ret = xread(fd, (char *) buf + got, size - got);
if (ret <= 0)
break;
got += ret;
Expand Down
22 changes: 11 additions & 11 deletions convert-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ static int write_subdirectory(void *buffer, unsigned long size, const char *base
if (!slash) {
newlen += sprintf(new + newlen, "%o %s", mode, path);
new[newlen++] = '\0';
memcpy(new + newlen, buffer + len - 20, 20);
memcpy(new + newlen, (char *) buffer + len - 20, 20);
newlen += 20;

used += len;
size -= len;
buffer += len;
buffer = (char *) buffer + len;
continue;
}

Expand All @@ -121,7 +121,7 @@ static int write_subdirectory(void *buffer, unsigned long size, const char *base

used += len;
size -= len;
buffer += len;
buffer = (char *) buffer + len;
}

write_sha1_file(new, newlen, tree_type, result_sha1);
Expand All @@ -137,13 +137,13 @@ static void convert_tree(void *buffer, unsigned long size, unsigned char *result
while (size) {
int len = 1+strlen(buffer);

convert_binary_sha1(buffer + len);
convert_binary_sha1((char *) buffer + len);

len += 20;
if (len > size)
die("corrupt tree object");
size -= len;
buffer += len;
buffer = (char *) buffer + len;
}

write_subdirectory(orig_buffer, orig_size, "", 0, result_sha1);
Expand Down Expand Up @@ -244,14 +244,14 @@ static void convert_date(void *buffer, unsigned long size, unsigned char *result
// "tree <sha1>\n"
memcpy(new + newlen, buffer, 46);
newlen += 46;
buffer += 46;
buffer = (char *) buffer + 46;
size -= 46;

// "parent <sha1>\n"
while (!memcmp(buffer, "parent ", 7)) {
memcpy(new + newlen, buffer, 48);
newlen += 48;
buffer += 48;
buffer = (char *) buffer + 48;
size -= 48;
}

Expand All @@ -275,11 +275,11 @@ static void convert_commit(void *buffer, unsigned long size, unsigned char *resu

if (memcmp(buffer, "tree ", 5))
die("Bad commit '%s'", (char*) buffer);
convert_ascii_sha1(buffer+5);
buffer += 46; /* "tree " + "hex sha1" + "\n" */
convert_ascii_sha1((char *) buffer + 5);
buffer = (char *) buffer + 46; /* "tree " + "hex sha1" + "\n" */
while (!memcmp(buffer, "parent ", 7)) {
convert_ascii_sha1(buffer+7);
buffer += 48;
convert_ascii_sha1((char *) buffer + 7);
buffer = (char *) buffer + 48;
}
convert_date(orig_buffer, orig_size, result_sha1);
}
Expand Down
4 changes: 2 additions & 2 deletions csum-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static int sha1flush(struct sha1file *f, unsigned int count)
for (;;) {
int ret = xwrite(f->fd, buf, count);
if (ret > 0) {
buf += ret;
buf = (char *) buf + ret;
count -= ret;
if (count)
continue;
Expand Down Expand Up @@ -57,7 +57,7 @@ int sha1write(struct sha1file *f, void *buf, unsigned int count)
memcpy(f->buffer + offset, buf, nr);
count -= nr;
offset += nr;
buf += nr;
buf = (char *) buf + nr;
left -= nr;
if (!left) {
SHA1_Update(&f->ctx, f->buffer, offset);
Expand Down
2 changes: 1 addition & 1 deletion diff-delta.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ create_delta(const struct delta_index *index,
ref_data = index->src_buf;
ref_top = ref_data + index->src_size;
data = trg_buf;
top = trg_buf + trg_size;
top = (const unsigned char *) trg_buf + trg_size;

outpos++;
val = 0;
Expand Down
2 changes: 1 addition & 1 deletion diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ static void emit_binary_diff(mmfile_t *one, mmfile_t *two)
else
line[0] = bytes - 26 + 'a' - 1;
encode_85(line + 1, cp, bytes);
cp += bytes;
cp = (char *) cp + bytes;
puts(line);
}
printf("\n");
Expand Down
2 changes: 1 addition & 1 deletion diffcore-order.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static void prepare_order(const char *orderfile)
close(fd);
if (map == MAP_FAILED)
return;
endp = map + st.st_size;
endp = (char *) map + st.st_size;
for (pass = 0; pass < 2; pass++) {
cnt = 0;
cp = map;
Expand Down
2 changes: 1 addition & 1 deletion http-fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,
struct object_request *obj_req = (struct object_request *)data;
do {
ssize_t retval = write(obj_req->local,
ptr + posn, size - posn);
(char *) ptr + posn, size - posn);
if (retval < 0)
return posn;
posn += retval;
Expand Down
2 changes: 1 addition & 1 deletion http-push.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,
struct transfer_request *request = (struct transfer_request *)data;
do {
ssize_t retval = write(request->local_fileno,
ptr + posn, size - posn);
(char *) ptr + posn, size - posn);
if (retval < 0)
return posn;
posn += retval;
Expand Down
4 changes: 2 additions & 2 deletions http.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ size_t fread_buffer(void *ptr, size_t eltsize, size_t nmemb,
size_t size = eltsize * nmemb;
if (size > buffer->size - buffer->posn)
size = buffer->size - buffer->posn;
memcpy(ptr, buffer->buffer + buffer->posn, size);
memcpy(ptr, (char *) buffer->buffer + buffer->posn, size);
buffer->posn += size;
return size;
}
Expand All @@ -49,7 +49,7 @@ size_t fwrite_buffer(const void *ptr, size_t eltsize,
buffer->size = buffer->posn + size;
buffer->buffer = xrealloc(buffer->buffer, buffer->size);
}
memcpy(buffer->buffer + buffer->posn, ptr, size);
memcpy((char *) buffer->buffer + buffer->posn, ptr, size);
buffer->posn += size;
data_received++;
return size;
Expand Down
6 changes: 3 additions & 3 deletions pack-check.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ static int verify_packfile(struct packed_git *p)
pack_base = p->pack_base;
SHA1_Update(&ctx, pack_base, pack_size - 20);
SHA1_Final(sha1, &ctx);
if (memcmp(sha1, pack_base + pack_size - 20, 20))
if (memcmp(sha1, (char *) pack_base + pack_size - 20, 20))
return error("Packfile %s SHA1 mismatch with itself",
p->pack_name);
if (memcmp(sha1, index_base + index_size - 40, 20))
if (memcmp(sha1, (char *) index_base + index_size - 40, 20))
return error("Packfile %s SHA1 mismatch with idx",
p->pack_name);

Expand Down Expand Up @@ -135,7 +135,7 @@ int verify_pack(struct packed_git *p, int verbose)
SHA1_Init(&ctx);
SHA1_Update(&ctx, index_base, index_size - 20);
SHA1_Final(sha1, &ctx);
if (memcmp(sha1, index_base + index_size - 20, 20))
if (memcmp(sha1, (char *) index_base + index_size - 20, 20))
ret = error("Packfile index for %s SHA1 mismatch",
p->pack_name);

Expand Down
4 changes: 2 additions & 2 deletions pack-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ static void prepare_pack_revindex(struct pack_revindex *rix)

rix->revindex = xmalloc(sizeof(unsigned long) * (num_ent + 1));
for (i = 0; i < num_ent; i++) {
unsigned int hl = *((unsigned int *)(index + 24 * i));
unsigned int hl = *((unsigned int *)((char *) index + 24*i));
rix->revindex[i] = ntohl(hl);
}
/* This knows the pack format -- the 20-byte trailer
Expand Down Expand Up @@ -300,7 +300,7 @@ static unsigned long write_object(struct sha1file *f,
use_packed_git(p);

datalen = find_packed_object_size(p, entry->in_pack_offset);
buf = p->pack_base + entry->in_pack_offset;
buf = (char *) p->pack_base + entry->in_pack_offset;
sha1write(f, buf, datalen);
unuse_packed_git(p);
hdrlen = 0; /* not really */
Expand Down
18 changes: 9 additions & 9 deletions pack-redundant.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,12 @@ static struct pack_list * pack_list_difference(const struct pack_list *A,
static void cmp_two_packs(struct pack_list *p1, struct pack_list *p2)
{
int p1_off, p2_off;
void *p1_base, *p2_base;
unsigned char *p1_base, *p2_base;
struct llist_item *p1_hint = NULL, *p2_hint = NULL;

p1_off = p2_off = 256 * 4 + 4;
p1_base = (void *)p1->pack->index_base;
p2_base = (void *)p2->pack->index_base;
p1_base = (unsigned char *) p1->pack->index_base;
p2_base = (unsigned char *) p2->pack->index_base;

while (p1_off <= p1->pack->index_size - 3 * 20 &&
p2_off <= p2->pack->index_size - 3 * 20)
Expand Down Expand Up @@ -351,11 +351,11 @@ static size_t sizeof_union(struct packed_git *p1, struct packed_git *p2)
{
size_t ret = 0;
int p1_off, p2_off;
void *p1_base, *p2_base;
char *p1_base, *p2_base;

p1_off = p2_off = 256 * 4 + 4;
p1_base = (void *)p1->index_base;
p2_base = (void *)p2->index_base;
p1_base = (char *)p1->index_base;
p2_base = (char *)p2->index_base;

while (p1_off <= p1->index_size - 3 * 20 &&
p2_off <= p2->index_size - 3 * 20)
Expand Down Expand Up @@ -534,7 +534,7 @@ static struct pack_list * add_pack(struct packed_git *p)
{
struct pack_list l;
size_t off;
void *base;
unsigned char *base;

if (!p->pack_local && !(alt_odb || verbose))
return NULL;
Expand All @@ -543,7 +543,7 @@ static struct pack_list * add_pack(struct packed_git *p)
llist_init(&l.all_objects);

off = 256 * 4 + 4;
base = (void *)p->index_base;
base = (unsigned char *)p->index_base;
while (off <= p->index_size - 3 * 20) {
llist_insert_back(l.all_objects, base + off);
off += 24;
Expand Down
4 changes: 2 additions & 2 deletions patch-delta.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void *patch_delta(const void *src_buf, unsigned long src_size,
return NULL;

data = delta_buf;
top = delta_buf + delta_size;
top = (const unsigned char *) delta_buf + delta_size;

/* make sure the orig file size matches what we expect */
size = get_delta_hdr_size(&data, top);
Expand Down Expand Up @@ -56,7 +56,7 @@ void *patch_delta(const void *src_buf, unsigned long src_size,
cp_off + cp_size > src_size ||
cp_size > size)
goto bad;
memcpy(out, src_buf + cp_off, cp_size);
memcpy(out, (char *) src_buf + cp_off, cp_size);
out += cp_size;
size -= cp_size;
} else if (cmd) {
Expand Down
4 changes: 2 additions & 2 deletions pkt-line.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static void safe_write(int fd, const void *buf, unsigned n)
while (n) {
int ret = xwrite(fd, buf, n);
if (ret > 0) {
buf += ret;
buf = (char *) buf + ret;
n -= ret;
continue;
}
Expand Down Expand Up @@ -66,7 +66,7 @@ static void safe_read(int fd, void *buffer, unsigned size)
int n = 0;

while (n < size) {
int ret = xread(fd, buffer + n, size - n);
int ret = xread(fd, (char *) buffer + n, size - n);
if (ret < 0)
die("read error (%s)", strerror(errno));
if (!ret)
Expand Down
13 changes: 7 additions & 6 deletions read-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ static int verify_hdr(struct cache_header *hdr, unsigned long size)
SHA1_Init(&c);
SHA1_Update(&c, hdr, size - 20);
SHA1_Final(sha1, &c);
if (memcmp(sha1, (void *)hdr + size - 20, 20))
if (memcmp(sha1, (char *) hdr + size - 20, 20))
return error("bad index file sha1 signature");
return 0;
}
Expand Down Expand Up @@ -770,7 +770,7 @@ int read_cache(void)

offset = sizeof(*hdr);
for (i = 0; i < active_nr; i++) {
struct cache_entry *ce = map + offset;
struct cache_entry *ce = (struct cache_entry *) ((char *) map + offset);
offset = offset + ce_size(ce);
active_cache[i] = ce;
}
Expand All @@ -783,10 +783,11 @@ int read_cache(void)
* in 4-byte network byte order.
*/
unsigned long extsize;
memcpy(&extsize, map + offset + 4, 4);
memcpy(&extsize, (char *) map + offset + 4, 4);
extsize = ntohl(extsize);
if (read_index_extension(map + offset,
map + offset + 8, extsize) < 0)
if (read_index_extension(((const char *) map) + offset,
(char *) map + offset + 8,
extsize) < 0)
goto unmap;
offset += 8;
offset += extsize;
Expand Down Expand Up @@ -820,7 +821,7 @@ static int ce_write(SHA_CTX *context, int fd, void *data, unsigned int len)
}
write_buffer_len = buffered;
len -= partial;
data += partial;
data = (char *) data + partial;
}
return 0;
}
Expand Down
Loading

0 comments on commit 1d7f171

Please sign in to comment.