diff options
| author | Andrew Clayton <ac@sigsegv.uk> | 2025-03-07 00:07:25 +0000 |
|---|---|---|
| committer | Andrew Clayton <ac@sigsegv.uk> | 2025-03-07 00:07:25 +0000 |
| commit | 891c8fbd0c825b6716225e778a8f013afb858d57 (patch) | |
| tree | 2b98bc47b6db420b10017ca4c0100e6abacd8cc8 /examples/strsep-invalid-free.c | |
| download | common_c_mistakes-master.tar.gz common_c_mistakes-master.tar.bz2 | |
Signed-off-by: Andrew Clayton <ac@sigsegv.uk>
Diffstat (limited to 'examples/strsep-invalid-free.c')
| -rw-r--r-- | examples/strsep-invalid-free.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/examples/strsep-invalid-free.c b/examples/strsep-invalid-free.c new file mode 100644 index 0000000..e01685d --- /dev/null +++ b/examples/strsep-invalid-free.c @@ -0,0 +1,16 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +int main(void) +{ + char *str = strdup("Hello World"), *tkn; + + printf("str [%s@%p]\n", str, str); + tkn = strsep(&str, " "); + printf("tkn [%s] str [%s@%p]\n", tkn, str, str); + + free(str); + + return 0; +} |
