public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2] safe_stdio: More checks for invalid function return values
@ 2026-04-17  8:47 Petr Vorel
  2026-04-17  8:47 ` [LTP] [PATCH 2/2] lib: Be pedantic on invalid comparison check Petr Vorel
  2026-04-17  9:24 ` [LTP] safe_stdio: More checks for invalid function return values linuxtestproject.agent
  0 siblings, 2 replies; 4+ messages in thread
From: Petr Vorel @ 2026-04-17  8:47 UTC (permalink / raw)
  To: ltp

LTP library pedantically check invalid function return values, add
missing ones.

Fixes: 56221c5bb2 ("lib: add safe macros for stream testing suite")
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 lib/safe_stdio.c | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/lib/safe_stdio.c b/lib/safe_stdio.c
index feb8a4b5c8..ed5bca0072 100644
--- a/lib/safe_stdio.c
+++ b/lib/safe_stdio.c
@@ -153,7 +153,11 @@ int safe_fseek(const char *file, const int lineno,
 
 	if (ret == -1) {
 		tst_brkm_(file, lineno, TBROK | TERRNO, NULL,
-			"fseek(%p, %ld, %d)", f, offset, whence);
+			"fseek(%p, %ld, %d) failed", f, offset, whence);
+	} else if (ret < 0) {
+		tst_brkm_(file, lineno, TBROK | TERRNO, NULL,
+			"Invalid fseek(%p, %ld, %d) return value %d",
+			f, offset, whence, ret);
 	}
 
 	return ret;
@@ -167,8 +171,12 @@ long safe_ftell(const char *file, const int lineno,
 	errno = 0;
 	ret = ftell(f);
 
-	if (ret == -1)
-		tst_brkm_(file, lineno, TBROK | TERRNO, NULL, "ftell(%p)", f);
+	if (ret == -1) {
+		tst_brkm_(file, lineno, TBROK | TERRNO, NULL, "ftell(%p) failed", f);
+	} else if (ret < 0) {
+		tst_brkm_(file, lineno, TBROK | TERRNO, NULL,
+				  "Invalid ftell(%p) return value %ld", f, ret);
+	}
 
 	return ret;
 }
@@ -181,8 +189,12 @@ int safe_fileno(const char *file, const int lineno,
 	errno = 0;
 	ret = fileno(f);
 
-	if (ret == -1)
-		tst_brkm_(file, lineno, TBROK | TERRNO, NULL, "fileno(%p)", f);
+	if (ret == -1) {
+		tst_brkm_(file, lineno, TBROK | TERRNO, NULL, "fileno(%p) failed", f);
+	} else if (ret < 0) {
+		tst_brkm_(file, lineno, TBROK | TERRNO, NULL,
+				  "Invalid fileno(%p) return value %d", f, ret);
+	}
 
 	return ret;
 }
@@ -195,8 +207,12 @@ int safe_fflush(const char *file, const int lineno,
 	errno = 0;
 	ret = fflush(f);
 
-	if (ret == EOF)
-		tst_brkm_(file, lineno, TBROK | TERRNO, NULL, "fflush(%p)", f);
+	if (ret == EOF) {
+		tst_brkm_(file, lineno, TBROK | TERRNO, NULL, "fflush(%p) failed", f);
+	} else if (!ret) {
+		tst_brkm_(file, lineno, TBROK | TERRNO, NULL,
+				  "Invalid fflush(%p) return value %d", f, ret);
+	}
 
 	return ret;
 }
-- 
2.53.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-04-17  9:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-17  8:47 [LTP] [PATCH 1/2] safe_stdio: More checks for invalid function return values Petr Vorel
2026-04-17  8:47 ` [LTP] [PATCH 2/2] lib: Be pedantic on invalid comparison check Petr Vorel
2026-04-17  9:24 ` [LTP] safe_stdio: More checks for invalid function return values linuxtestproject.agent
2026-04-17  9:42   ` Petr Vorel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox