Download raw body.
[patch] getline: fix the return type to ssize_t and small nits
Hi,
The below patch changes the return type of getline from size_t to ssize_t.
It also changes a few tiny nits :)
- Remove an unnecessary cast.
- Follow the same error handling pattern as in worktree.c copy_one_line().
From 500467ff1bf0dbd15c0941dd741e80c35c708818 Mon Sep 17 00:00:00 2001
From: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Wed, 25 Sep 2019 22:02:03 +0200
Subject: [PATCH] getline: fix the return type to ssize_t and small nits
---
got/got.c | 2 +-
lib/diff3.c | 3 ++-
lib/worktree.c | 7 +++++--
3 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/got/got.c b/got/got.c
index e9a814c..212005d 100644
--- a/got/got.c
+++ b/got/got.c
@@ -2410,7 +2410,7 @@ blame_cb(void *arg, int nlines, int lineno, struct got_object_id *id)
char *smallerthan, *at, *nl, *committer;
size_t len;
- if (getline(&line, &linesize, a->f) == (ssize_t)-1) {
+ if (getline(&line, &linesize, a->f) == -1) {
if (ferror(a->f))
err = got_error_from_errno("getline");
break;
diff --git a/lib/diff3.c b/lib/diff3.c
index 87c3a41..7f642f7 100644
--- a/lib/diff3.c
+++ b/lib/diff3.c
@@ -655,7 +655,8 @@ static char *
get_line(FILE *b, size_t *n, struct diff3_state *d3s)
{
char *cp = NULL;
- size_t size, len;
+ size_t size;
+ ssize_t len;
char *new;
char *ret = NULL;
diff --git a/lib/worktree.c b/lib/worktree.c
index c6ccac6..729abd3 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -2864,9 +2864,12 @@ skip_one_line(FILE *f)
ssize_t linelen;
linelen = getline(&line, &linesize, f);
+ if (linelen == -1) {
+ if (ferror(f))
+ return got_error_from_errno("getline");
+ return NULL;
+ }
free(line);
- if (linelen == -1 && ferror(f))
- return got_error_from_errno("getline");
return NULL;
}
--
2.21.0
--
Kind regards,
Hiltjo
[patch] getline: fix the return type to ssize_t and small nits