Patchwork [3/4] erec: Handle returned value properly in erec_print

login
register
mail settings
Submitter Tomasz Bursztyka
Date Aug. 2, 2012, 10:31 a.m.
Message ID <1343903495-14486-4-git-send-email-tomasz.bursztyka@linux.intel.com>
Download mbox | patch
Permalink /patch/174721/
State Accepted
Headers show

Comments

Tomasz Bursztyka - Aug. 2, 2012, 10:31 a.m.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
---
 src/erec.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

Patch

diff --git a/src/erec.c b/src/erec.c
index 501bf4b..554a406 100644
--- a/src/erec.c
+++ b/src/erec.c
@@ -78,7 +78,7 @@  void erec_print(FILE *f, const struct error_record *erec)
 	const char *line = NULL; /* silence gcc */
 	char buf[1024];
 	unsigned int i, end;
-	int l;
+	int l, ret;
 
 	switch (indesc->type) {
 	case INDESC_BUFFER:
@@ -88,8 +88,9 @@  void erec_print(FILE *f, const struct error_record *erec)
 	case INDESC_FILE:
 		memset(buf, 0, sizeof(buf));
 		lseek(indesc->fd, loc->line_offset, SEEK_SET);
-		read(indesc->fd, buf, sizeof(buf) - 1);
-		*strchrnul(buf, '\n') = '\0';
+		ret = read(indesc->fd, buf, sizeof(buf) - 1);
+		if (ret > 0)
+			*strchrnul(buf, '\n') = '\0';
 		line = buf;
 		break;
 	case INDESC_INTERNAL: