[LTP] [PATCH 17/19] Unify error handling in include/tst_safe_prw.h

Martin Doucha mdoucha@suse.cz
Mon Oct 26 17:47:54 CET 2020


- Pedantically check syscall return values

Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
 include/tst_safe_prw.h | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/include/tst_safe_prw.h b/include/tst_safe_prw.h
index 01a684da3..2e506cb41 100644
--- a/include/tst_safe_prw.h
+++ b/include/tst_safe_prw.h
@@ -15,8 +15,12 @@ static inline ssize_t safe_pread(const char *file, const int lineno,
 
 	if (rval == -1 || (len_strict && (size_t)rval != nbyte)) {
 		tst_brk_(file, lineno, TBROK | TERRNO,
-			 "pread(%d,%p,%zu,%lld) failed",
-			 fildes, buf, nbyte, (long long)offset);
+			"pread(%d,%p,%zu,%lld) failed",
+			fildes, buf, nbyte, (long long)offset);
+	} else if (rval < 0) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"Invalid pread(%d,%p,%zu,%lld) return value %zd",
+			fildes, buf, nbyte, (long long)offset, rval);
 	}
 
 	return rval;
@@ -34,8 +38,12 @@ static inline ssize_t safe_pwrite(const char *file, const int lineno,
 	rval = pwrite(fildes, buf, nbyte, offset);
 	if (rval == -1 || (len_strict && (size_t)rval != nbyte)) {
 		tst_brk_(file, lineno, TBROK | TERRNO,
-			 "pwrite(%d,%p,%zu,%lld) failed",
-			 fildes, buf, nbyte, (long long)offset);
+			"pwrite(%d,%p,%zu,%lld) failed",
+			fildes, buf, nbyte, (long long)offset);
+	} else if (rval < 0) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"Invalid pwrite(%d,%p,%zu,%lld) return value %zd",
+			fildes, buf, nbyte, (long long)offset, rval);
 	}
 
 	return rval;
-- 
2.28.0



More information about the ltp mailing list