diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2024-06-06 20:09:48 +1000 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2024-06-07 20:44:44 +0200 |
commit | f9e8ee0777c257ffd2956a6dd51e866dff26bc8e (patch) | |
tree | 048a78b97301e3cac3e1d79bf4dff78bba351c33 /lineread.c | |
parent | c919bbbdd370f86af37e18ca991c936d3bf36cfa (diff) | |
download | passt-f9e8ee0777c257ffd2956a6dd51e866dff26bc8e.tar passt-f9e8ee0777c257ffd2956a6dd51e866dff26bc8e.tar.gz passt-f9e8ee0777c257ffd2956a6dd51e866dff26bc8e.tar.bz2 passt-f9e8ee0777c257ffd2956a6dd51e866dff26bc8e.tar.lz passt-f9e8ee0777c257ffd2956a6dd51e866dff26bc8e.tar.xz passt-f9e8ee0777c257ffd2956a6dd51e866dff26bc8e.tar.zst passt-f9e8ee0777c257ffd2956a6dd51e866dff26bc8e.zip |
lineread: Use ssize_t for line lengths
Functions and structures in lineread.c use plain int to record and report
the length of lines we receive. This means we truncate the result from
read(2) in some circumstances. Use ssize_t to avoid that.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'lineread.c')
-rw-r--r-- | lineread.c | 10 |
1 files changed, 4 insertions, 6 deletions
@@ -39,13 +39,11 @@ void lineread_init(struct lineread *lr, int fd) * * Return: length of line in bytes, -1 if no line was found */ -static int peek_line(struct lineread *lr, bool eof) +static ssize_t peek_line(struct lineread *lr, bool eof) { char *nl; /* Sanity checks (which also document invariants) */ - ASSERT(lr->count >= 0); - ASSERT(lr->next_line >= 0); ASSERT(lr->next_line + lr->count >= lr->next_line); ASSERT(lr->next_line + lr->count <= LINEREAD_BUFFER_SIZE); @@ -74,13 +72,13 @@ static int peek_line(struct lineread *lr, bool eof) * * Return: Length of line read on success, 0 on EOF, negative on error */ -int lineread_get(struct lineread *lr, char **line) +ssize_t lineread_get(struct lineread *lr, char **line) { bool eof = false; - int line_len; + ssize_t line_len; while ((line_len = peek_line(lr, eof)) < 0) { - int rc; + ssize_t rc; if ((lr->next_line + lr->count) == LINEREAD_BUFFER_SIZE) { /* No space at end */ |