Skip to content

Commit 1d7f171

Browse files
Florian ForsterJunio C Hamano
authored andcommitted
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>
1 parent 2bda77e commit 1d7f171

19 files changed

Lines changed: 72 additions & 69 deletions

builtin-apply.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ static void *read_patch_file(int fd, unsigned long *sizep)
148148
buffer = xrealloc(buffer, alloc);
149149
nr = alloc - size;
150150
}
151-
nr = xread(fd, buffer + size, nr);
151+
nr = xread(fd, (char *) buffer + size, nr);
152152
if (!nr)
153153
break;
154154
if (nr < 0)
@@ -164,7 +164,7 @@ static void *read_patch_file(int fd, unsigned long *sizep)
164164
*/
165165
if (alloc < size + SLOP)
166166
buffer = xrealloc(buffer, size + SLOP);
167-
memset(buffer + size, 0, SLOP);
167+
memset((char *) buffer + size, 0, SLOP);
168168
return buffer;
169169
}
170170

@@ -1194,7 +1194,7 @@ static int read_old_data(struct stat *st, const char *path, void *buf, unsigned
11941194
return error("unable to open %s", path);
11951195
got = 0;
11961196
for (;;) {
1197-
int ret = xread(fd, buf + got, size - got);
1197+
int ret = xread(fd, (char *) buf + got, size - got);
11981198
if (ret <= 0)
11991199
break;
12001200
got += ret;

convert-objects.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ static int write_subdirectory(void *buffer, unsigned long size, const char *base
103103
if (!slash) {
104104
newlen += sprintf(new + newlen, "%o %s", mode, path);
105105
new[newlen++] = '\0';
106-
memcpy(new + newlen, buffer + len - 20, 20);
106+
memcpy(new + newlen, (char *) buffer + len - 20, 20);
107107
newlen += 20;
108108

109109
used += len;
110110
size -= len;
111-
buffer += len;
111+
buffer = (char *) buffer + len;
112112
continue;
113113
}
114114

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

122122
used += len;
123123
size -= len;
124-
buffer += len;
124+
buffer = (char *) buffer + len;
125125
}
126126

127127
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
137137
while (size) {
138138
int len = 1+strlen(buffer);
139139

140-
convert_binary_sha1(buffer + len);
140+
convert_binary_sha1((char *) buffer + len);
141141

142142
len += 20;
143143
if (len > size)
144144
die("corrupt tree object");
145145
size -= len;
146-
buffer += len;
146+
buffer = (char *) buffer + len;
147147
}
148148

149149
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
244244
// "tree <sha1>\n"
245245
memcpy(new + newlen, buffer, 46);
246246
newlen += 46;
247-
buffer += 46;
247+
buffer = (char *) buffer + 46;
248248
size -= 46;
249249

250250
// "parent <sha1>\n"
251251
while (!memcmp(buffer, "parent ", 7)) {
252252
memcpy(new + newlen, buffer, 48);
253253
newlen += 48;
254-
buffer += 48;
254+
buffer = (char *) buffer + 48;
255255
size -= 48;
256256
}
257257

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

276276
if (memcmp(buffer, "tree ", 5))
277277
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" */
280280
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;
283283
}
284284
convert_date(orig_buffer, orig_size, result_sha1);
285285
}

csum-file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ static int sha1flush(struct sha1file *f, unsigned int count)
1717
for (;;) {
1818
int ret = xwrite(f->fd, buf, count);
1919
if (ret > 0) {
20-
buf += ret;
20+
buf = (char *) buf + ret;
2121
count -= ret;
2222
if (count)
2323
continue;
@@ -57,7 +57,7 @@ int sha1write(struct sha1file *f, void *buf, unsigned int count)
5757
memcpy(f->buffer + offset, buf, nr);
5858
count -= nr;
5959
offset += nr;
60-
buf += nr;
60+
buf = (char *) buf + nr;
6161
left -= nr;
6262
if (!left) {
6363
SHA1_Update(&f->ctx, f->buffer, offset);

diff-delta.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ create_delta(const struct delta_index *index,
284284
ref_data = index->src_buf;
285285
ref_top = ref_data + index->src_size;
286286
data = trg_buf;
287-
top = trg_buf + trg_size;
287+
top = (const unsigned char *) trg_buf + trg_size;
288288

289289
outpos++;
290290
val = 0;

diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ static void emit_binary_diff(mmfile_t *one, mmfile_t *two)
515515
else
516516
line[0] = bytes - 26 + 'a' - 1;
517517
encode_85(line + 1, cp, bytes);
518-
cp += bytes;
518+
cp = (char *) cp + bytes;
519519
puts(line);
520520
}
521521
printf("\n");

diffcore-order.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static void prepare_order(const char *orderfile)
3030
close(fd);
3131
if (map == MAP_FAILED)
3232
return;
33-
endp = map + st.st_size;
33+
endp = (char *) map + st.st_size;
3434
for (pass = 0; pass < 2; pass++) {
3535
cnt = 0;
3636
cp = map;

http-fetch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,
123123
struct object_request *obj_req = (struct object_request *)data;
124124
do {
125125
ssize_t retval = write(obj_req->local,
126-
ptr + posn, size - posn);
126+
(char *) ptr + posn, size - posn);
127127
if (retval < 0)
128128
return posn;
129129
posn += retval;

http-push.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,
196196
struct transfer_request *request = (struct transfer_request *)data;
197197
do {
198198
ssize_t retval = write(request->local_fileno,
199-
ptr + posn, size - posn);
199+
(char *) ptr + posn, size - posn);
200200
if (retval < 0)
201201
return posn;
202202
posn += retval;

http.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ size_t fread_buffer(void *ptr, size_t eltsize, size_t nmemb,
3434
size_t size = eltsize * nmemb;
3535
if (size > buffer->size - buffer->posn)
3636
size = buffer->size - buffer->posn;
37-
memcpy(ptr, buffer->buffer + buffer->posn, size);
37+
memcpy(ptr, (char *) buffer->buffer + buffer->posn, size);
3838
buffer->posn += size;
3939
return size;
4040
}
@@ -49,7 +49,7 @@ size_t fwrite_buffer(const void *ptr, size_t eltsize,
4949
buffer->size = buffer->posn + size;
5050
buffer->buffer = xrealloc(buffer->buffer, buffer->size);
5151
}
52-
memcpy(buffer->buffer + buffer->posn, ptr, size);
52+
memcpy((char *) buffer->buffer + buffer->posn, ptr, size);
5353
buffer->posn += size;
5454
data_received++;
5555
return size;

pack-check.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ static int verify_packfile(struct packed_git *p)
2929
pack_base = p->pack_base;
3030
SHA1_Update(&ctx, pack_base, pack_size - 20);
3131
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))
3333
return error("Packfile %s SHA1 mismatch with itself",
3434
p->pack_name);
35-
if (memcmp(sha1, index_base + index_size - 40, 20))
35+
if (memcmp(sha1, (char *) index_base + index_size - 40, 20))
3636
return error("Packfile %s SHA1 mismatch with idx",
3737
p->pack_name);
3838

@@ -135,7 +135,7 @@ int verify_pack(struct packed_git *p, int verbose)
135135
SHA1_Init(&ctx);
136136
SHA1_Update(&ctx, index_base, index_size - 20);
137137
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))
139139
ret = error("Packfile index for %s SHA1 mismatch",
140140
p->pack_name);
141141

0 commit comments

Comments
 (0)