libsheepy

C lib for handling text files, strings and json like data structure with an object oriented system
git clone https://spartatek.se/git/libsheepy.git
Log | Files | Refs | README | LICENSE

commit 642c24b1baca7dde1c16437ca21f27704245286f
parent cbfaffb72443c0af6d7e6a48b5f6800ccb746add
Author: Remy Noulin <loader2x@gmail.com>
Date:   Mon,  7 Jun 2021 22:21:22 +0200

fix problems found with facebook infer static analyzer

Mostly NULL dereference or resource leak after OOM
and some dead stores

release/libsheepy.c                 | 158 +++++++++++++++++++++++++++++++++---
release/libsheepy.h                 |   2 +-
src/json/libsheepyCClassTemplate.c  |   3 +
src/json/libsheepyCSmallArray.c     |  68 +++++++++++++++-
src/json/libsheepyCSmallBool.c      |   3 +
src/json/libsheepyCSmallBytes.c     |   3 +
src/json/libsheepyCSmallContainer.c |   3 +
src/json/libsheepyCSmallDict.c      |  26 +++++-
src/json/libsheepyCSmallDouble.c    |   3 +
src/json/libsheepyCSmallInt.c       |   3 +
src/json/libsheepyCSmallJson.c      |  42 +++++++++-
src/json/libsheepyCSmallString.c    |  22 +++++
src/json/libsheepyCUndefined.c      |   3 +
src/json/libsheepyObject.c          |  32 ++++++--
src/libsheepy.c                     | 158 +++++++++++++++++++++++++++++++++---
src/libsheepy.h                     |   2 +-
16 files changed, 494 insertions(+), 37 deletions(-)

Diffstat:
Mrelease/libsheepy.c | 158++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
Mrelease/libsheepy.h | 2+-
Msrc/json/libsheepyCClassTemplate.c | 3+++
Msrc/json/libsheepyCSmallArray.c | 68+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
Msrc/json/libsheepyCSmallBool.c | 3+++
Msrc/json/libsheepyCSmallBytes.c | 3+++
Msrc/json/libsheepyCSmallContainer.c | 3+++
Msrc/json/libsheepyCSmallDict.c | 26+++++++++++++++++++++++++-
Msrc/json/libsheepyCSmallDouble.c | 3+++
Msrc/json/libsheepyCSmallInt.c | 3+++
Msrc/json/libsheepyCSmallJson.c | 42+++++++++++++++++++++++++++++++++++++++---
Msrc/json/libsheepyCSmallString.c | 22++++++++++++++++++++++
Msrc/json/libsheepyCUndefined.c | 3+++
Msrc/json/libsheepyObject.c | 32++++++++++++++++++++++++--------
Msrc/libsheepy.c | 158++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
Msrc/libsheepy.h | 2+-
16 files changed, 494 insertions(+), 37 deletions(-)

diff --git a/release/libsheepy.c b/release/libsheepy.c @@ -3869,6 +3869,9 @@ char *bLRelPath(char *dest, size_t destSize, char *path, const char *start) { char *getHomePath(void) { struct passwd *pw = getpwuid(getuid());; + if (!pw) { + return(NULL); + } return(strdup(pw->pw_dir)); } @@ -3883,6 +3886,9 @@ char *getHomePath(void) { char *bGetHomePath(char *path) { struct passwd *pw = getpwuid(getuid());; + if (!pw) { + return(NULL); + } strcpy(path, pw->pw_dir); return(path); } @@ -3900,6 +3906,9 @@ char *bGetHomePath(char *path) { char *bLGetHomePath(char *path, size_t pathSize) { struct passwd *pw = getpwuid(getuid());; + if (!pw) { + return(NULL); + } if (strlen(pw->pw_dir)+1 > pathSize) { return(NULL); } @@ -3916,6 +3925,9 @@ char *bLGetHomePath(char *path, size_t pathSize) { const char *getCHomePath(void) { struct passwd *pw = getpwuid(getuid());; + if (!pw) { + return(NULL); + } return(pw->pw_dir); } @@ -5457,7 +5469,6 @@ int rmADir(const char *dirPath) { * 0 when src or dst are NULL or empty */ int copy(const char* src, const char* dst) { - int r = 1;; // sanity checks if (!src || !dst || isBlankS(src) || isBlankS(dst)) { @@ -5506,7 +5517,7 @@ int copy(const char* src, const char* dst) { } } - r = copyADir(src, dPath, ""); + int r = copyADir(src, dPath, ""); // copy permissions struct stat st; @@ -6208,11 +6219,13 @@ UNUSED local char *shGetpass(void) { /* Turn echoing off and fail if we can’t. */ if (tcgetattr (fileno (stream), &old) != 0) { + fclose(stream); return(NULL); } new = old; new.c_lflag &= ~ECHO; if (tcsetattr (fileno (stream), TCSAFLUSH, &new) != 0) { + fclose(stream); return(NULL); } @@ -6240,7 +6253,11 @@ char *readPasswordS(void) { #if (__TERMUX__ || __HAIKU__ || unitTest) char *r = shGetpass(); #else + // TODO getpass is obsolete, see man for getpass char *p = getpass(""); + if (!p) { + return(NULL); + } char *r = strdup(p); memset(p, 0, strlen(p)); #endif @@ -9856,6 +9873,9 @@ char *upperS(const char *string) { } r = strdup(string); + if (!r) { + return(NULL); + } // upper case size_t i = 0; @@ -9934,6 +9954,9 @@ char *lowerS(const char *string) { } r = strdup(string); + if (!r) { + return(NULL); + } // lower case size_t i = 0; @@ -10033,6 +10056,9 @@ char *trimS(const char *string) { // copy range to new string len = end - string + 2; r = MALLOC(len); + if (!r) { + return(NULL); + } r = strncpy(r, string, len - 1); r[len - 1] = 0; return(r); @@ -10081,6 +10107,9 @@ char *iTrimS(char **string) { // copy range to new string len = end - workingS + 2; r = MALLOC(len); + if (!r) { + return(NULL); + } r = strncpy(r, workingS, len - 1); r[len - 1] = 0; free(*string); @@ -10130,6 +10159,9 @@ char *bTrimS(char *string) { // copy range to new string len = end - workingS + 2; r = MALLOC(len); + if (!r) { + return(NULL); + } r = strncpy(r, workingS, len - 1); r[len - 1] = 0; strcpy(string, r); @@ -10196,6 +10228,9 @@ char *iLTrimS(char **string) { } r = strdup(workingS); + if (!r) { + return(NULL); + } free(*string); *string = r;; return(r); @@ -10260,6 +10295,9 @@ char *rTrimS(const char *string) { // copy range to new string len = end - string + 2; r = MALLOC(len); + if (!r) { + return(NULL); + } r = strncpy(r, string, len - 1); r[len - 1] = 0; return(r); @@ -10627,6 +10665,9 @@ char *repeatS(const char *string, size_t count) { size_t len = slen * count; r = MALLOC(len+1);; + if (!r) { + return(NULL); + } strcpy(r, string); count--; @@ -10667,6 +10708,9 @@ char *iRepeatS(char **string, size_t count) { size_t len = slen * count; r = MALLOC(len+1);; + if (!r) { + return(NULL); + } strcpy(r, *string); count--; @@ -11412,6 +11456,9 @@ char *bEllipsisEndS(char *dest, const char *string, size_t targetLength, const c // ellipsisString is longer than targetLength ellip = sliceS(ellipsisString, 0, targetLength); } + if (!ellip) { + return(NULL); + } strncpy(dest, ellip, targetLength+1); free(ellip); } @@ -11607,6 +11654,9 @@ char *bEllipsisEndCharS(char *dest, const char *string, size_t targetLength, cha // truncate string char *ellip; ellip = sliceS(string, 0, targetLength - strlen(ellipsisString)); + if (!ellip) { + return(NULL); + } iAppendS(&ellip, ellipsisString); strncpy(dest, ellip, targetLength+1); free(ellip); @@ -11708,6 +11758,9 @@ char *padStartS(const char *string, size_t targetLength, const char *padString) targetLength -= strlen(string); char *pads = strdup(padString);; + if (!pads) { + return(NULL); + } if (targetLength > strlen(padString)) { iRepeatS(&pads, targetLength/strlen(padString)+1); } @@ -11813,6 +11866,9 @@ char *bPadStartS(char *dest, const char *string, size_t targetLength, const char targetLength -= strlen(string); char *pads = strdup(padString);; + if (!pads) { + return(NULL); + } if (targetLength > strlen(padString)) { iRepeatS(&pads, targetLength/strlen(padString)+1); } @@ -11821,6 +11877,9 @@ char *bPadStartS(char *dest, const char *string, size_t targetLength, const char char *r = appendS(pads, string); free(pads); + if (!r) { + return(NULL); + } strcpy(dest, r); free(r); @@ -11869,6 +11928,9 @@ char *bLPadStartS(char *dest, size_t destSize, const char *string, size_t target targetLength -= strlen(string); char *pads = strdup(padString);; + if (!pads) { + return(NULL); + } if (targetLength > strlen(padString)) { iRepeatS(&pads, targetLength/strlen(padString)+1); } @@ -11877,6 +11939,9 @@ char *bLPadStartS(char *dest, size_t destSize, const char *string, size_t target char *r = appendS(pads, string); free(pads); + if (!r) { + return(NULL); + } strLCpy(dest, destSize, r); free(r); @@ -11917,6 +11982,9 @@ char *padStartCharS(const char *string, size_t targetLength, char padChar) { charToS(padString, padChar); char *pads = strdup(padString);; + if (!pads) { + return(NULL); + } if (targetLength > strlen(padString)) { iRepeatS(&pads, targetLength/strlen(padString)+1); } @@ -12009,6 +12077,9 @@ char *bPadStartCharS(char *dest, const char *string, size_t targetLength, char p charToS(padString, padChar); char *pads = strdup(padString);; + if (!pads) { + return(NULL); + } if (targetLength > strlen(padString)) { iRepeatS(&pads, targetLength/strlen(padString)+1); } @@ -12017,6 +12088,9 @@ char *bPadStartCharS(char *dest, const char *string, size_t targetLength, char p char *r = appendS(pads, string); free(pads); + if (!r) { + return(NULL); + } strcpy(dest, r); free(r); @@ -12058,6 +12132,9 @@ char *bLPadStartCharS(char *dest, size_t destSize, const char *string, size_t ta charToS(padString, padChar); char *pads = strdup(padString);; + if (!pads) { + return(NULL); + } if (targetLength > strlen(padString)) { iRepeatS(&pads, targetLength/strlen(padString)+1); } @@ -12066,6 +12143,9 @@ char *bLPadStartCharS(char *dest, size_t destSize, const char *string, size_t ta char *r = appendS(pads, string); free(pads); + if (!r) { + return(NULL); + } strLCpy(dest, destSize, r); free(r); @@ -12140,6 +12220,9 @@ char *padEndS(const char *string, size_t targetLength, const char *padString) { targetLength -= strlen(string); char *pads = strdup(padString);; + if (!pads) { + return(NULL); + } if (targetLength > strlen(padString)) { iRepeatS(&pads, targetLength/strlen(padString)+1); } @@ -12193,6 +12276,9 @@ char *iPadEndS(char **string, size_t targetLength, const char *padString) { targetLength -= strlen(*string); char *pads = strdup(padString);; + if (!pads) { + return(NULL); + } if (targetLength > strlen(padString)) { iRepeatS(&pads, targetLength/strlen(padString)+1); } @@ -12246,6 +12332,9 @@ char *bPadEndS(char *dest, const char *string, size_t targetLength, const char * targetLength -= strlen(string); char *pads = strdup(padString);; + if (!pads) { + return(NULL); + } if (targetLength > strlen(padString)) { iRepeatS(&pads, targetLength/strlen(padString)+1); } @@ -12254,6 +12343,9 @@ char *bPadEndS(char *dest, const char *string, size_t targetLength, const char * char *r = appendS(string, pads); free(pads); + if (!r) { + return(NULL); + } strcpy(dest, r); free(r); @@ -12302,6 +12394,9 @@ char *bLPadEndS(char *dest, size_t destSize, const char *string, size_t targetLe targetLength -= strlen(string); char *pads = strdup(padString);; + if (!pads) { + return(NULL); + } if (targetLength > strlen(padString)) { iRepeatS(&pads, targetLength/strlen(padString)+1); } @@ -12310,6 +12405,9 @@ char *bLPadEndS(char *dest, size_t destSize, const char *string, size_t targetLe char *r = appendS(string, pads); free(pads); + if (!r) { + return(NULL); + } strLCpy(dest, destSize, r); free(r); @@ -12350,6 +12448,9 @@ char *padEndCharS(const char *string, size_t targetLength, char padChar) { charToS(padString, padChar); char *pads = strdup(padString);; + if (!pads) { + return(NULL); + } if (targetLength > strlen(padString)) { iRepeatS(&pads, targetLength/strlen(padString)+1); } @@ -12395,6 +12496,9 @@ char *iPadEndCharS(char **string, size_t targetLength, char padChar) { charToS(padString, padChar); char *pads = strdup(padString);; + if (!pads) { + return(NULL); + } if (targetLength > strlen(padString)) { iRepeatS(&pads, targetLength/strlen(padString)+1); } @@ -12441,6 +12545,9 @@ char *bPadEndCharS(char *dest, const char *string, size_t targetLength, char pad charToS(padString, padChar); char *pads = strdup(padString);; + if (!pads) { + return(NULL); + } if (targetLength > strlen(padString)) { iRepeatS(&pads, targetLength/strlen(padString)+1); } @@ -12449,6 +12556,9 @@ char *bPadEndCharS(char *dest, const char *string, size_t targetLength, char pad char *r = appendS(string, pads); free(pads); + if (!r) { + return(NULL); + } strcpy(dest, r); free(r); @@ -12490,6 +12600,9 @@ char *bLPadEndCharS(char *dest, size_t destSize, const char *string, size_t targ charToS(padString, padChar); char *pads = strdup(padString);; + if (!pads) { + return(NULL); + } if (targetLength > strlen(padString)) { iRepeatS(&pads, targetLength/strlen(padString)+1); } @@ -12498,6 +12611,9 @@ char *bLPadEndCharS(char *dest, size_t destSize, const char *string, size_t targ char *r = appendS(string, pads); free(pads); + if (!r) { + return(NULL); + } strLCpy(dest, destSize, r); free(r); @@ -12630,6 +12746,9 @@ char *swapS(char *string, int64_t index1, int64_t index2) { } char *r = strdup(string); + if (!r) { + return(NULL); + } char tmp = r[index1]; r[index1] = r[index2]; @@ -14921,13 +15040,11 @@ bool isCodeUTF8(const char *code) { // ASCII // use bytes[0] <= 0x7F to allow ASCII control characters if (bytes[0] == 0x09 || bytes[0] == 0x0A || bytes[0] == 0x0D || (0x20 <= bytes[0] && bytes[0] <= 0x7E)) { - bytes += 1; return(true); } // non-overlong 2-byte if ((0xC2 <= bytes[0] && bytes[0] <= 0xDF) && (0x80 <= bytes[1] && bytes[1] <= 0xBF)) { - bytes += 2; return(true); } @@ -14935,7 +15052,6 @@ bool isCodeUTF8(const char *code) { // straight 3-byte // excluding surrogates if ((bytes[0] == 0xE0 && (0xA0 <= bytes[1] && bytes[1] <= 0xBF) && (0x80 <= bytes[2] && bytes[2] <= 0xBF)) || (((0xE1 <= bytes[0] && bytes[0] <= 0xEC) || bytes[0] == 0xEE || bytes[0] == 0xEF) && (0x80 <= bytes[1] && bytes[1] <= 0xBF) && (0x80 <= bytes[2] && bytes[2] <= 0xBF)) || (bytes[0] == 0xED && (0x80 <= bytes[1] && bytes[1] <= 0x9F) && (0x80 <= bytes[2] && bytes[2] <= 0xBF))) { - bytes += 3; return(true); } @@ -14943,7 +15059,6 @@ bool isCodeUTF8(const char *code) { // planes 4-15 // plane 16 if ((bytes[0] == 0xF0 && (0x90 <= bytes[1] && bytes[1] <= 0xBF) && (0x80 <= bytes[2] && bytes[2] <= 0xBF) && (0x80 <= bytes[3] && bytes[3] <= 0xBF)) || ((0xF1 <= bytes[0] && bytes[0] <= 0xF3) && (0x80 <= bytes[1] && bytes[1] <= 0xBF) && (0x80 <= bytes[2] && bytes[2] <= 0xBF) && (0x80 <= bytes[3] && bytes[3] <= 0xBF)) || (bytes[0] == 0xF4 && (0x80 <= bytes[1] && bytes[1] <= 0x8F) && (0x80 <= bytes[2] && bytes[2] <= 0xBF) && (0x80 <= bytes[3] && bytes[3] <= 0xBF))) { - bytes += 4; return(true); } @@ -46959,6 +47074,9 @@ char *uniqUTF8(const char *string, const char *code) { } r = strdup(string); + if (!r) { + return(NULL); + } len = lenUTF8(string); if (len < 2) { @@ -48281,14 +48399,10 @@ char *bLDelUTF8(char *string, size_t stringSize, int64_t start, int64_t end) { char *endp = bLIdx2PtrUTF8(string, stringSize, end); size_t starto = (size_t)(startp-string); - size_t endo = (size_t)(endp-string); if (starto >= stringSize) { starto = stringSize; } - if (endo > stringSize) { - endo = stringSize; - } if (start == 0) { starto = 0; } @@ -49073,6 +49187,9 @@ char **listPushS(char ***list, const char *s) { if (!*list) { *list = MALLOC(2 * sizeof(char *)); + if (!*list) { + return(NULL); + } (*list)[0] = strdup(s); (*list)[1] = NULL; } @@ -49125,6 +49242,9 @@ char **iListPushS(char ***list, char *s) { if (!*list) { *list = MALLOC(2 * sizeof(char *)); + if (!*list) { + return(NULL); + } (*list)[0] = s; (*list)[1] = NULL; } @@ -49204,6 +49324,9 @@ char **listPrependS(char ***list, const char *s) { if (!*list) { *list = MALLOC(2 * sizeof(char *)); + if (!*list) { + return(NULL); + } (*list)[0] = strdup(s); (*list)[1] = NULL; } @@ -49260,6 +49383,9 @@ char **iListPrependS(char ***list, char *s) { if (!*list) { *list = MALLOC(2 * sizeof(char *)); + if (!*list) { + return(NULL); + } (*list)[0] = s; (*list)[1] = NULL; } @@ -50461,6 +50587,9 @@ char **iListAppendS(char ***list1, char **list2) { // copy list2 len2 = listLengthS(list2); *list1 = MALLOC((len2+1) * sizeof(char *)); + if (!*list1) { + return(NULL); + } int j = 0; while (list2[j]) { (*list1)[j] = list2[j]; @@ -53546,6 +53675,9 @@ void **listPush(void ***list, void *s) { if (!*list) { *list = MALLOC(2 * sizeof(void *)); + if (!*list) { + return(NULL); + } (*list)[0] = s; (*list)[1] = NULL; } @@ -53627,6 +53759,9 @@ void **listPrepend(void ***list, void *s) { if (!*list) { *list = MALLOC(2 * sizeof(void *)); + if (!*list) { + return(NULL); + } (*list)[0] = s; (*list)[1] = NULL; } @@ -53995,6 +54130,9 @@ void **listAppend(void ***list1, void **list2) { // copy list2 len2 = listLength(list2); *list1 = MALLOC((len2+1) * sizeof(void *)); + if (!*list1) { + return(NULL); + } int j = 0; while (list2[j]) { (*list1)[j] = list2[j]; diff --git a/release/libsheepy.h b/release/libsheepy.h @@ -98,7 +98,7 @@ // version accoring to the version package: Release.Major.minor.patch // https://noulin.net/version/file/README.md.html -#define LIBSHEEPY_VERSION "2.2.5.1" +#define LIBSHEEPY_VERSION "2.2.5.2" #ifndef SH_PREFIX #define SH_PREFIX(NAME) NAME diff --git a/src/json/libsheepyCClassTemplate.c b/src/json/libsheepyCClassTemplate.c @@ -54,9 +54,12 @@ void initiateAllocateClassTemplate(classTemplatet **self) { (*self) = malloc(sizeof(classTemplatet)); if (*self) { initiateClassTemplate(*self); + if (!(*self)->f) { + finishClassTemplate(self); } } } + } void finalizeClassTemplate(void) { diff --git a/src/json/libsheepyCSmallArray.c b/src/json/libsheepyCSmallArray.c @@ -1400,9 +1400,12 @@ void initiateAllocateSmallArray(smallArrayt **self) { // recycleContainers if (*self) { initiateSmallArray(*self); + if (!(*self)->f) { + finishSmallArray(self); } } } + } smallArrayt* allocSmallArray(void) { smallArrayt *r = NULL; @@ -1701,6 +1704,9 @@ internal smallArrayt* pushSmallArray(smallArrayt *self, baset *value) { return(NULL); } o = toSmallt(value);; + if (!o) { + return(NULL); + } sArrayPushTiny(&(self->a), o); return(self); } @@ -1956,6 +1962,9 @@ internal smallArrayt* pushNFreeSmallArray(smallArrayt *self, baset *value) { return(NULL); } o = toSmallt(value);; + if (!o) { + return(NULL); + } sArrayPushTiny(&(self->a), o); if (!(o->type == CONTAINER && (((sContainert*)o)->dataType == SH_DT_BASET))) { @@ -2644,6 +2653,9 @@ internal smallArrayt* prependSmallArray(smallArrayt *self, baset *value) { } o = toSmallt(value);; + if (!o) { + return(NULL); + } sArrayPrependTiny(&(self->a), o); return(self); } @@ -2899,6 +2911,9 @@ internal smallArrayt* prependNFreeSmallArray(smallArrayt *self, baset *value) { } o = toSmallt(value);; + if (!o) { + return(NULL); + } sArrayPrependTiny(&(self->a), o); if (!(o->type == CONTAINER && (((sContainert*)o)->dataType == SH_DT_BASET))) { @@ -4812,6 +4827,9 @@ internal smallArrayt* insertSmallJsonSmallArray(smallArrayt *self, int64_t index } createSmallArray(a); + if (!a.f) { + return(NULL); + } setsoO(&a, (sArrayt*)getsoO(toInsert)); return(insertSmallArray(self, index, &a)); } @@ -4875,6 +4893,10 @@ internal smallArrayt* injectSmallArray(smallArrayt *self, int64_t index, baset * } smallt *o = toSmallt(toInject); + if (!o) { + sFree((smallt*)a); + return(NULL); + } if (index == 0) { // inject at beginning @@ -5620,6 +5642,10 @@ internal smallArrayt* injectNFreeSmallArray(smallArrayt *self, int64_t index, ba } smallt *o = toSmallt(toInject); + if (!o) { + sFree((smallt*)a); + return(NULL); + } if (!(o->type == CONTAINER && (((sContainert*)o)->dataType == SH_DT_BASET))) { finishO(toInject); @@ -7755,6 +7781,9 @@ internal smallArrayt* setAtNFreeSmallArray(smallArrayt *self, int64_t index, bas } smallt *o = toSmallt(value); + if (!o) { + return(NULL); + } sArraySetTiny(self->a, index, o); if (!(o->type == CONTAINER && (((sContainert*)o)->dataType == SH_DT_BASET))) { @@ -10853,7 +10882,11 @@ internal char* joinSSmallArray(smallArrayt *self, const char* delim) { } break; default: - s = sToString(e);; + s = sToString(e); + if (!s) { + free(r); + return(NULL); + } if (!r) { r = strdup(s); } @@ -10961,6 +10994,9 @@ internal smallArrayt* zipSmallJsonSmallArray(smallArrayt *self, smallArrayt *ar } createSmallArray(a); + if (!a.f) { + return(NULL); + } setsoO(&a, (sArrayt*)getsoO(array2)); return(zipSmallArray(self, array1, &a)); } @@ -10986,6 +11022,9 @@ internal smallArrayt* zipSmallJsonSmallArraySmallArray(smallArrayt *self, small } createSmallArray(a); + if (!a.f) { + return(NULL); + } setsoO(&a, (sArrayt*)getsoO(array1)); return(zipSmallArray(self, &a, array2)); } @@ -11017,8 +11056,14 @@ internal smallArrayt* zipSmallJsonSmallJsonSmallArray(smallArrayt *self, smallJ } createSmallArray(a); - setsoO(&a, (sArrayt*)getsoO(array1)); + if (!a.f) { + return(NULL); + } createSmallArray(b); + if (!b.f) { + return(NULL); + } + setsoO(&a, (sArrayt*)getsoO(array1)); setsoO(&b, (sArrayt*)getsoO(array2)); return(zipSmallArray(self, &a, &b)); } @@ -11040,6 +11085,9 @@ internal smallArrayt* zipSmallJsonCharSmallArray(smallArrayt *self, smallJsont } createSmallArray(a); + if (!a.f) { + return(NULL); + } setsoO(&a, (sArrayt*)getsoO(array1)); return(zipCharSmallArray(self, &a, array2)); } @@ -11061,6 +11109,9 @@ internal smallArrayt* zipSmallJsonCCharSmallArray(smallArrayt *self, smallJsont } createSmallArray(a); + if (!a.f) { + return(NULL); + } setsoO(&a, (sArrayt*)getsoO(array1)); return(zipCCharSmallArray(self, &a, array2)); } @@ -11158,6 +11209,9 @@ internal smallArrayt* zipArraySmallJsonSmallArray(smallArrayt *self, char** arr } createSmallArray(a); + if (!a.f) { + return(NULL); + } setsoO(&a, (sArrayt*)getsoO(array2)); return(zipArraySmallArray(self, array1, &a)); } @@ -11179,6 +11233,9 @@ internal smallArrayt* zipCArraySmallJsonSmallArray(smallArrayt *self, const cha } createSmallArray(a); + if (!a.f) { + return(NULL); + } setsoO(&a, (sArrayt*)getsoO(array2)); return(zipCArraySmallArray(self, array1, &a)); } @@ -11409,7 +11466,12 @@ internal void logSmallArray(smallArrayt *self) { forEachSArray(self->a, e) { if (e) { char *s = sToString(e); - puts(s); + if (s) { + puts(s); + } + else { + puts("(null)"); + } free(s); } } diff --git a/src/json/libsheepyCSmallBool.c b/src/json/libsheepyCSmallBool.c @@ -208,9 +208,12 @@ void initiateAllocateSmallBool(smallBoolt **self) { // recycleContainers if (*self) { initiateSmallBool(*self); + if (!(*self)->f) { + finishSmallBool(self); } } } + } void finalizeRecycleSmallBool(void *arg UNUSED) { diff --git a/src/json/libsheepyCSmallBytes.c b/src/json/libsheepyCSmallBytes.c @@ -177,9 +177,12 @@ void initiateAllocateSmallBytes(smallBytest **self) { #endif if (*self) { initiateSmallBytes(*self); + if (!(*self)->f) { + finishSmallBytes(self); } } } + } void finalizeRecycleSmallBytes(void *arg UNUSED) { diff --git a/src/json/libsheepyCSmallContainer.c b/src/json/libsheepyCSmallContainer.c @@ -115,9 +115,12 @@ void initiateAllocateSmallContainer(smallContainert **self) { #endif if (*self) { initiateSmallContainer(*self); + if (!(*self)->f) { + finishSmallContainer(self); } } } + } void finalizeRecycleSmallContainer(void *arg UNUSED) { diff --git a/src/json/libsheepyCSmallDict.c b/src/json/libsheepyCSmallDict.c @@ -957,9 +957,12 @@ void initiateAllocateSmallDict(smallDictt **self) { #endif if (*self) { initiateSmallDict(*self); + if (!(*self)->f) { + finishSmallDict(self); } } } + } void finalizeRecycleSmallDict(void *arg UNUSED) { @@ -1572,6 +1575,9 @@ internal smallDictt* setNFreeSmallDict(smallDictt *self, const char *key, baset } smallt *o = toSmallt(value); + if (!o) { + return(NULL); + } sDictSetTiny(&(self->d), key, o); if (!(o->type == CONTAINER && (((sContainert*)o)->dataType == SH_DT_BASET))) { @@ -4815,6 +4821,9 @@ internal smallDictt* zipSmallJsonSmallDict(smallDictt *self, smallArrayt *keys, } createSmallArray(a); + if (!a.f) { + return(NULL); + } setsoO(&a, (sArrayt*)getsoO(values)); return(zipSmallDict(self, keys, &a)); } @@ -4840,6 +4849,9 @@ internal smallDictt* zipSmallJsonSmallArraySmallDict(smallDictt *self, smallJson } createSmallArray(a); + if (!a.f) { + return(NULL); + } setsoO(&a, (sArrayt*)getsoO(keys)); return(zipSmallDict(self, &a, values)); } @@ -4871,8 +4883,14 @@ internal smallDictt* zipSmallJsonSmallJsonSmallDict(smallDictt *self, smallJsont } createSmallArray(a); - setsoO(&a, (sArrayt*)getsoO(keys)); + if (!a.f) { + return(NULL); + } createSmallArray(b); + if (!b.f) { + return(NULL); + } + setsoO(&a, (sArrayt*)getsoO(keys)); setsoO(&b, (sArrayt*)getsoO(values)); return(zipSmallDict(self, &a, &b)); } @@ -4894,6 +4912,9 @@ internal smallDictt* zipSmallJsonVArraySmallDict(smallDictt *self, smallJsont *k } createSmallArray(a); + if (!a.f) { + return(NULL); + } setsoO(&a, (sArrayt*)getsoO(keys)); return(zipVArraySmallDict(self, &a, values)); } @@ -4950,6 +4971,9 @@ internal smallDictt* zipArraySmallJsonSmallDict(smallDictt *self, char** keys, s } createSmallArray(a); + if (!a.f) { + return(NULL); + } setsoO(&a, (sArrayt*)getsoO(values)); return(zipArraySmallDict(self, keys, &a)); } diff --git a/src/json/libsheepyCSmallDouble.c b/src/json/libsheepyCSmallDouble.c @@ -208,9 +208,12 @@ void initiateAllocateSmallDouble(smallDoublet **self) { #endif if (*self) { initiateSmallDouble(*self); + if (!(*self)->f) { + finishSmallDouble(self); } } } + } void finalizeRecycleSmallDouble(void *arg UNUSED) { diff --git a/src/json/libsheepyCSmallInt.c b/src/json/libsheepyCSmallInt.c @@ -214,9 +214,12 @@ void initiateAllocateSmallInt(smallIntt **self) { #endif if (*self) { initiateSmallInt(*self); + if (!(*self)->f) { + finishSmallInt(self); } } } + } void finalizeRecycleSmallInt(void *arg UNUSED) { diff --git a/src/json/libsheepyCSmallJson.c b/src/json/libsheepyCSmallJson.c @@ -2579,9 +2579,12 @@ void initiateAllocateSmallJson(smallJsont **self) { #endif if (*self) { initiateSmallJson(*self); + if (!(*self)->f) { + finishSmallJson(self); } } } + } smallJsont* createSJF(const char *paramType, ...) { va_list pl; @@ -4834,6 +4837,9 @@ internal smallJsont* setAtNFreeSmallJson(smallJsont *self, int64_t index, baset } smallt *o = toSmallt(value); + if (!o) { + return(NULL); + } sArraySetTiny(self->topA, index, o); if (!(o->type == CONTAINER && (((sContainert*)o)->dataType == SH_DT_BASET))) { @@ -5695,6 +5701,9 @@ internal smallJsont* pushNFreeSmallJson(smallJsont *self, baset *value) { FALLTHRU; case TOP_IS_ARRAY: o = toSmallt(value); + if (!o) { + return(NULL); + } sArrayPushTiny(&(self->topA), o); break; default: @@ -5845,6 +5854,9 @@ internal smallJsont* pushManySmallJson(smallJsont *self, ...) { smallStringt *paramTypes; createSmallArray(l); + if (!l.f) { + return(NULL); + } if (self->topS) { // add self to result createSmallString(ss); @@ -5905,6 +5917,9 @@ internal smallJsont* pushManySSmallJson(smallJsont *self, ...) { char *paramTypes; createSmallArray(l); + if (!l.f) { + return(NULL); + } if (self->topS) { // add self to result createSmallString(ss); @@ -5959,6 +5974,9 @@ internal smallJsont* pushNFreeManySmallJson(smallJsont *self, ...) { smallStringt *paramTypes; createSmallArray(l); + if (!l.f) { + return(NULL); + } if (self->topS) { // add self to result createSmallString(ss); @@ -6019,6 +6037,9 @@ internal smallJsont* pushNFreeManySSmallJson(smallJsont *self, ...) { char *paramTypes; createSmallArray(l); + if (!l.f) { + return(NULL); + } if (self->topS) { // add self to result createSmallString(ss); @@ -6593,11 +6614,15 @@ internal smallJsont* prependSmallJson(smallJsont *self, baset *value) { return(NULL); } + o = toSmallt(value);; + if (!o) { + return(NULL); + } + if (self->topIsA == SMALLJSON_IS_EMPTY) { self->topIsA = TOP_IS_ARRAY; } - o = toSmallt(value);; sArrayPrependTiny(&(self->topA), o); return(self); } @@ -7019,11 +7044,15 @@ internal smallJsont* prependNFreeSmallJson(smallJsont *self, baset *value) { return(NULL); } + o = toSmallt(value);; + if (!o) { + return(NULL); + } + if (self->topIsA == SMALLJSON_IS_EMPTY) { self->topIsA = TOP_IS_ARRAY; } - o = toSmallt(value);; sArrayPrependTiny(&(self->topA), o); if (!(o->type == CONTAINER && (((sContainert*)o)->dataType == SH_DT_BASET))) { @@ -7783,6 +7812,9 @@ internal smallJsont* catSmallJson(smallJsont *self, ...) { smallStringt *paramTypes; createSmallArray(l); + if (!l.f) { + return(NULL); + } if (self->topS) { // add self to result createSmallString(ss); @@ -18106,7 +18138,11 @@ internal char* joinSSmallJson(smallJsont *self, const char* delim) { } break; default: - s = sToString(e);; + s = sToString(e); + if (!s) { + free(r); + return(NULL); + } if (!r) { r = strdup(s); } diff --git a/src/json/libsheepyCSmallString.c b/src/json/libsheepyCSmallString.c @@ -798,9 +798,12 @@ void initiateAllocateSmallString(smallStringt **self) { #endif if (*self) { initiateSmallString(*self); + if (!(*self)->f) { + finishSmallString(self); } } } + } void finalizeRecycleSmallString(void *arg UNUSED) { @@ -855,6 +858,9 @@ smallStringt* createSF(const char *paramType, ...) { smallStringt *r = NULL; createSmallArray(l); + if (!l.f) { + return(NULL); + } // add arguments to a list va_start(pl, paramType); @@ -1513,6 +1519,10 @@ internal smallStringt* catSmallString(smallStringt *self, ...) { smallStringt *paramType = NULL; createSmallArray(l); + if (!l.f) { + return(NULL); + } + if (self->data) { // add self to result l.f->pushSmallString(&l, self); @@ -1546,6 +1556,10 @@ internal smallStringt* catSSmallString(smallStringt *self, ...) { char *paramType = NULL; createSmallArray(l); + if (!l.f) { + return(NULL); + } + if (self->data) { // add self to result l.f->pushS(&l, sStringGetTiny(self->data)); @@ -1574,6 +1588,10 @@ internal smallStringt* pushNFreeManySmallString(smallStringt *self, ...) { smallStringt *paramType = NULL; createSmallArray(l); + if (!l.f) { + return(NULL); + } + if (self->data) { // add self to result l.f->pushSmallString(&l, self); @@ -1607,6 +1625,10 @@ internal smallStringt* pushNFreeManySSmallString(smallStringt *self, ...) { char *paramType = NULL; createSmallArray(l); + if (!l.f) { + return(NULL); + } + if (self->data) { // add self to result l.f->pushSmallString(&l, self); diff --git a/src/json/libsheepyCUndefined.c b/src/json/libsheepyCUndefined.c @@ -80,9 +80,12 @@ void initiateAllocateUndefined(undefinedt **self) { #endif if (*self) { initiateUndefined(*self); + if (!(*self)->f) { + finishUndefined(self); } } } + } void finalizeRecycleUndefined(void *arg UNUSED) { diff --git a/src/json/libsheepyObject.c b/src/json/libsheepyObject.c @@ -826,7 +826,9 @@ void putsIntGF(int64_t object) { char *s = NULL; s = intToS(object); - puts(s); + if (s) { + puts(s); + } free(s); } @@ -837,7 +839,9 @@ void putsIntPGF(int64_t* object) { return; } s = intToS(*object); - puts(s); + if (s) { + puts(s); + } free(s); } @@ -845,7 +849,9 @@ void putsInt32GF(int32_t object) { char *s = NULL; s = intToS(object); - puts(s); + if (s) { + puts(s); + } free(s); } @@ -856,7 +862,9 @@ void putsInt32PGF(int32_t* object) { return; } s = intToS(*object); - puts(s); + if (s) { + puts(s); + } free(s); } @@ -864,7 +872,9 @@ void putsUintGF(uint64_t object) { char *s = NULL; s = intToS(object); - puts(s); + if (s) { + puts(s); + } free(s); } @@ -875,7 +885,9 @@ void putsUintPGF(uint64_t* object) { return; } s = intToS(*object); - puts(s); + if (s) { + puts(s); + } free(s); } @@ -883,7 +895,9 @@ void putsUint32GF(uint32_t object) { char *s = NULL; s = intToS(object); - puts(s); + if (s) { + puts(s); + } free(s); } @@ -894,7 +908,9 @@ void putsUint32PGF(uint32_t* object) { return; } s = intToS(*object); - puts(s); + if (s) { + puts(s); + } free(s); } diff --git a/src/libsheepy.c b/src/libsheepy.c @@ -3925,6 +3925,9 @@ char *bLRelPath(char *dest, size_t destSize, char *path, const char *start) { char *getHomePath(void) { struct passwd *pw = getpwuid(getuid());; + if (!pw) { + return(NULL); + } return(strdup(pw->pw_dir)); } @@ -3939,6 +3942,9 @@ char *getHomePath(void) { char *bGetHomePath(char *path) { struct passwd *pw = getpwuid(getuid());; + if (!pw) { + return(NULL); + } strcpy(path, pw->pw_dir); return(path); } @@ -3956,6 +3962,9 @@ char *bGetHomePath(char *path) { char *bLGetHomePath(char *path, size_t pathSize) { struct passwd *pw = getpwuid(getuid());; + if (!pw) { + return(NULL); + } if (strlen(pw->pw_dir)+1 > pathSize) { return(NULL); } @@ -3972,6 +3981,9 @@ char *bLGetHomePath(char *path, size_t pathSize) { const char *getCHomePath(void) { struct passwd *pw = getpwuid(getuid());; + if (!pw) { + return(NULL); + } return(pw->pw_dir); } @@ -5513,7 +5525,6 @@ int rmADir(const char *dirPath) { * 0 when src or dst are NULL or empty */ int copy(const char* src, const char* dst) { - int r = 1;; // sanity checks if (!src || !dst || isBlankS(src) || isBlankS(dst)) { @@ -5562,7 +5573,7 @@ int copy(const char* src, const char* dst) { } } - r = copyADir(src, dPath, ""); + int r = copyADir(src, dPath, ""); // copy permissions struct stat st; @@ -6264,11 +6275,13 @@ UNUSED local char *shGetpass(void) { /* Turn echoing off and fail if we can’t. */ if (tcgetattr (fileno (stream), &old) != 0) { + fclose(stream); return(NULL); } new = old; new.c_lflag &= ~ECHO; if (tcsetattr (fileno (stream), TCSAFLUSH, &new) != 0) { + fclose(stream); return(NULL); } @@ -6296,7 +6309,11 @@ char *readPasswordS(void) { #if (__TERMUX__ || __HAIKU__ || unitTest) char *r = shGetpass(); #else + // TODO getpass is obsolete, see man for getpass char *p = getpass(""); + if (!p) { + return(NULL); + } char *r = strdup(p); memset(p, 0, strlen(p)); #endif @@ -9912,6 +9929,9 @@ char *upperS(const char *string) { } r = strdup(string); + if (!r) { + return(NULL); + } // upper case size_t i = 0; @@ -9990,6 +10010,9 @@ char *lowerS(const char *string) { } r = strdup(string); + if (!r) { + return(NULL); + } // lower case size_t i = 0; @@ -10089,6 +10112,9 @@ char *trimS(const char *string) { // copy range to new string len = end - string + 2; r = MALLOC(len); + if (!r) { + return(NULL); + } r = strncpy(r, string, len - 1); r[len - 1] = 0; return(r); @@ -10137,6 +10163,9 @@ char *iTrimS(char **string) { // copy range to new string len = end - workingS + 2; r = MALLOC(len); + if (!r) { + return(NULL); + } r = strncpy(r, workingS, len - 1); r[len - 1] = 0; free(*string); @@ -10186,6 +10215,9 @@ char *bTrimS(char *string) { // copy range to new string len = end - workingS + 2; r = MALLOC(len); + if (!r) { + return(NULL); + } r = strncpy(r, workingS, len - 1); r[len - 1] = 0; strcpy(string, r); @@ -10252,6 +10284,9 @@ char *iLTrimS(char **string) { } r = strdup(workingS); + if (!r) { + return(NULL); + } free(*string); *string = r;; return(r); @@ -10316,6 +10351,9 @@ char *rTrimS(const char *string) { // copy range to new string len = end - string + 2; r = MALLOC(len); + if (!r) { + return(NULL); + } r = strncpy(r, string, len - 1); r[len - 1] = 0; return(r); @@ -10683,6 +10721,9 @@ char *repeatS(const char *string, size_t count) { size_t len = slen * count; r = MALLOC(len+1);; + if (!r) { + return(NULL); + } strcpy(r, string); count--; @@ -10723,6 +10764,9 @@ char *iRepeatS(char **string, size_t count) { size_t len = slen * count; r = MALLOC(len+1);; + if (!r) { + return(NULL); + } strcpy(r, *string); count--; @@ -11468,6 +11512,9 @@ char *bEllipsisEndS(char *dest, const char *string, size_t targetLength, const c // ellipsisString is longer than targetLength ellip = sliceS(ellipsisString, 0, targetLength); } + if (!ellip) { + return(NULL); + } strncpy(dest, ellip, targetLength+1); free(ellip); } @@ -11663,6 +11710,9 @@ char *bEllipsisEndCharS(char *dest, const char *string, size_t targetLength, cha // truncate string char *ellip; ellip = sliceS(string, 0, targetLength - strlen(ellipsisString)); + if (!ellip) { + return(NULL); + } iAppendS(&ellip, ellipsisString); strncpy(dest, ellip, targetLength+1); free(ellip); @@ -11764,6 +11814,9 @@ char *padStartS(const char *string, size_t targetLength, const char *padString) targetLength -= strlen(string); char *pads = strdup(padString);; + if (!pads) { + return(NULL); + } if (targetLength > strlen(padString)) { iRepeatS(&pads, targetLength/strlen(padString)+1); } @@ -11869,6 +11922,9 @@ char *bPadStartS(char *dest, const char *string, size_t targetLength, const char targetLength -= strlen(string); char *pads = strdup(padString);; + if (!pads) { + return(NULL); + } if (targetLength > strlen(padString)) { iRepeatS(&pads, targetLength/strlen(padString)+1); } @@ -11877,6 +11933,9 @@ char *bPadStartS(char *dest, const char *string, size_t targetLength, const char char *r = appendS(pads, string); free(pads); + if (!r) { + return(NULL); + } strcpy(dest, r); free(r); @@ -11925,6 +11984,9 @@ char *bLPadStartS(char *dest, size_t destSize, const char *string, size_t target targetLength -= strlen(string); char *pads = strdup(padString);; + if (!pads) { + return(NULL); + } if (targetLength > strlen(padString)) { iRepeatS(&pads, targetLength/strlen(padString)+1); } @@ -11933,6 +11995,9 @@ char *bLPadStartS(char *dest, size_t destSize, const char *string, size_t target char *r = appendS(pads, string); free(pads); + if (!r) { + return(NULL); + } strLCpy(dest, destSize, r); free(r); @@ -11973,6 +12038,9 @@ char *padStartCharS(const char *string, size_t targetLength, char padChar) { charToS(padString, padChar); char *pads = strdup(padString);; + if (!pads) { + return(NULL); + } if (targetLength > strlen(padString)) { iRepeatS(&pads, targetLength/strlen(padString)+1); } @@ -12065,6 +12133,9 @@ char *bPadStartCharS(char *dest, const char *string, size_t targetLength, char p charToS(padString, padChar); char *pads = strdup(padString);; + if (!pads) { + return(NULL); + } if (targetLength > strlen(padString)) { iRepeatS(&pads, targetLength/strlen(padString)+1); } @@ -12073,6 +12144,9 @@ char *bPadStartCharS(char *dest, const char *string, size_t targetLength, char p char *r = appendS(pads, string); free(pads); + if (!r) { + return(NULL); + } strcpy(dest, r); free(r); @@ -12114,6 +12188,9 @@ char *bLPadStartCharS(char *dest, size_t destSize, const char *string, size_t ta charToS(padString, padChar); char *pads = strdup(padString);; + if (!pads) { + return(NULL); + } if (targetLength > strlen(padString)) { iRepeatS(&pads, targetLength/strlen(padString)+1); } @@ -12122,6 +12199,9 @@ char *bLPadStartCharS(char *dest, size_t destSize, const char *string, size_t ta char *r = appendS(pads, string); free(pads); + if (!r) { + return(NULL); + } strLCpy(dest, destSize, r); free(r); @@ -12196,6 +12276,9 @@ char *padEndS(const char *string, size_t targetLength, const char *padString) { targetLength -= strlen(string); char *pads = strdup(padString);; + if (!pads) { + return(NULL); + } if (targetLength > strlen(padString)) { iRepeatS(&pads, targetLength/strlen(padString)+1); } @@ -12249,6 +12332,9 @@ char *iPadEndS(char **string, size_t targetLength, const char *padString) { targetLength -= strlen(*string); char *pads = strdup(padString);; + if (!pads) { + return(NULL); + } if (targetLength > strlen(padString)) { iRepeatS(&pads, targetLength/strlen(padString)+1); } @@ -12302,6 +12388,9 @@ char *bPadEndS(char *dest, const char *string, size_t targetLength, const char * targetLength -= strlen(string); char *pads = strdup(padString);; + if (!pads) { + return(NULL); + } if (targetLength > strlen(padString)) { iRepeatS(&pads, targetLength/strlen(padString)+1); } @@ -12310,6 +12399,9 @@ char *bPadEndS(char *dest, const char *string, size_t targetLength, const char * char *r = appendS(string, pads); free(pads); + if (!r) { + return(NULL); + } strcpy(dest, r); free(r); @@ -12358,6 +12450,9 @@ char *bLPadEndS(char *dest, size_t destSize, const char *string, size_t targetLe targetLength -= strlen(string); char *pads = strdup(padString);; + if (!pads) { + return(NULL); + } if (targetLength > strlen(padString)) { iRepeatS(&pads, targetLength/strlen(padString)+1); } @@ -12366,6 +12461,9 @@ char *bLPadEndS(char *dest, size_t destSize, const char *string, size_t targetLe char *r = appendS(string, pads); free(pads); + if (!r) { + return(NULL); + } strLCpy(dest, destSize, r); free(r); @@ -12406,6 +12504,9 @@ char *padEndCharS(const char *string, size_t targetLength, char padChar) { charToS(padString, padChar); char *pads = strdup(padString);; + if (!pads) { + return(NULL); + } if (targetLength > strlen(padString)) { iRepeatS(&pads, targetLength/strlen(padString)+1); } @@ -12451,6 +12552,9 @@ char *iPadEndCharS(char **string, size_t targetLength, char padChar) { charToS(padString, padChar); char *pads = strdup(padString);; + if (!pads) { + return(NULL); + } if (targetLength > strlen(padString)) { iRepeatS(&pads, targetLength/strlen(padString)+1); } @@ -12497,6 +12601,9 @@ char *bPadEndCharS(char *dest, const char *string, size_t targetLength, char pad charToS(padString, padChar); char *pads = strdup(padString);; + if (!pads) { + return(NULL); + } if (targetLength > strlen(padString)) { iRepeatS(&pads, targetLength/strlen(padString)+1); } @@ -12505,6 +12612,9 @@ char *bPadEndCharS(char *dest, const char *string, size_t targetLength, char pad char *r = appendS(string, pads); free(pads); + if (!r) { + return(NULL); + } strcpy(dest, r); free(r); @@ -12546,6 +12656,9 @@ char *bLPadEndCharS(char *dest, size_t destSize, const char *string, size_t targ charToS(padString, padChar); char *pads = strdup(padString);; + if (!pads) { + return(NULL); + } if (targetLength > strlen(padString)) { iRepeatS(&pads, targetLength/strlen(padString)+1); } @@ -12554,6 +12667,9 @@ char *bLPadEndCharS(char *dest, size_t destSize, const char *string, size_t targ char *r = appendS(string, pads); free(pads); + if (!r) { + return(NULL); + } strLCpy(dest, destSize, r); free(r); @@ -12686,6 +12802,9 @@ char *swapS(char *string, int64_t index1, int64_t index2) { } char *r = strdup(string); + if (!r) { + return(NULL); + } char tmp = r[index1]; r[index1] = r[index2]; @@ -14977,13 +15096,11 @@ bool isCodeUTF8(const char *code) { // ASCII // use bytes[0] <= 0x7F to allow ASCII control characters if (bytes[0] == 0x09 || bytes[0] == 0x0A || bytes[0] == 0x0D || (0x20 <= bytes[0] && bytes[0] <= 0x7E)) { - bytes += 1; return(true); } // non-overlong 2-byte if ((0xC2 <= bytes[0] && bytes[0] <= 0xDF) && (0x80 <= bytes[1] && bytes[1] <= 0xBF)) { - bytes += 2; return(true); } @@ -14991,7 +15108,6 @@ bool isCodeUTF8(const char *code) { // straight 3-byte // excluding surrogates if ((bytes[0] == 0xE0 && (0xA0 <= bytes[1] && bytes[1] <= 0xBF) && (0x80 <= bytes[2] && bytes[2] <= 0xBF)) || (((0xE1 <= bytes[0] && bytes[0] <= 0xEC) || bytes[0] == 0xEE || bytes[0] == 0xEF) && (0x80 <= bytes[1] && bytes[1] <= 0xBF) && (0x80 <= bytes[2] && bytes[2] <= 0xBF)) || (bytes[0] == 0xED && (0x80 <= bytes[1] && bytes[1] <= 0x9F) && (0x80 <= bytes[2] && bytes[2] <= 0xBF))) { - bytes += 3; return(true); } @@ -14999,7 +15115,6 @@ bool isCodeUTF8(const char *code) { // planes 4-15 // plane 16 if ((bytes[0] == 0xF0 && (0x90 <= bytes[1] && bytes[1] <= 0xBF) && (0x80 <= bytes[2] && bytes[2] <= 0xBF) && (0x80 <= bytes[3] && bytes[3] <= 0xBF)) || ((0xF1 <= bytes[0] && bytes[0] <= 0xF3) && (0x80 <= bytes[1] && bytes[1] <= 0xBF) && (0x80 <= bytes[2] && bytes[2] <= 0xBF) && (0x80 <= bytes[3] && bytes[3] <= 0xBF)) || (bytes[0] == 0xF4 && (0x80 <= bytes[1] && bytes[1] <= 0x8F) && (0x80 <= bytes[2] && bytes[2] <= 0xBF) && (0x80 <= bytes[3] && bytes[3] <= 0xBF))) { - bytes += 4; return(true); } @@ -47015,6 +47130,9 @@ char *uniqUTF8(const char *string, const char *code) { } r = strdup(string); + if (!r) { + return(NULL); + } len = lenUTF8(string); if (len < 2) { @@ -48337,14 +48455,10 @@ char *bLDelUTF8(char *string, size_t stringSize, int64_t start, int64_t end) { char *endp = bLIdx2PtrUTF8(string, stringSize, end); size_t starto = (size_t)(startp-string); - size_t endo = (size_t)(endp-string); if (starto >= stringSize) { starto = stringSize; } - if (endo > stringSize) { - endo = stringSize; - } if (start == 0) { starto = 0; } @@ -49129,6 +49243,9 @@ char **listPushS(char ***list, const char *s) { if (!*list) { *list = MALLOC(2 * sizeof(char *)); + if (!*list) { + return(NULL); + } (*list)[0] = strdup(s); (*list)[1] = NULL; } @@ -49181,6 +49298,9 @@ char **iListPushS(char ***list, char *s) { if (!*list) { *list = MALLOC(2 * sizeof(char *)); + if (!*list) { + return(NULL); + } (*list)[0] = s; (*list)[1] = NULL; } @@ -49260,6 +49380,9 @@ char **listPrependS(char ***list, const char *s) { if (!*list) { *list = MALLOC(2 * sizeof(char *)); + if (!*list) { + return(NULL); + } (*list)[0] = strdup(s); (*list)[1] = NULL; } @@ -49316,6 +49439,9 @@ char **iListPrependS(char ***list, char *s) { if (!*list) { *list = MALLOC(2 * sizeof(char *)); + if (!*list) { + return(NULL); + } (*list)[0] = s; (*list)[1] = NULL; } @@ -50517,6 +50643,9 @@ char **iListAppendS(char ***list1, char **list2) { // copy list2 len2 = listLengthS(list2); *list1 = MALLOC((len2+1) * sizeof(char *)); + if (!*list1) { + return(NULL); + } int j = 0; while (list2[j]) { (*list1)[j] = list2[j]; @@ -53602,6 +53731,9 @@ void **listPush(void ***list, void *s) { if (!*list) { *list = MALLOC(2 * sizeof(void *)); + if (!*list) { + return(NULL); + } (*list)[0] = s; (*list)[1] = NULL; } @@ -53683,6 +53815,9 @@ void **listPrepend(void ***list, void *s) { if (!*list) { *list = MALLOC(2 * sizeof(void *)); + if (!*list) { + return(NULL); + } (*list)[0] = s; (*list)[1] = NULL; } @@ -54051,6 +54186,9 @@ void **listAppend(void ***list1, void **list2) { // copy list2 len2 = listLength(list2); *list1 = MALLOC((len2+1) * sizeof(void *)); + if (!*list1) { + return(NULL); + } int j = 0; while (list2[j]) { (*list1)[j] = list2[j]; diff --git a/src/libsheepy.h b/src/libsheepy.h @@ -98,7 +98,7 @@ // version accoring to the version package: Release.Major.minor.patch // https://noulin.net/version/file/README.md.html -#define LIBSHEEPY_VERSION "2.2.5.1" +#define LIBSHEEPY_VERSION "2.2.5.2" #ifndef SH_PREFIX #define SH_PREFIX(NAME) NAME