e937f6
diff --git a/src/compress.c b/src/compress.c
e937f6
index cb11303..5677412 100644
e937f6
--- a/src/compress.c
e937f6
+++ b/src/compress.c
e937f6
@@ -723,25 +723,24 @@ uncompressbuf(int fd, size_t bytes_max, size_t method, const unsigned char *old,
e937f6
 		rv = OKDATA;
e937f6
 		if ((r = sread(fdp[STDOUT_FILENO][0], *newch, bytes_max, 0)) > 0)
e937f6
 			break;
e937f6
-		DPRINTF("Read stdout failed %d (%s)\n", fdp[STDOUT_FILENO][0],
e937f6
-		    r != -1 ? strerror(errno) : "no data");
e937f6
-
e937f6
-		rv = ERRDATA;
e937f6
-		if (r == 0 &&
e937f6
-		    (r = sread(fdp[STDERR_FILENO][0], *newch, bytes_max, 0)) > 0)
e937f6
-		{
e937f6
+		if (r < 0) {
e937f6
+			rv = ERRDATA;
e937f6
+			DPRINTF("Read stdout failed %d (%s)\n", fdp[STDOUT_FILENO][0],
e937f6
+				strerror(errno));
e937f6
+			goto err;
e937f6
+		} else if ((r = sread(fdp[STDERR_FILENO][0], *newch, bytes_max, 0)) > 0){
e937f6
+			rv = ERRDATA;
e937f6
 			r = filter_error(*newch, r);
e937f6
 			break;
e937f6
 		}
e937f6
-		free(*newch);
e937f6
 		if  (r == 0)
e937f6
-			rv = makeerror(newch, n, "Read failed, %s",
e937f6
-			    strerror(errno));
e937f6
-		else
e937f6
-			rv = makeerror(newch, n, "No data");
e937f6
+			break;
e937f6
+		free(*newch);
e937f6
+		rv = ERRDATA;
e937f6
+		rv = makeerror(newch, n, "Read stderr failed, %s",
e937f6
+		    strerror(errno));
e937f6
 		goto err;
e937f6
 	}
e937f6
-
e937f6
 	*n = r;
e937f6
 	/* NUL terminate, as every buffer is handled here. */
e937f6
 	(*newch)[*n] = '\0';