forked from github/lukesmith-dwmblocks
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.
This commit is contained in:
parent
7892511501
commit
0c268f5fc9
@ -51,13 +51,13 @@ void remove_all(char *str, char to_remove) {
|
|||||||
char *read = str;
|
char *read = str;
|
||||||
char *write = str;
|
char *write = str;
|
||||||
while (*read) {
|
while (*read) {
|
||||||
if (*read == to_remove) {
|
if (*read != to_remove) {
|
||||||
read++;
|
|
||||||
*write = *read;
|
*write = *read;
|
||||||
|
++write;
|
||||||
}
|
}
|
||||||
read++;
|
++read;
|
||||||
write++;
|
|
||||||
}
|
}
|
||||||
|
*write = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
//opens process *cmd and stores output in *output
|
//opens process *cmd and stores output in *output
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user