Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 26 additions & 16 deletions libc/string/memchr.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#include "_string.h"
#include "../klee/include/klee/klee.h"

#ifdef WANT_WIDE
# define Wmemchr wmemchr
Expand All @@ -17,24 +18,33 @@ libc_hidden_proto(Wmemchr)

Wvoid *Wmemchr(const Wvoid *s, Wint c, size_t n)
{
register const Wuchar *r = (const Wuchar *) s;
#ifdef __BCC__
/* bcc can optimize the counter if it thinks it is a pointer... */
register const char *np = (const char *) n;
#else
# define np n
#endif
uint32_t ret;
klee_make_symbolic(&ret, sizeof(ret), "memchr_return_value");
klee_memchr(s, c, n, ret);
if (ret == n)
return NULL;
else
return (Wvoid *) (s + ret);

// register const Wuchar *r = (const Wuchar *) s;
// #ifdef __BCC__
// /* bcc can optimize the counter if it thinks it is a pointer... */
// register const char *np = (const char *) n;
// #else
// # define np n
// #endif

while (np) {
if (*r == ((Wuchar)c)) {
return (Wvoid *) r; /* silence the warning */
}
++r;
--np;
}
// while (np) {
// if (*r == ((Wuchar)c)) {
// return (Wvoid *) r; /* silence the warning */
// }
// ++r;
// --np;
// }

return NULL;
// return NULL;

}
#undef np
// #undef np

libc_hidden_def(Wmemchr)
57 changes: 32 additions & 25 deletions libc/string/memcmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,46 @@
*/

#include "_string.h"
#include "../klee/include/klee/klee.h"

#ifdef WANT_WIDE
# define Wmemcmp wmemcmp
#else
libc_hidden_proto(memcmp)
// #ifdef WANT_WIDE
// # define Wmemcmp wmemcmp
// #else
// libc_hidden_proto(memcmp)
# define Wmemcmp memcmp
#endif
// #endif

int Wmemcmp(const Wvoid *s1, const Wvoid *s2, size_t n)
{
register const Wuchar *r1 = (const Wuchar *) s1;
register const Wuchar *r2 = (const Wuchar *) s2;

#ifdef WANT_WIDE
while (n && (*r1 == *r2)) {
++r1;
++r2;
--n;
}
uint32_t ret;
klee_make_symbolic(&ret, sizeof(ret), "memcmp_return_value");
klee_memcmp(s1, s2, n, ret);
return ret;

return (n == 0) ? 0 : ((*r1 < *r2) ? -1 : 1);
#else
int r = 0;
// register const Wuchar *r1 = (const Wuchar *) s1;
// register const Wuchar *r2 = (const Wuchar *) s2;

while (n-- && ((r = ((int)(*r1++)) - *r2++) == 0));
// #ifdef WANT_WIDE
// while (n && (*r1 == *r2)) {
// ++r1;
// ++r2;
// --n;
// }

return r;
#endif
// return (n == 0) ? 0 : ((*r1 < *r2) ? -1 : 1);
// #else
// int r = 0;

// while (n-- && ((r = ((int)(*r1++)) - *r2++) == 0));

// return r;
// #endif
}

#ifndef WANT_WIDE
libc_hidden_def(memcmp)
# ifdef __UCLIBC_SUSV3_LEGACY__
strong_alias(memcmp,bcmp)
# endif
#endif
// #ifndef WANT_WIDE
// libc_hidden_def(memcmp)
// # ifdef __UCLIBC_SUSV3_LEGACY__
// strong_alias(memcmp,bcmp)
// # endif
// #endif
49 changes: 27 additions & 22 deletions libc/string/memmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,42 @@
*/

#include "_string.h"
#include "../klee/include/klee/klee.h"

