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.
This commit is contained in:
parent
3396088666
commit
a88906b423
1
Makefile
1
Makefile
|
@ -75,7 +75,6 @@ LIBUTILSRC =\
|
||||||
libutil/strcasestr.c\
|
libutil/strcasestr.c\
|
||||||
libutil/strlcat.c\
|
libutil/strlcat.c\
|
||||||
libutil/strlcpy.c\
|
libutil/strlcpy.c\
|
||||||
libutil/strmem.c\
|
|
||||||
libutil/strsep.c\
|
libutil/strsep.c\
|
||||||
libutil/strtonum.c\
|
libutil/strtonum.c\
|
||||||
libutil/unescape.c
|
libutil/unescape.c
|
||||||
|
|
3
TODO
3
TODO
|
@ -15,5 +15,8 @@ If you are looking for some work to do on sbase, another option is to
|
||||||
pick a utility from the list in the README which has missing flags or
|
pick a utility from the list in the README which has missing flags or
|
||||||
features noted.
|
features noted.
|
||||||
|
|
||||||
|
What also needs to be implemented is the capability of the tools to
|
||||||
|
handle data with NUL-bytes in it.
|
||||||
|
|
||||||
[0] http://landley.net/toybox/roadmap.html
|
[0] http://landley.net/toybox/roadmap.html
|
||||||
[1] http://git.suckless.org/ubase/
|
[1] http://git.suckless.org/ubase/
|
||||||
|
|
2
join.c
2
join.c
|
@ -225,7 +225,7 @@ makeline(char *s, size_t len)
|
||||||
beg = sp;
|
beg = sp;
|
||||||
|
|
||||||
if (sep) {
|
if (sep) {
|
||||||
if (!(end = strmem(sp, sep, seplen)))
|
if (!(end = utfutf(sp, sep)))
|
||||||
eol = 1;
|
eol = 1;
|
||||||
|
|
||||||
if (!eol) {
|
if (!eol) {
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
2
util.h
2
util.h
|
@ -58,8 +58,6 @@ size_t estrlcpy(char *, const char *, size_t);
|
||||||
#undef strsep
|
#undef strsep
|
||||||
char *strsep(char **, const char *);
|
char *strsep(char **, const char *);
|
||||||
|
|
||||||
char *strmem(char *, char *, size_t);
|
|
||||||
|
|
||||||
/* regex */
|
/* regex */
|
||||||
int enregcomp(int, regex_t *, const char *, int);
|
int enregcomp(int, regex_t *, const char *, int);
|
||||||
int eregcomp(regex_t *, const char *, int);
|
int eregcomp(regex_t *, const char *, int);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user