Skip to content

Commit

Permalink
Replace bughy implementation of function 'remove_all()'.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Ivan Mikhnovich committed May 23, 2021
1 parent 7892511 commit 0c268f5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions dwmblocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0c268f5

Please sign in to comment.