From 6c48fe02c9be6a27407342904be1a8f1e7620d19 Mon Sep 17 00:00:00 2001 From: naddy <> Date: Wed, 11 Jul 2012 10:46:23 +0000 Subject: catch off-by-one errors in stpncpy(); ok guenther@ --- src/regress/lib/libc/stpncpy/stpncpy_test.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/regress/lib/libc/stpncpy/stpncpy_test.c (limited to 'src/regress/lib/libc/stpncpy/stpncpy_test.c') diff --git a/src/regress/lib/libc/stpncpy/stpncpy_test.c b/src/regress/lib/libc/stpncpy/stpncpy_test.c new file mode 100644 index 0000000000..63b7d25e53 --- /dev/null +++ b/src/regress/lib/libc/stpncpy/stpncpy_test.c @@ -0,0 +1,24 @@ +/* $OpenBSD: stpncpy_test.c,v 1.1 2012/07/11 10:46:23 naddy Exp $ */ + +/* + * Public domain, 2012, Christian Weisgerber + */ + +#include + +int main(void) +{ + char dst[8]; + char *src = "abcdef"; + + if (stpncpy(dst, src, 5) != dst + 5) + return 1; + if (stpncpy(dst, src, 6) != dst + 6) + return 1; + if (stpncpy(dst, src, 7) != dst + 6) + return 1; + if (stpncpy(dst, src, 8) != dst + 6) + return 1; + + return 0; +} -- cgit v1.2.3-55-g6feb