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>
This commit is contained in:
Johan Herland
2007-05-15 14:49:22 +02:00
committed by Junio C Hamano
parent 2924415f4f
commit 8a912bcb25
12 changed files with 15 additions and 16 deletions

View File

@ -185,7 +185,7 @@ static void *read_patch_file(int fd, unsigned long *sizep)
void *buffer = xmalloc(alloc); void *buffer = xmalloc(alloc);
for (;;) { for (;;) {
int nr = alloc - size; ssize_t nr = alloc - size;
if (nr < 1024) { if (nr < 1024) {
alloc += CHUNKSIZE; alloc += CHUNKSIZE;
buffer = xrealloc(buffer, alloc); buffer = xrealloc(buffer, alloc);
@ -1468,7 +1468,7 @@ static int read_old_data(struct stat *st, const char *path, char **buf_p, unsign
return error("unable to open %s", path); return error("unable to open %s", path);
got = 0; got = 0;
for (;;) { for (;;) {
int ret = xread(fd, buf + got, size - got); ssize_t ret = xread(fd, buf + got, size - got);
if (ret <= 0) if (ret <= 0)
break; break;
got += ret; got += ret;

View File

@ -48,7 +48,7 @@ static int read_string(int fd, char *buffer, int size)
{ {
int i; int i;
for (i = 0; i < size - 1; i++) { for (i = 0; i < size - 1; i++) {
int count = xread(fd, buffer + i, 1); ssize_t count = xread(fd, buffer + i, 1);
if (count < 0) if (count < 0)
return error("Read error: %s", strerror(errno)); return error("Read error: %s", strerror(errno));
if (count == 0) { if (count == 0) {

View File

@ -6,11 +6,11 @@
static char *get_stdin(void) static char *get_stdin(void)
{ {
int offset = 0; size_t offset = 0;
char *data = xmalloc(CHUNK_SIZE); char *data = xmalloc(CHUNK_SIZE);
while (1) { while (1) {
int cnt = xread(0, data + offset, CHUNK_SIZE); ssize_t cnt = xread(0, data + offset, CHUNK_SIZE);
if (cnt < 0) if (cnt < 0)
die("error reading standard input: %s", die("error reading standard input: %s",
strerror(errno)); strerror(errno));

View File

@ -34,7 +34,7 @@ static void *fill(int min)
offset = 0; offset = 0;
} }
do { do {
int ret = xread(0, buffer + len, sizeof(buffer) - len); ssize_t ret = xread(0, buffer + len, sizeof(buffer) - len);
if (ret <= 0) { if (ret <= 0) {
if (!ret) if (!ret)
die("early EOF"); die("early EOF");

View File

@ -714,7 +714,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
result_size = len; result_size = len;
result = xmalloc(len + 1); result = xmalloc(len + 1);
while (sz < len) { while (sz < len) {
int done = xread(fd, result+sz, len-sz); ssize_t done = xread(fd, result+sz, len-sz);
if (done == 0) if (done == 0)
break; break;
if (done < 0) if (done < 0)

3
copy.c
View File

@ -3,10 +3,9 @@
int copy_fd(int ifd, int ofd) int copy_fd(int ifd, int ofd)
{ {
while (1) { while (1) {
int len;
char buffer[8192]; char buffer[8192];
char *buf = buffer; char *buf = buffer;
len = xread(ifd, buffer, sizeof(buffer)); ssize_t len = xread(ifd, buffer, sizeof(buffer));
if (!len) if (!len)
break; break;
if (len < 0) { if (len < 0) {

2
diff.c
View File

@ -1411,7 +1411,7 @@ static int populate_from_stdin(struct diff_filespec *s)
#define INCREMENT 1024 #define INCREMENT 1024
char *buf; char *buf;
unsigned long size; unsigned long size;
int got; ssize_t got;
size = 0; size = 0;
buf = NULL; buf = NULL;

View File

@ -224,7 +224,7 @@ socket_perror( const char *func, Socket_t *sock, int ret )
static int static int
socket_read( Socket_t *sock, char *buf, int len ) socket_read( Socket_t *sock, char *buf, int len )
{ {
int n = xread( sock->fd, buf, len ); ssize_t n = xread( sock->fd, buf, len );
if (n <= 0) { if (n <= 0) {
socket_perror( "read", sock, n ); socket_perror( "read", sock, n );
close( sock->fd ); close( sock->fd );

View File

@ -82,7 +82,7 @@ static void *fill(int min)
die("cannot fill %d bytes", min); die("cannot fill %d bytes", min);
flush(); flush();
do { do {
int ret = xread(input_fd, input_buffer + input_len, ssize_t ret = xread(input_fd, input_buffer + input_len,
sizeof(input_buffer) - input_len); sizeof(input_buffer) - input_len);
if (ret <= 0) { if (ret <= 0) {
if (!ret) if (!ret)

View File

@ -65,10 +65,10 @@ void packet_write(int fd, const char *fmt, ...)
static void safe_read(int fd, void *buffer, unsigned size) static void safe_read(int fd, void *buffer, unsigned size)
{ {
int n = 0; size_t n = 0;
while (n < size) { while (n < size) {
int ret = xread(fd, (char *) buffer + n, size - n); ssize_t ret = xread(fd, (char *) buffer + n, size - n);
if (ret < 0) if (ret < 0)
die("read error (%s)", strerror(errno)); die("read error (%s)", strerror(errno));
if (!ret) if (!ret)

View File

@ -2276,7 +2276,7 @@ int read_pipe(int fd, char** return_buf, unsigned long* return_size)
{ {
char* buf = *return_buf; char* buf = *return_buf;
unsigned long size = *return_size; unsigned long size = *return_size;
int iret; ssize_t iret;
unsigned long off = 0; unsigned long off = 0;
do { do {

View File

@ -86,7 +86,7 @@ static int serve_ref(int fd_in, int fd_out)
static void service(int fd_in, int fd_out) { static void service(int fd_in, int fd_out) {
char type; char type;
int retval; ssize_t retval;
do { do {
retval = xread(fd_in, &type, 1); retval = xread(fd_in, &type, 1);
if (retval < 1) { if (retval < 1) {