X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm_string.c;h=7950934d8b91fb75971cf6e8baae121491cb8cba;hb=2cb41f7db5b9f89113432d6b3daff4807ba8e5f2;hp=725fa17a40c87bc0f20e1c9520ee03285c39c792;hpb=94f67717b6461df514dc225ed84f03b44c44061b;p=palacios.git diff --git a/palacios/src/palacios/vmm_string.c b/palacios/src/palacios/vmm_string.c index 725fa17..7950934 100644 --- a/palacios/src/palacios/vmm_string.c +++ b/palacios/src/palacios/vmm_string.c @@ -71,6 +71,11 @@ void * memcpy(void * dst, const void * src, size_t n) { #ifdef V3_CONFIG_BUILT_IN_MEMMOVE void * memmove(void * dst, const void * src, size_t n) { uint8_t * tmp = (uint8_t *)V3_Malloc(n); + + if (!tmp) { + PrintError(info->vm_info, info, "Cannot allocate in built-in memmove\n"); + return NULL; + } memcpy(tmp, src, n); memcpy(dst, tmp, n); @@ -285,6 +290,12 @@ char * strdup(const char * s1) { char *ret; ret = V3_Malloc(strlen(s1) + 1); + + if (!ret) { + PrintError(VM_NONE, VCORE_NONE, "Cannot allocate in built-in strdup\n"); + return NULL; + } + strcpy(ret, s1); return ret; @@ -309,6 +320,7 @@ int atoi(const char * buf) { #endif +#ifdef V3_CONFIG_BUILT_IN_STRTOI int strtoi(const char * nptr, char ** endptr) { int ret = 0; char * buf = (char *)nptr; @@ -326,7 +338,9 @@ int strtoi(const char * nptr, char ** endptr) { return ret; } +#endif +#ifdef V3_CONFIG_BUILT_IN_ATOX uint64_t atox(const char * buf) { uint64_t ret = 0; @@ -348,7 +362,9 @@ uint64_t atox(const char * buf) { return ret; } +#endif +#ifdef V3_CONFIG_BUILT_IN_STRTOX uint64_t strtox(const char * nptr, char ** endptr) { uint64_t ret = 0; char * buf = (char *)nptr; @@ -376,7 +392,7 @@ uint64_t strtox(const char * nptr, char ** endptr) { return ret; } - +#endif #ifdef V3_CONFIG_BUILT_IN_STRCHR @@ -460,10 +476,14 @@ size_t strcspn(const char * s, const char * reject) { for (i = 0; i < reject_len; i++) { if (s[cnt] == reject[i]) { match = 1; - cnt++; break; } } + + if (!match) { + cnt++; + } + } return cnt; @@ -490,7 +510,7 @@ char *strstr(const char *haystack, const char *needle) } #endif - +#ifdef V3_CONFIG_BUILT_IN_STR_TOLOWER void str_tolower(char * s) { while (isalpha(*s)) { if (!islower(*s)) { @@ -499,8 +519,9 @@ void str_tolower(char * s) { s++; } } +#endif - +#ifdef V3_CONFIG_BUILT_IN_STR_TOUPPER void str_toupper(char * s) { while (isalpha(*s)) { if (!isupper(*s)) { @@ -509,3 +530,4 @@ void str_toupper(char * s) { s++; } } +#endif