[klibc] [PATCH 7/7] tests getoptlong check return value of snprintf()

maximilian attems max at stro.at
Tue Jul 5 11:06:32 PDT 2011


Signed-off-by: maximilian attems <max at stro.at>
---
 usr/klibc/tests/getoptlong.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/usr/klibc/tests/getoptlong.c b/usr/klibc/tests/getoptlong.c
index 6c019b7..8e969b8 100644
--- a/usr/klibc/tests/getoptlong.c
+++ b/usr/klibc/tests/getoptlong.c
@@ -27,7 +27,7 @@ int main(int argc, char *const *argv)
 	const char *showchar;
 	char one_char[] = "\'?\'";
 	char num_buf[16];
-	int c;
+	int c, len;
 	int longindex;
 
 	parser = getenv("GETOPTTEST");
@@ -43,7 +43,9 @@ int main(int argc, char *const *argv)
 			one_char[1] = c;
 			showchar = one_char;
 		} else {
-			snprintf(num_buf, sizeof num_buf, "%d", c);
+			len = snprintf(num_buf, sizeof num_buf, "%d", c);
+			if (len >= sizeof num_buf)
+				return 0;
 			showchar = num_buf;
 		}
 
-- 
1.7.5.4



More information about the klibc mailing list