diff options
| author | jvoisin | 2026-04-30 17:57:51 +0200 |
|---|---|---|
| committer | jvoisin | 2026-04-30 17:57:51 +0200 |
| commit | 7fecafe015505c0ebd47780050118ff789a9ae3f (patch) | |
| tree | d397318b8422b7898109760aa5c5eebf3560efad /tests | |
| parent | dfdf53df99c8f59e5e3a4296c455041bee96a88d (diff) | |
Fix a POSIX violation for swab
Diffstat (limited to '')
| -rw-r--r-- | tests/Makefile | 1 | ||||
| -rw-r--r-- | tests/test_swab_negative.c | 19 |
2 files changed, 20 insertions, 0 deletions
diff --git a/tests/Makefile b/tests/Makefile index fbfd178..9fc8287 100644 --- a/tests/Makefile +++ b/tests/Makefile | |||
| @@ -87,6 +87,7 @@ RUNTIME_TARGETS= \ | |||
| 87 | test_strncpy_static_write \ | 87 | test_strncpy_static_write \ |
| 88 | test_swab_dynamic_read \ | 88 | test_swab_dynamic_read \ |
| 89 | test_swab_dynamic_write \ | 89 | test_swab_dynamic_write \ |
| 90 | test_swab_negative \ | ||
| 90 | test_swab_static_read \ | 91 | test_swab_static_read \ |
| 91 | test_ttyname_r_dynamic \ | 92 | test_ttyname_r_dynamic \ |
| 92 | test_ttyname_r_static \ | 93 | test_ttyname_r_static \ |
diff --git a/tests/test_swab_negative.c b/tests/test_swab_negative.c new file mode 100644 index 0000000..f9c182b --- /dev/null +++ b/tests/test_swab_negative.c | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <unistd.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | char src[8] = "ABCDEFG"; | ||
| 7 | char dst[8] = {0}; | ||
| 8 | |||
| 9 | /* Positive case: normal swab works */ | ||
| 10 | swab(src, dst, 6); | ||
| 11 | puts(dst); | ||
| 12 | |||
| 13 | /* Negative n: POSIX says swab does nothing, must NOT trap */ | ||
| 14 | swab(src, dst, -1); | ||
| 15 | swab(src, dst, -100); | ||
| 16 | |||
| 17 | puts(dst); | ||
| 18 | return ret; | ||
| 19 | } | ||
