@matheusbsbs / matheus-bagliano / commits / 8a912bcb25
Fork 0

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>

Johan Herland committed May 15, 2007 at 14:49 UTC 8a912bcb250d8bf57b225e1cf02c0d69d54c8920
12 files changed +15 -16
builtin-apply.c
+2 -2
@@ -185,7 +185,7 @@ static void *read_patch_file(int fd, unsigned long *sizep)
185 void *buffer = xmalloc(alloc);
186
187 for (;;) {
188 - int nr = alloc - size;
188 + ssize_t nr = alloc - size;
189 if (nr < 1024) {
190 alloc += CHUNKSIZE;
191 buffer = xrealloc(buffer, alloc);
@@ -1468,7 +1468,7 @@ static int read_old_data(struct stat *st, const char *path, char **buf_p, unsign
1468 return error("unable to open %s", path);
1469 got = 0;
1470 for (;;) {
1471 - int ret = xread(fd, buf + got, size - got);
1471 + ssize_t ret = xread(fd, buf + got, size - got);
1472 if (ret <= 0)
1473 break;
1474 got += ret;
builtin-bundle.c
+1 -1
@@ -48,7 +48,7 @@ static int read_string(int fd, char *buffer, int size)
48 {
49 int i;
50 for (i = 0; i < size - 1; i++) {
51 - int count = xread(fd, buffer + i, 1);
51 + ssize_t count = xread(fd, buffer + i, 1);
52 if (count < 0)
53 return error("Read error: %s", strerror(errno));
54 if (count == 0) {
builtin-fetch--tool.c
+2 -2
@@ -6,11 +6,11 @@
6
7 static char *get_stdin(void)
8 {
9 - int offset = 0;
9 + size_t offset = 0;
10 char *data = xmalloc(CHUNK_SIZE);
11
12 while (1) {
13 - int cnt = xread(0, data + offset, CHUNK_SIZE);
13 + ssize_t cnt = xread(0, data + offset, CHUNK_SIZE);
14 if (cnt < 0)
15 die("error reading standard input: %s",
16 strerror(errno));
builtin-unpack-objects.c
+1 -1
@@ -34,7 +34,7 @@ static void *fill(int min)
34 offset = 0;
35 }
36 do {
37 - int ret = xread(0, buffer + len, sizeof(buffer) - len);
37 + ssize_t ret = xread(0, buffer + len, sizeof(buffer) - len);
38 if (ret <= 0) {
39 if (!ret)
40 die("early EOF");
combine-diff.c
+1 -1
@@ -714,7 +714,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
714 result_size = len;
715 result = xmalloc(len + 1);
716 while (sz < len) {
717 - int done = xread(fd, result+sz, len-sz);
717 + ssize_t done = xread(fd, result+sz, len-sz);
718 if (done == 0)
719 break;
720 if (done < 0)
copy.c
+1 -2
@@ -3,10 +3,9 @@
3 int copy_fd(int ifd, int ofd)
4 {
5 while (1) {
6 - int len;
6 char buffer[8192];
7 char *buf = buffer;
9 - len = xread(ifd, buffer, sizeof(buffer));
8 + ssize_t len = xread(ifd, buffer, sizeof(buffer));
9 if (!len)
10 break;
11 if (len < 0) {
diff.c
+1 -1
@@ -1411,7 +1411,7 @@ static int populate_from_stdin(struct diff_filespec *s)
1411 #define INCREMENT 1024
1412 char *buf;
1413 unsigned long size;
1414 - int got;
1414 + ssize_t got;
1415
1416 size = 0;
1417 buf = NULL;
imap-send.c
+1 -1
@@ -224,7 +224,7 @@ socket_perror( const char *func, Socket_t *sock, int ret )
224 static int
225 socket_read( Socket_t *sock, char *buf, int len )
226 {
227 - int n = xread( sock->fd, buf, len );
227 + ssize_t n = xread( sock->fd, buf, len );
228 if (n <= 0) {
229 socket_perror( "read", sock, n );
230 close( sock->fd );
index-pack.c
+1 -1
@@ -82,7 +82,7 @@ static void *fill(int min)
82 die("cannot fill %d bytes", min);
83 flush();
84 do {
85 - int ret = xread(input_fd, input_buffer + input_len,
85 + ssize_t ret = xread(input_fd, input_buffer + input_len,
86 sizeof(input_buffer) - input_len);
87 if (ret <= 0) {
88 if (!ret)
pkt-line.c
+2 -2
@@ -65,10 +65,10 @@ void packet_write(int fd, const char *fmt, ...)
65
66 static void safe_read(int fd, void *buffer, unsigned size)
67 {
68 - int n = 0;
68 + size_t n = 0;
69
70 while (n < size) {
71 - int ret = xread(fd, (char *) buffer + n, size - n);
71 + ssize_t ret = xread(fd, (char *) buffer + n, size - n);
72 if (ret < 0)
73 die("read error (%s)", strerror(errno));
74 if (!ret)
sha1_file.c
+1 -1
@@ -2276,7 +2276,7 @@ int read_pipe(int fd, char** return_buf, unsigned long* return_size)
2276 {
2277 char* buf = *return_buf;
2278 unsigned long size = *return_size;
2279 - int iret;
2279 + ssize_t iret;
2280 unsigned long off = 0;
2281
2282 do {
ssh-upload.c
+1 -1
@@ -86,7 +86,7 @@ static int serve_ref(int fd_in, int fd_out)
86
87 static void service(int fd_in, int fd_out) {
88 char type;
89 - int retval;
89 + ssize_t retval;
90 do {
91 retval = xread(fd_in, &type, 1);
92 if (retval < 1) {