Skip to content

Commit 8a912bc

Browse files
jherlandJunio C Hamano
authored and
Junio C Hamano
committed
Ensure return value from xread() is always stored into an ssize_t
This patch fixes all calls to xread() where the return value is not stored into an ssize_t. The patch should not have any effect whatsoever, other than putting better/more appropriate type names on variables. Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 2924415 commit 8a912bc

12 files changed

+15
-16
lines changed

builtin-apply.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ static void *read_patch_file(int fd, unsigned long *sizep)
185185
void *buffer = xmalloc(alloc);
186186

187187
for (;;) {
188-
int nr = alloc - size;
188+
ssize_t nr = alloc - size;
189189
if (nr < 1024) {
190190
alloc += CHUNKSIZE;
191191
buffer = xrealloc(buffer, alloc);
@@ -1468,7 +1468,7 @@ static int read_old_data(struct stat *st, const char *path, char **buf_p, unsign
14681468
return error("unable to open %s", path);
14691469
got = 0;
14701470
for (;;) {
1471-
int ret = xread(fd, buf + got, size - got);
1471+
ssize_t ret = xread(fd, buf + got, size - got);
14721472
if (ret <= 0)
14731473
break;
14741474
got += ret;

builtin-bundle.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static int read_string(int fd, char *buffer, int size)
4848
{
4949
int i;
5050
for (i = 0; i < size - 1; i++) {
51-
int count = xread(fd, buffer + i, 1);
51+
ssize_t count = xread(fd, buffer + i, 1);
5252
if (count < 0)
5353
return error("Read error: %s", strerror(errno));
5454
if (count == 0) {

builtin-fetch--tool.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
static char *get_stdin(void)
88
{
9-
int offset = 0;
9+
size_t offset = 0;
1010
char *data = xmalloc(CHUNK_SIZE);
1111

1212
while (1) {
13-
int cnt = xread(0, data + offset, CHUNK_SIZE);
13+
ssize_t cnt = xread(0, data + offset, CHUNK_SIZE);
1414
if (cnt < 0)
1515
die("error reading standard input: %s",
1616
strerror(errno));

builtin-unpack-objects.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static void *fill(int min)
3434
offset = 0;
3535
}
3636
do {
37-
int ret = xread(0, buffer + len, sizeof(buffer) - len);
37+
ssize_t ret = xread(0, buffer + len, sizeof(buffer) - len);
3838
if (ret <= 0) {
3939
if (!ret)
4040
die("early EOF");

combine-diff.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
714714
result_size = len;
715715
result = xmalloc(len + 1);
716716
while (sz < len) {
717-
int done = xread(fd, result+sz, len-sz);
717+
ssize_t done = xread(fd, result+sz, len-sz);
718718
if (done == 0)
719719
break;
720720
if (done < 0)

copy.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
int copy_fd(int ifd, int ofd)
44
{
55
while (1) {
6-
int len;
76
char buffer[8192];
87
char *buf = buffer;
9-
len = xread(ifd, buffer, sizeof(buffer));
8+
ssize_t len = xread(ifd, buffer, sizeof(buffer));
109
if (!len)
1110
break;
1211
if (len < 0) {

diff.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,7 @@ static int populate_from_stdin(struct diff_filespec *s)
14111411
#define INCREMENT 1024
14121412
char *buf;
14131413
unsigned long size;
1414-
int got;
1414+
ssize_t got;
14151415

14161416
size = 0;
14171417
buf = NULL;

imap-send.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ socket_perror( const char *func, Socket_t *sock, int ret )
224224
static int
225225
socket_read( Socket_t *sock, char *buf, int len )
226226
{
227-
int n = xread( sock->fd, buf, len );
227+
ssize_t n = xread( sock->fd, buf, len );
228228
if (n <= 0) {
229229
socket_perror( "read", sock, n );
230230
close( sock->fd );

index-pack.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static void *fill(int min)
8282
die("cannot fill %d bytes", min);
8383
flush();
8484
do {
85-
int ret = xread(input_fd, input_buffer + input_len,
85+
ssize_t ret = xread(input_fd, input_buffer + input_len,
8686
sizeof(input_buffer) - input_len);
8787
if (ret <= 0) {
8888
if (!ret)

pkt-line.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ void packet_write(int fd, const char *fmt, ...)
6565

6666
static void safe_read(int fd, void *buffer, unsigned size)
6767
{
68-
int n = 0;
68+
size_t n = 0;
6969

7070
while (n < size) {
71-
int ret = xread(fd, (char *) buffer + n, size - n);
71+
ssize_t ret = xread(fd, (char *) buffer + n, size - n);
7272
if (ret < 0)
7373
die("read error (%s)", strerror(errno));
7474
if (!ret)

sha1_file.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2276,7 +2276,7 @@ int read_pipe(int fd, char** return_buf, unsigned long* return_size)
22762276
{
22772277
char* buf = *return_buf;
22782278
unsigned long size = *return_size;
2279-
int iret;
2279+
ssize_t iret;
22802280
unsigned long off = 0;
22812281

22822282
do {

ssh-upload.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static int serve_ref(int fd_in, int fd_out)
8686

8787
static void service(int fd_in, int fd_out) {
8888
char type;
89-
int retval;
89+
ssize_t retval;
9090
do {
9191
retval = xread(fd_in, &type, 1);
9292
if (retval < 1) {

0 commit comments

Comments
 (0)