Rever the strmem() addition and add a TODO element
strmem() was not very well thought out. The thing is the following: If the string contains a zero character, we want to match it, and not stop right there in place. The "real" solution is to use memmem() where needed and replace all functions that assume zero-terminated-strings from standard input, which could lead to early string-breakoffs. This requires a strict tracking of string lengths.master
parent
3396088666
commit
a88906b423
@ -1,23 +0,0 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
strmem(char *haystack, char *needle, size_t needlelen)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < needlelen; i++) {
|
||||
if (haystack[i] == '\0') {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
for (; haystack[i]; i++) {
|
||||
if (!(memcmp(haystack + i - needlelen, needle, needlelen))) {
|
||||
return (haystack + i - needlelen);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
Loading…
Reference in New Issue