diff options
author | naddy <> | 2012-07-11 10:46:23 +0000 |
---|---|---|
committer | naddy <> | 2012-07-11 10:46:23 +0000 |
commit | 6c48fe02c9be6a27407342904be1a8f1e7620d19 (patch) | |
tree | 1a80b9d610bafa8678620c1004774a4bac9764a4 /src/regress/lib/libc/stpncpy/stpncpy_test.c | |
parent | e1fe34b2d493d33174e80455cc4c8962feae4333 (diff) | |
download | openbsd-6c48fe02c9be6a27407342904be1a8f1e7620d19.tar.gz openbsd-6c48fe02c9be6a27407342904be1a8f1e7620d19.tar.bz2 openbsd-6c48fe02c9be6a27407342904be1a8f1e7620d19.zip |
catch off-by-one errors in stpncpy(); ok guenther@
Diffstat (limited to 'src/regress/lib/libc/stpncpy/stpncpy_test.c')
-rw-r--r-- | src/regress/lib/libc/stpncpy/stpncpy_test.c | 24 |
1 files changed, 24 insertions, 0 deletions
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 @@ | |||
1 | /* $OpenBSD: stpncpy_test.c,v 1.1 2012/07/11 10:46:23 naddy Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Public domain, 2012, Christian Weisgerber <naddy@openbsd.org> | ||
5 | */ | ||
6 | |||
7 | #include <string.h> | ||
8 | |||
9 | int main(void) | ||
10 | { | ||
11 | char dst[8]; | ||
12 | char *src = "abcdef"; | ||
13 | |||
14 | if (stpncpy(dst, src, 5) != dst + 5) | ||
15 | return 1; | ||
16 | if (stpncpy(dst, src, 6) != dst + 6) | ||
17 | return 1; | ||
18 | if (stpncpy(dst, src, 7) != dst + 6) | ||
19 | return 1; | ||
20 | if (stpncpy(dst, src, 8) != dst + 6) | ||
21 | return 1; | ||
22 | |||
23 | return 0; | ||
24 | } | ||