Skip to content

Commit 3b175fb

Browse files
committed
Merge branch 'mh/strbuf-read-file-returns-ssize-t' into maint
Avoid possible ssize_t to int truncation. * mh/strbuf-read-file-returns-ssize-t: strbuf: strbuf_read_file() should return ssize_t
2 parents 6f402a9 + 6c8afe4 commit 3b175fb

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

strbuf.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,9 +481,10 @@ int strbuf_getwholeline_fd(struct strbuf *sb, int fd, int term)
481481
return 0;
482482
}
483483

484-
int strbuf_read_file(struct strbuf *sb, const char *path, size_t hint)
484+
ssize_t strbuf_read_file(struct strbuf *sb, const char *path, size_t hint)
485485
{
486-
int fd, len;
486+
int fd;
487+
ssize_t len;
487488

488489
fd = open(path, O_RDONLY);
489490
if (fd < 0)

strbuf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ extern ssize_t strbuf_read(struct strbuf *, int fd, size_t hint);
364364
* Read the contents of a file, specified by its path. The third argument
365365
* can be used to give a hint about the file size, to avoid reallocs.
366366
*/
367-
extern int strbuf_read_file(struct strbuf *sb, const char *path, size_t hint);
367+
extern ssize_t strbuf_read_file(struct strbuf *sb, const char *path, size_t hint);
368368

369369
/**
370370
* Read the target of a symbolic link, specified by its path. The third

0 commit comments

Comments
 (0)