diff options
author | Ivan Mikhnovich <ivan.mikhnovich@gmail.com> | 2021-05-23 19:24:42 +0300 |
---|---|---|
committer | Ivan Mikhnovich <ivan.mikhnovich@gmail.com> | 2021-05-23 19:24:42 +0300 |
commit | 0c268f5fc93fe3e96c543b771a5d6070d4c55985 (patch) | |
tree | 3423050eff8dda91c92aeeaf0c88ddba5b652e36 | |
parent | 78925115014bea2f4ead26f0dd7f833ff301ad11 (diff) | |
download | dwmblocks-0c268f5fc93fe3e96c543b771a5d6070d4c55985.tar.gz dwmblocks-0c268f5fc93fe3e96c543b771a5d6070d4c55985.tar.bz2 dwmblocks-0c268f5fc93fe3e96c543b771a5d6070d4c55985.zip |
Replace bughy implementation of function 'remove_all()'.
Counterexample for old implementation:
char str[] = "aaa";
remove_all(str, 'a');
printf("%s\n", str); // displays "a" if we're lucky,
//or crashes if we're not.
-rw-r--r-- | dwmblocks.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/dwmblocks.c b/dwmblocks.c index 18f58fb..563a07e 100644 --- a/dwmblocks.c +++ b/dwmblocks.c @@ -51,13 +51,13 @@ void remove_all(char *str, char to_remove) { char *read = str; char *write = str; while (*read) { - if (*read == to_remove) { - read++; + if (*read != to_remove) { *write = *read; + ++write; } - read++; - write++; + ++read; } + *write = '\0'; } //opens process *cmd and stores output in *output |