Remove all void-pointer arithmetic.
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 <octo@verplant.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Florian Forster committed
Jun 18, 2006 at 17:18 UTC
1d7f171c3a456b980d821ee0f68e01535a5f7e36
19 files changed
+72
-69
builtin-apply.c
+3
-3
@@ -148,7 +148,7 @@ static void *read_patch_file(int fd, unsigned long *sizep)
148
buffer = xrealloc(buffer, alloc);
149
nr = alloc - size;
150
}
151
- nr = xread(fd, buffer + size, nr);
151
+ nr = xread(fd, (char *) buffer + size, nr);
152
if (!nr)
153
break;
154
if (nr < 0)
@@ -164,7 +164,7 @@ static void *read_patch_file(int fd, unsigned long *sizep)
164
*/
165
if (alloc < size + SLOP)
166
buffer = xrealloc(buffer, size + SLOP);
167
- memset(buffer + size, 0, SLOP);
167
+ memset((char *) buffer + size, 0, SLOP);
168
return buffer;
169
}
170
@@ -1194,7 +1194,7 @@ static int read_old_data(struct stat *st, const char *path, void *buf, unsigned
1194
return error("unable to open %s", path);
1195
got = 0;
1196
for (;;) {
1197
- int ret = xread(fd, buf + got, size - got);
1197
+ int ret = xread(fd, (char *) buf + got, size - got);
1198
if (ret <= 0)
1199
break;
1200
got += ret;
convert-objects.c
+11
-11
@@ -103,12 +103,12 @@ static int write_subdirectory(void *buffer, unsigned long size, const char *base
103
if (!slash) {
104
newlen += sprintf(new + newlen, "%o %s", mode, path);
105
new[newlen++] = '\0';
106
- memcpy(new + newlen, buffer + len - 20, 20);
106
+ memcpy(new + newlen, (char *) buffer + len - 20, 20);
107
newlen += 20;
108
109
used += len;
110
size -= len;
111
- buffer += len;
111
+ buffer = (char *) buffer + len;
112
continue;
113
}
114
@@ -121,7 +121,7 @@ static int write_subdirectory(void *buffer, unsigned long size, const char *base
121
122
used += len;
123
size -= len;
124
- buffer += len;
124
+ buffer = (char *) buffer + len;
125
}
126
127
write_sha1_file(new, newlen, tree_type, result_sha1);
@@ -137,13 +137,13 @@ static void convert_tree(void *buffer, unsigned long size, unsigned char *result
137
while (size) {
138
int len = 1+strlen(buffer);
139
140
- convert_binary_sha1(buffer + len);
140
+ convert_binary_sha1((char *) buffer + len);
141
142
len += 20;
143
if (len > size)
144
die("corrupt tree object");
145
size -= len;
146
- buffer += len;
146
+ buffer = (char *) buffer + len;
147
}
148
149
write_subdirectory(orig_buffer, orig_size, "", 0, result_sha1);
@@ -244,14 +244,14 @@ static void convert_date(void *buffer, unsigned long size, unsigned char *result
244
// "tree <sha1>\n"
245
memcpy(new + newlen, buffer, 46);
246
newlen += 46;
247
- buffer += 46;
247
+ buffer = (char *) buffer + 46;
248
size -= 46;
249
250
// "parent <sha1>\n"
251
while (!memcmp(buffer, "parent ", 7)) {
252
memcpy(new + newlen, buffer, 48);
253
newlen += 48;
254
- buffer += 48;
254
+ buffer = (char *) buffer + 48;
255
size -= 48;
256
}
257
@@ -275,11 +275,11 @@ static void convert_commit(void *buffer, unsigned long size, unsigned char *resu
275
276
if (memcmp(buffer, "tree ", 5))
277
die("Bad commit '%s'", (char*) buffer);
278
- convert_ascii_sha1(buffer+5);
279
- buffer += 46; /* "tree " + "hex sha1" + "\n" */
278
+ convert_ascii_sha1((char *) buffer + 5);
279
+ buffer = (char *) buffer + 46; /* "tree " + "hex sha1" + "\n" */
280
while (!memcmp(buffer, "parent ", 7)) {
281
- convert_ascii_sha1(buffer+7);
282
- buffer += 48;
281
+ convert_ascii_sha1((char *) buffer + 7);
282
+ buffer = (char *) buffer + 48;
283
}
284
convert_date(orig_buffer, orig_size, result_sha1);
285
}
csum-file.c
+2
-2
@@ -17,7 +17,7 @@ static int sha1flush(struct sha1file *f, unsigned int count)
17
for (;;) {
18
int ret = xwrite(f->fd, buf, count);
19
if (ret > 0) {
20
- buf += ret;
20
+ buf = (char *) buf + ret;
21
count -= ret;
22
if (count)
23
continue;
@@ -57,7 +57,7 @@ int sha1write(struct sha1file *f, void *buf, unsigned int count)
57
memcpy(f->buffer + offset, buf, nr);
58
count -= nr;
59
offset += nr;
60
- buf += nr;
60
+ buf = (char *) buf + nr;
61
left -= nr;
62
if (!left) {
63
SHA1_Update(&f->ctx, f->buffer, offset);
diff-delta.c
+1
-1
@@ -284,7 +284,7 @@ create_delta(const struct delta_index *index,
284
ref_data = index->src_buf;
285
ref_top = ref_data + index->src_size;
286
data = trg_buf;
287
- top = trg_buf + trg_size;
287
+ top = (const unsigned char *) trg_buf + trg_size;
288
289
outpos++;
290
val = 0;
diff.c
+1
-1
@@ -515,7 +515,7 @@ static void emit_binary_diff(mmfile_t *one, mmfile_t *two)
515
else
516
line[0] = bytes - 26 + 'a' - 1;
517
encode_85(line + 1, cp, bytes);
518
- cp += bytes;
518
+ cp = (char *) cp + bytes;
519
puts(line);
520
}
521
printf("\n");
diffcore-order.c
+1
-1
@@ -30,7 +30,7 @@ static void prepare_order(const char *orderfile)
30
close(fd);
31
if (map == MAP_FAILED)
32
return;
33
- endp = map + st.st_size;
33
+ endp = (char *) map + st.st_size;
34
for (pass = 0; pass < 2; pass++) {
35
cnt = 0;
36
cp = map;
http-fetch.c
+1
-1
@@ -123,7 +123,7 @@ static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,
123
struct object_request *obj_req = (struct object_request *)data;
124
do {
125
ssize_t retval = write(obj_req->local,
126
- ptr + posn, size - posn);
126
+ (char *) ptr + posn, size - posn);
127
if (retval < 0)
128
return posn;
129
posn += retval;
http-push.c
+1
-1
@@ -196,7 +196,7 @@ static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,
196
struct transfer_request *request = (struct transfer_request *)data;
197
do {
198
ssize_t retval = write(request->local_fileno,
199
- ptr + posn, size - posn);
199
+ (char *) ptr + posn, size - posn);
200
if (retval < 0)
201
return posn;
202
posn += retval;
http.c
+2
-2
@@ -34,7 +34,7 @@ size_t fread_buffer(void *ptr, size_t eltsize, size_t nmemb,
34
size_t size = eltsize * nmemb;
35
if (size > buffer->size - buffer->posn)
36
size = buffer->size - buffer->posn;
37
- memcpy(ptr, buffer->buffer + buffer->posn, size);
37
+ memcpy(ptr, (char *) buffer->buffer + buffer->posn, size);
38
buffer->posn += size;
39
return size;
40
}
@@ -49,7 +49,7 @@ size_t fwrite_buffer(const void *ptr, size_t eltsize,
49
buffer->size = buffer->posn + size;
50
buffer->buffer = xrealloc(buffer->buffer, buffer->size);
51
}
52
- memcpy(buffer->buffer + buffer->posn, ptr, size);
52
+ memcpy((char *) buffer->buffer + buffer->posn, ptr, size);
53
buffer->posn += size;
54
data_received++;
55
return size;
pack-check.c
+3
-3
@@ -29,10 +29,10 @@ static int verify_packfile(struct packed_git *p)
29
pack_base = p->pack_base;
30
SHA1_Update(&ctx, pack_base, pack_size - 20);
31
SHA1_Final(sha1, &ctx);
32
- if (memcmp(sha1, pack_base + pack_size - 20, 20))
32
+ if (memcmp(sha1, (char *) pack_base + pack_size - 20, 20))
33
return error("Packfile %s SHA1 mismatch with itself",
34
p->pack_name);
35
- if (memcmp(sha1, index_base + index_size - 40, 20))
35
+ if (memcmp(sha1, (char *) index_base + index_size - 40, 20))
36
return error("Packfile %s SHA1 mismatch with idx",
37
p->pack_name);
38
@@ -135,7 +135,7 @@ int verify_pack(struct packed_git *p, int verbose)
135
SHA1_Init(&ctx);
136
SHA1_Update(&ctx, index_base, index_size - 20);
137
SHA1_Final(sha1, &ctx);
138
- if (memcmp(sha1, index_base + index_size - 20, 20))
138
+ if (memcmp(sha1, (char *) index_base + index_size - 20, 20))
139
ret = error("Packfile index for %s SHA1 mismatch",
140
p->pack_name);
141
pack-objects.c
+2
-2
@@ -156,7 +156,7 @@ static void prepare_pack_revindex(struct pack_revindex *rix)
156
157
rix->revindex = xmalloc(sizeof(unsigned long) * (num_ent + 1));
158
for (i = 0; i < num_ent; i++) {
159
- unsigned int hl = *((unsigned int *)(index + 24 * i));
159
+ unsigned int hl = *((unsigned int *)((char *) index + 24*i));
160
rix->revindex[i] = ntohl(hl);
161
}
162
/* This knows the pack format -- the 20-byte trailer
@@ -300,7 +300,7 @@ static unsigned long write_object(struct sha1file *f,
300
use_packed_git(p);
301
302
datalen = find_packed_object_size(p, entry->in_pack_offset);
303
- buf = p->pack_base + entry->in_pack_offset;
303
+ buf = (char *) p->pack_base + entry->in_pack_offset;
304
sha1write(f, buf, datalen);
305
unuse_packed_git(p);
306
hdrlen = 0; /* not really */
pack-redundant.c
+9
-9
@@ -246,12 +246,12 @@ static struct pack_list * pack_list_difference(const struct pack_list *A,
246
static void cmp_two_packs(struct pack_list *p1, struct pack_list *p2)
247
{
248
int p1_off, p2_off;
249
- void *p1_base, *p2_base;
249
+ unsigned char *p1_base, *p2_base;
250
struct llist_item *p1_hint = NULL, *p2_hint = NULL;
251
-
251
+
252
p1_off = p2_off = 256 * 4 + 4;
253
- p1_base = (void *)p1->pack->index_base;
254
- p2_base = (void *)p2->pack->index_base;
253
+ p1_base = (unsigned char *) p1->pack->index_base;
254
+ p2_base = (unsigned char *) p2->pack->index_base;
255
256
while (p1_off <= p1->pack->index_size - 3 * 20 &&
257
p2_off <= p2->pack->index_size - 3 * 20)
@@ -351,11 +351,11 @@ static size_t sizeof_union(struct packed_git *p1, struct packed_git *p2)
351
{
352
size_t ret = 0;
353
int p1_off, p2_off;
354
- void *p1_base, *p2_base;
354
+ char *p1_base, *p2_base;
355
356
p1_off = p2_off = 256 * 4 + 4;
357
- p1_base = (void *)p1->index_base;
358
- p2_base = (void *)p2->index_base;
357
+ p1_base = (char *)p1->index_base;
358
+ p2_base = (char *)p2->index_base;
359
360
while (p1_off <= p1->index_size - 3 * 20 &&
361
p2_off <= p2->index_size - 3 * 20)
@@ -534,7 +534,7 @@ static struct pack_list * add_pack(struct packed_git *p)
534
{
535
struct pack_list l;
536
size_t off;
537
- void *base;
537
+ unsigned char *base;
538
539
if (!p->pack_local && !(alt_odb || verbose))
540
return NULL;
@@ -543,7 +543,7 @@ static struct pack_list * add_pack(struct packed_git *p)
543
llist_init(&l.all_objects);
544
545
off = 256 * 4 + 4;
546
- base = (void *)p->index_base;
546
+ base = (unsigned char *)p->index_base;
547
while (off <= p->index_size - 3 * 20) {
548
llist_insert_back(l.all_objects, base + off);
549
off += 24;
patch-delta.c
+2
-2
@@ -25,7 +25,7 @@ void *patch_delta(const void *src_buf, unsigned long src_size,
25
return NULL;
26
27
data = delta_buf;
28
- top = delta_buf + delta_size;
28
+ top = (const unsigned char *) delta_buf + delta_size;
29
30
/* make sure the orig file size matches what we expect */
31
size = get_delta_hdr_size(&data, top);
@@ -56,7 +56,7 @@ void *patch_delta(const void *src_buf, unsigned long src_size,
56
cp_off + cp_size > src_size ||
57
cp_size > size)
58
goto bad;
59
- memcpy(out, src_buf + cp_off, cp_size);
59
+ memcpy(out, (char *) src_buf + cp_off, cp_size);
60
out += cp_size;
61
size -= cp_size;
62
} else if (cmd) {
pkt-line.c
+2
-2
@@ -21,7 +21,7 @@ static void safe_write(int fd, const void *buf, unsigned n)
21
while (n) {
22
int ret = xwrite(fd, buf, n);
23
if (ret > 0) {
24
- buf += ret;
24
+ buf = (char *) buf + ret;
25
n -= ret;
26
continue;
27
}
@@ -66,7 +66,7 @@ static void safe_read(int fd, void *buffer, unsigned size)
66
int n = 0;
67
68
while (n < size) {
69
- int ret = xread(fd, buffer + n, size - n);
69
+ int ret = xread(fd, (char *) buffer + n, size - n);
70
if (ret < 0)
71
die("read error (%s)", strerror(errno));
72
if (!ret)
read-cache.c
+7
-6
@@ -706,7 +706,7 @@ static int verify_hdr(struct cache_header *hdr, unsigned long size)
706
SHA1_Init(&c);
707
SHA1_Update(&c, hdr, size - 20);
708
SHA1_Final(sha1, &c);
709
- if (memcmp(sha1, (void *)hdr + size - 20, 20))
709
+ if (memcmp(sha1, (char *) hdr + size - 20, 20))
710
return error("bad index file sha1 signature");
711
return 0;
712
}
@@ -770,7 +770,7 @@ int read_cache(void)
770
771
offset = sizeof(*hdr);
772
for (i = 0; i < active_nr; i++) {
773
- struct cache_entry *ce = map + offset;
773
+ struct cache_entry *ce = (struct cache_entry *) ((char *) map + offset);
774
offset = offset + ce_size(ce);
775
active_cache[i] = ce;
776
}
@@ -783,10 +783,11 @@ int read_cache(void)
783
* in 4-byte network byte order.
784
*/
785
unsigned long extsize;
786
- memcpy(&extsize, map + offset + 4, 4);
786
+ memcpy(&extsize, (char *) map + offset + 4, 4);
787
extsize = ntohl(extsize);
788
- if (read_index_extension(map + offset,
789
- map + offset + 8, extsize) < 0)
788
+ if (read_index_extension(((const char *) map) + offset,
789
+ (char *) map + offset + 8,
790
+ extsize) < 0)
791
goto unmap;
792
offset += 8;
793
offset += extsize;
@@ -820,7 +821,7 @@ static int ce_write(SHA_CTX *context, int fd, void *data, unsigned int len)
821
}
822
write_buffer_len = buffered;
823
len -= partial;
823
- data += partial;
824
+ data = (char *) data + partial;
825
}
826
return 0;
827
}
sha1_file.c
+15
-14
@@ -486,8 +486,9 @@ int use_packed_git(struct packed_git *p)
486
* this is cheap.
487
*/
488
if (memcmp((char*)(p->index_base) + p->index_size - 40,
489
- p->pack_base + p->pack_size - 20, 20)) {
490
-
489
+ (char *) p->pack_base + p->pack_size - 20,
490
+ 20)) {
491
+
492
die("packfile %s does not match index.", p->pack_name);
493
}
494
}
@@ -701,7 +702,7 @@ static void *unpack_sha1_rest(z_stream *stream, void *buffer, unsigned long size
702
int bytes = strlen(buffer) + 1;
703
unsigned char *buf = xmalloc(1+size);
704
704
- memcpy(buf, buffer + bytes, stream->total_out - bytes);
705
+ memcpy(buf, (char *) buffer + bytes, stream->total_out - bytes);
706
bytes = stream->total_out - bytes;
707
if (bytes < size) {
708
stream->next_out = buf + bytes;
@@ -853,7 +854,7 @@ static unsigned long unpack_object_header(struct packed_git *p, unsigned long of
854
if (offset >= p->pack_size)
855
die("object offset outside of pack file");
856
856
- pack = p->pack_base + offset;
857
+ pack = (unsigned char *) p->pack_base + offset;
858
c = *pack++;
859
offset++;
860
*type = (c >> 4) & 7;
@@ -883,7 +884,7 @@ int check_reuse_pack_delta(struct packed_git *p, unsigned long offset,
884
ptr = unpack_object_header(p, ptr, kindp, sizep);
885
if (*kindp != OBJ_DELTA)
886
goto done;
886
- memcpy(base, p->pack_base + ptr, 20);
887
+ memcpy(base, (char *) p->pack_base + ptr, 20);
888
status = 0;
889
done:
890
unuse_packed_git(p);
@@ -903,7 +904,7 @@ void packed_object_info_detail(struct pack_entry *e,
904
enum object_type kind;
905
906
offset = unpack_object_header(p, e->offset, &kind, size);
906
- pack = p->pack_base + offset;
907
+ pack = (unsigned char *) p->pack_base + offset;
908
if (kind != OBJ_DELTA)
909
*delta_chain_length = 0;
910
else {
@@ -919,7 +920,7 @@ void packed_object_info_detail(struct pack_entry *e,
920
find_pack_entry_one(pack, &base_ent, p);
921
offset = unpack_object_header(p, base_ent.offset,
922
&kind, &junk);
922
- pack = p->pack_base + offset;
923
+ pack = (unsigned char *) p->pack_base + offset;
924
chain_length++;
925
} while (kind == OBJ_DELTA);
926
*delta_chain_length = chain_length;
@@ -957,7 +958,7 @@ static int packed_object_info(struct pack_entry *entry,
958
die("cannot map packed file");
959
960
offset = unpack_object_header(p, entry->offset, &kind, &size);
960
- pack = p->pack_base + offset;
961
+ pack = (unsigned char *) p->pack_base + offset;
962
left = p->pack_size - offset;
963
964
switch (kind) {
@@ -1096,7 +1097,7 @@ void *unpack_entry_gently(struct pack_entry *entry,
1097
void *retval;
1098
1099
offset = unpack_object_header(p, entry->offset, &kind, &size);
1099
- pack = p->pack_base + offset;
1100
+ pack = (unsigned char *) p->pack_base + offset;
1101
left = p->pack_size - offset;
1102
switch (kind) {
1103
case OBJ_DELTA:
@@ -1134,7 +1135,7 @@ int nth_packed_object_sha1(const struct packed_git *p, int n,
1135
void *index = p->index_base + 256;
1136
if (n < 0 || num_packed_objects(p) <= n)
1137
return -1;
1137
- memcpy(sha1, (index + 24 * n + 4), 20);
1138
+ memcpy(sha1, (char *) index + (24 * n) + 4, 20);
1139
return 0;
1140
}
1141
@@ -1148,9 +1149,9 @@ int find_pack_entry_one(const unsigned char *sha1,
1149
1150
do {
1151
int mi = (lo + hi) / 2;
1151
- int cmp = memcmp(index + 24 * mi + 4, sha1, 20);
1152
+ int cmp = memcmp((char *) index + (24 * mi) + 4, sha1, 20);
1153
if (!cmp) {
1153
- e->offset = ntohl(*((unsigned int *)(index + 24 * mi)));
1154
+ e->offset = ntohl(*((unsigned int *) ((char *) index + (24 * mi))));
1155
memcpy(e->sha1, sha1, 20);
1156
e->p = p;
1157
return 1;
@@ -1290,7 +1291,7 @@ void *read_object_with_reference(const unsigned char *sha1,
1291
ref_length = strlen(ref_type);
1292
1293
if (memcmp(buffer, ref_type, ref_length) ||
1293
- get_sha1_hex(buffer + ref_length, actual_sha1)) {
1294
+ get_sha1_hex((char *) buffer + ref_length, actual_sha1)) {
1295
free(buffer);
1296
return NULL;
1297
}
@@ -1408,7 +1409,7 @@ static int write_buffer(int fd, const void *buf, size_t len)
1409
return error("file write error (%s)", strerror(errno));
1410
}
1411
len -= size;
1411
- buf += size;
1412
+ buf = (char *) buf + size;
1413
}
1414
return 0;
1415
}
ssh-fetch.c
+1
-1
@@ -24,7 +24,7 @@ static ssize_t force_write(int fd, void *buffer, size_t length)
24
{
25
ssize_t ret = 0;
26
while (ret < length) {
27
- ssize_t size = write(fd, buffer + ret, length - ret);
27
+ ssize_t size = write(fd, (char *) buffer + ret, length - ret);
28
if (size < 0) {
29
return size;
30
}
tag.c
+2
-2
@@ -47,10 +47,10 @@ int parse_tag_buffer(struct tag *item, void *data, unsigned long size)
47
48
if (size < 64)
49
return -1;
50
- if (memcmp("object ", data, 7) || get_sha1_hex(data + 7, object))
50
+ if (memcmp("object ", data, 7) || get_sha1_hex((char *) data + 7, object))
51
return -1;
52
53
- type_line = data + 48;
53
+ type_line = (char *) data + 48;
54
if (memcmp("\ntype ", type_line-1, 6))
55
return -1;
56
tree-walk.c
+6
-5
@@ -43,7 +43,7 @@ void update_tree_entry(struct tree_desc *desc)
43
44
if (size < len)
45
die("corrupt tree file");
46
- desc->buf = buf + len;
46
+ desc->buf = (char *) buf + len;
47
desc->size = size - len;
48
}
49
@@ -66,7 +66,7 @@ const unsigned char *tree_entry_extract(struct tree_desc *desc, const char **pat
66
const void *tree = desc->buf;
67
unsigned long size = desc->size;
68
int len = strlen(tree)+1;
69
- const unsigned char *sha1 = tree + len;
69
+ const unsigned char *sha1 = (unsigned char *) tree + len;
70
const char *path;
71
unsigned int mode;
72
@@ -80,7 +80,8 @@ const unsigned char *tree_entry_extract(struct tree_desc *desc, const char **pat
80
81
int tree_entry(struct tree_desc *desc, struct name_entry *entry)
82
{
83
- const void *tree = desc->buf, *path;
83
+ const void *tree = desc->buf;
84
+ const char *path;
85
unsigned long len, size = desc->size;
86
87
if (!size)
@@ -95,10 +96,10 @@ int tree_entry(struct tree_desc *desc, struct name_entry *entry)
96
entry->pathlen = len;
97
98
path += len + 1;
98
- entry->sha1 = path;
99
+ entry->sha1 = (const unsigned char *) path;
100
101
path += 20;
101
- len = path - tree;
102
+ len = path - (char *) tree;
103
if (len > size)
104
die("corrupt tree file");
105