Skip to content

Commit d790ba9

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

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
@@ -526,9 +526,10 @@ int strbuf_getwholeline_fd(struct strbuf *sb, int fd, int term)
526526
return 0;
527527
}
528528

529-
int strbuf_read_file(struct strbuf *sb, const char *path, size_t hint)
529+
ssize_t strbuf_read_file(struct strbuf *sb, const char *path, size_t hint)
530530
{
531-
int fd, len;
531+
int fd;
532+
ssize_t len;
532533

533534
fd = open(path, O_RDONLY);
534535
if (fd < 0)

strbuf.h

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

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

0 commit comments

Comments
 (0)