#ifdef __USE_GNU
libc_hidden_proto(memmem)
void *memmem(const void *haystack, size_t haystacklen,
const void *needle, size_t needlelen)
{
register const char *ph;
register const char *pn;
const char *plast;
size_t n;
{
uint32_t ret;
klee_make_symbolic(&ret, sizeof(ret), "memmem_return_value");
klee_memmem(haystack, needle, haystacklen, needlelen, ret);
return (char *)(haystack + ret);
// register const char *ph;
// register const char *pn;
// const char *plast;
// size_t n;

if (needlelen == 0) {
return (void *) haystack;
}
// if (needlelen == 0) {
// return (void *) haystack;
// }

if (haystacklen >= needlelen) {
ph = (const char *) haystack;
pn = (const char *) needle;
plast = ph + (haystacklen - needlelen);
// if (haystacklen >= needlelen) {
// ph = (const char *) haystack;
// pn = (const char *) needle;
// plast = ph + (haystacklen - needlelen);

do {
n = 0;
while (ph[n] == pn[n]) {
if (++n == needlelen) {
return (void *) ph;
}
}
} while (++ph <= plast);
}
// do {
// n = 0;
// while (ph[n] == pn[n]) {
// if (++n == needlelen) {
// return (void *) ph;
// }
// }
// } while (++ph <= plast);
// }

return NULL;
// return NULL;
}
libc_hidden_def(memmem)
#endif
42 changes: 26 additions & 16 deletions libc/string/memrchr.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,43 @@
*/

#include "_string.h"
#include "../klee/include/klee/klee.h"

#ifdef __USE_GNU

libc_hidden_proto(memrchr)

void *memrchr(const void *s, int c, size_t n)
{
register const unsigned char *r;
#ifdef __BCC__
/* bcc can optimize the counter if it thinks it is a pointer... */
register const char *np = (const char *) n;
#else
#define np n
#endif
uint32_t ret;
klee_make_symbolic(&ret, sizeof(ret), "memrchr_return_value");
klee_memrchr(s, c, n, ret);
if (ret == n)
return NULL;
else
return s + ret;


// register const unsigned char *r;
// #ifdef __BCC__
// /* bcc can optimize the counter if it thinks it is a pointer... */
// register const char *np = (const char *) n;
// #else
// #define np n
// #endif

r = ((unsigned char *)s) + ((size_t) np);
// r = ((unsigned char *)s) + ((size_t) np);

while (np) {
if (*--r == ((unsigned char)c)) {
return (void *) r; /* silence the warning */
}
--np;
}
// while (np) {
// if (*--r == ((unsigned char)c)) {
// return (void *) r; /* silence the warning */
// }
// --np;
// }

return NULL;
// return NULL;
}
#undef np
// #undef np

libc_hidden_def(memrchr)
#endif
21 changes: 15 additions & 6 deletions libc/string/strchr.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#include "_string.h"
#include "../klee/include/klee/klee.h"

#ifdef WANT_WIDE
# define Wstrchr wcschr
Expand All @@ -17,13 +18,21 @@ libc_hidden_proto(Wstrchr)

Wchar *Wstrchr(register const Wchar *s, Wint c)
{
do {
if (*s == ((Wchar)c)) {
return (Wchar *) s; /* silence the warning */
}
} while (*s++);
uint32_t ret;
klee_make_symbolic(&ret, sizeof(ret), "strchr_return_value");
int n = strlen(s);
klee_strchr(s, c, n, ret);
if (ret == n)
return NULL;
else
return (Wchar *)(s + ret);
// do {
// if (*s == ((Wchar)c)) {
// return (Wchar *) s; /* silence the warning */
// }
// } while (*s++);

return NULL;
// return NULL;
}
libc_hidden_def(Wstrchr)

Expand Down
35 changes: 21 additions & 14 deletions libc/string/strcmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#include "_string.h"
#include "../klee/include/klee/klee.h"

#ifdef WANT_WIDE
# define Wstrcmp wcscmp
Expand All @@ -19,23 +20,29 @@ libc_hidden_proto(Wstrcmp)

int Wstrcmp(register const Wchar *s1, register const Wchar *s2)
{
#ifdef WANT_WIDE
while (*((Wuchar *)s1) == *((Wuchar *)s2)) {
if (!*s1++) {
return 0;
}
++s2;
}
int s1_len = strlen(s1);
int s2_len = strlen(s2);
uint32_t ret;
klee_make_symbolic(&ret, sizeof(ret), "strcmp_return_value");
klee_strcmp(s1, s2, s1_len, s2_len, ret);
return (int)ret;
// #ifdef WANT_WIDE
// while (*((Wuchar *)s1) == *((Wuchar *)s2)) {
// if (!*s1++) {
// return 0;
// }
// ++s2;
// }

return (*((Wuchar *)s1) < *((Wuchar *)s2)) ? -1 : 1;
#else
int r;
// return (*((Wuchar *)s1) < *((Wuchar *)s2)) ? -1 : 1;
// #else
// int r;

while (((r = ((int)(*((Wuchar *)s1))) - *((Wuchar *)s2++))
== 0) && *s1++);
// while (((r = ((int)(*((Wuchar *)s1))) - *((Wuchar *)s2++))
// == 0) && *s1++);

return r;
#endif
// return r;
// #endif
}
libc_hidden_def(Wstrcmp)

Expand Down
11 changes: 8 additions & 3 deletions libc/string/strlen.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#include "_string.h"
#include "../klee/include/klee/klee.h"

#ifdef WANT_WIDE
# define Wstrlen wcslen
Expand All @@ -17,10 +18,14 @@ libc_hidden_proto(Wstrlen)

size_t Wstrlen(const Wchar *s)
{
register const Wchar *p;
int len_s;
klee_make_symbolic(&len_s, sizeof(len_s), "strlen_return_value");
klee_strlen(s, len_s);
return len_s;
// register const Wchar *p;

for (p=s ; *p ; p++);
// for (p=s ; *p ; p++);

return p - s;
// return p - s;
}
libc_hidden_def(Wstrlen)
Loading