commit e98c9079b075ae005ed61aea4be43d187fad55f3
parent e69e1e9d26f1d350ae97ecc47079119b48fddf77
Author: Remy Noulin <loader2x@gmail.com>
Date: Sat, 2 Jan 2021 21:15:33 +0100
fix problems detected with clang static analyzer
src/json/libsheepyCSmallDict.c | 39 +++++++++++++++++---
src/json/libsheepyCSmallJson.c | 78 +++++++++++++++++++++++++++++++---------
src/json/libsheepyCSmallString.c | 2 --
3 files changed, 96 insertions(+), 23 deletions(-)
Diffstat:
3 files changed, 96 insertions(+), 23 deletions(-)
diff --git a/src/json/libsheepyCSmallDict.c b/src/json/libsheepyCSmallDict.c
@@ -2974,6 +2974,9 @@ internal bool cropElemBoolSmallDict(smallDictt *self, char* key) {
if (e->key && strEq(key, e->key)) {
sm = e->data;
o = (smallBoolt*)toBaset(sm);
+ if (!o) {
+ return(false);
+ }
if (checkObjectTypes && o && !isOSmallBool(o)) {
finishO(o);
return(false);
@@ -3002,6 +3005,9 @@ internal double cropElemDoubleSmallDict(smallDictt *self, char* key) {
if (e->key && strEq(key, e->key)) {
sm = e->data;
o = (smallDoublet*)toBaset(sm);
+ if (!o) {
+ return(0);
+ }
if (checkObjectTypes && o && !isOSmallDouble(o)) {
finishO(o);
return(0);
@@ -3030,6 +3036,9 @@ internal int64_t cropElemIntSmallDict(smallDictt *self, char* key) {
if (e->key && strEq(key, e->key)) {
sm = e->data;
o = (smallIntt*)toBaset(sm);
+ if (!o) {
+ return(0);
+ }
if (checkObjectTypes && o && !isOSmallInt(o)) {
finishO(o);
return(0);
@@ -3058,6 +3067,9 @@ internal int32_t cropElemInt32SmallDict(smallDictt *self, char* key) {
if (e->key && strEq(key, e->key)) {
sm = e->data;
o = (smallIntt*)toBaset(sm);
+ if (!o) {
+ return(0);
+ }
if (checkObjectTypes && o && !isOSmallInt(o)) {
finishO(o);
return(0);
@@ -3086,6 +3098,9 @@ internal uint64_t cropElemUintSmallDict(smallDictt *self, char* key) {
if (e->key && strEq(key, e->key)) {
sm = e->data;
o = (smallIntt*)toBaset(sm);
+ if (!o) {
+ return(0);
+ }
if (checkObjectTypes && o && !isOSmallInt(o)) {
finishO(o);
return(0);
@@ -3114,6 +3129,9 @@ internal uint32_t cropElemUint32SmallDict(smallDictt *self, char* key) {
if (e->key && strEq(key, e->key)) {
sm = e->data;
o = (smallIntt*)toBaset(sm);
+ if (!o) {
+ return(0);
+ }
if (checkObjectTypes && o && !isOSmallInt(o)) {
finishO(o);
return(0);
@@ -3142,6 +3160,9 @@ internal char* cropElemSSmallDict(smallDictt *self, char* key) {
if (e->key && strEq(key, e->key)) {
sm = e->data;
o = (smallStringt*)toBaset(sm);
+ if (!o) {
+ return(NULL);
+ }
if (checkObjectTypes && o && !isOSmallString(o)) {
finishO(o);
return(NULL);
@@ -3320,7 +3341,6 @@ internal smallJsont* cropElemSmallJsonSmallDict(smallDictt *self, char* key) {
sm = e->data;
baset *o = toBaset(sm);
if (!o) {
- finishO(o);
return(NULL);
}
free(e->key);
@@ -3371,6 +3391,9 @@ internal void* cropElemVoidSmallDict(smallDictt *self, char* key) {
if (e->key && strEq(key, e->key)) {
sm = e->data;
o = (smallContainert*)toBaset(sm);
+ if (!o) {
+ return(NULL);
+ }
if (checkObjectTypes && o && !isOSmallContainer(o)) {
finishO(o);
return(NULL);
@@ -4633,8 +4656,11 @@ internal smallDictt* zipSmallDict(smallDictt *self, smallArrayt *keys, smallArra
if (not K) {
return(NULL);
}
- castS(k, K);
- sDictSetTiny(&(self->d), ssGet(k), sArrayGetTiny(values->a, count));
+ if (!isOSmallString(K)) {
+ finishO(K);
+ return(NULL);
+ }
+ sDictSetTiny(&(self->d), ssGet(K), sArrayGetTiny(values->a, count));
finishO(K);
count++;
if (count == len) {
@@ -4867,9 +4893,12 @@ internal smallDictt* zipVArraySmallDict(smallDictt *self, smallArrayt *keys, cha
if (not K) {
return(NULL);
}
- castS(k, K);
+ if (!isOSmallString(K)) {
+ finishO(K);
+ return(NULL);
+ }
e = (smallt *) allocSStringTiny(values[count]);;
- sDictSetTiny(&(self->d), ssGet(k), e);
+ sDictSetTiny(&(self->d), ssGet(K), e);
finishO(K);
count++;
if (count == len) {
diff --git a/src/json/libsheepyCSmallJson.c b/src/json/libsheepyCSmallJson.c
@@ -3887,7 +3887,7 @@ internal char* makeKeySmallJson(smallJsont *self UNUSED, const char *key) {
internal char* iMakeKeySmallJson(smallJsont *self UNUSED, char **key) {
- if (!key && !*key) {
+ if (!key || !*key) {
return(NULL);
}
@@ -4643,6 +4643,8 @@ internal smallJsont* setAtSmallJsonSmallJson(smallJsont *self, intmax_t index, s
case TOP_IS_ARRAY:
o = (smallt *) value->topA;
break;
+ default:
+ return(NULL);
}
sArraySetTiny(self->topA, index, o);
return(self);
@@ -4996,6 +4998,8 @@ internal smallJsont* setPAtSmallJsonSmallJson(smallJsont *self, intmax_t index,
case TOP_IS_ARRAY:
o = (smallt *) value->topA;
break;
+ default:
+ return(NULL);
}
sArraySetP(self->topA, index, o);
return(self);
@@ -5138,6 +5142,8 @@ internal smallJsont* setPAtNFreeSmallJsonSmallJson(smallJsont *self, intmax_t in
case TOP_IS_ARRAY:
o = (smallt *) value->topA;
break;
+ default:
+ return(NULL);
}
sArraySetP(self->topA, index, o);
return(self);
@@ -8133,7 +8139,6 @@ internal smallJsont* sliceSmallJson(smallJsont *self, intmax_t start, intmax_t e
case TOP_IS_STRING:
if (start == end) {
emptyS(s);
- n = 0;
}
else {
// start < end < len
@@ -9284,6 +9289,9 @@ internal bool cropElemKeyBoolSmallJson(smallJsont *self, char* key) {
return(no);
}
o = (smallBoolt*)toBaset(sm);
+ if (!o) {
+ return(no);
+ }
if (checkObjectTypes && o && !isOSmallBool(o)) {
if ((sm->type == CONTAINER) && (((sContainert*)sm)->dataType == SH_DT_BASET)) {
return(no);
@@ -9323,6 +9331,9 @@ internal double cropElemKeyDoubleSmallJson(smallJsont *self, char* key) {
return(0);
}
o = (smallDoublet*)toBaset(sm);
+ if (!o) {
+ return(0);
+ }
if (checkObjectTypes && o && !isOSmallDouble(o)) {
if ((sm->type == CONTAINER) && (((sContainert*)sm)->dataType == SH_DT_BASET)) {
return(0);
@@ -9362,6 +9373,9 @@ internal int64_t cropElemKeyIntSmallJson(smallJsont *self, char* key) {
return(0);
}
o = (smallIntt*)toBaset(sm);
+ if (!o) {
+ return(0);
+ }
if (checkObjectTypes && o && !isOSmallInt(o)) {
if ((sm->type == CONTAINER) && (((sContainert*)sm)->dataType == SH_DT_BASET)) {
return(0);
@@ -9401,6 +9415,9 @@ internal int32_t cropElemKeyInt32SmallJson(smallJsont *self, char* key) {
return(0);
}
o = (smallIntt*)toBaset(sm);
+ if (!o) {
+ return(0);
+ }
if (checkObjectTypes && o && !isOSmallInt(o)) {
if ((sm->type == CONTAINER) && (((sContainert*)sm)->dataType == SH_DT_BASET)) {
return(0);
@@ -9440,6 +9457,9 @@ internal uint64_t cropElemKeyUintSmallJson(smallJsont *self, char* key) {
return(0);
}
o = (smallIntt*)toBaset(sm);
+ if (!o) {
+ return(0);
+ }
if (checkObjectTypes && o && !isOSmallInt(o)) {
if ((sm->type == CONTAINER) && (((sContainert*)sm)->dataType == SH_DT_BASET)) {
return(0);
@@ -9479,6 +9499,9 @@ internal uint32_t cropElemKeyUint32SmallJson(smallJsont *self, char* key) {
return(0);
}
o = (smallIntt*)toBaset(sm);
+ if (!o) {
+ return(0);
+ }
if (checkObjectTypes && o && !isOSmallInt(o)) {
if ((sm->type == CONTAINER) && (((sContainert*)sm)->dataType == SH_DT_BASET)) {
return(0);
@@ -9518,6 +9541,9 @@ internal char* cropElemKeySSmallJson(smallJsont *self, char* key) {
return(NULL);
}
o = (smallStringt*)toBaset(sm);
+ if (!o) {
+ return(NULL);
+ }
if (checkObjectTypes && o && !isOSmallString(o)) {
if ((sm->type == CONTAINER) && (((sContainert*)sm)->dataType == SH_DT_BASET)) {
return(NULL);
@@ -9846,6 +9872,9 @@ internal void* cropElemKeyVoidSmallJson(smallJsont *self, char* key) {
return(NULL);
}
o = (smallContainert*)toBaset(sm);
+ if (!o) {
+ return(NULL);
+ }
if ((sm->type == CONTAINER) && (((sContainert*)sm)->dataType == SH_DT_BASET)) {
return(NULL);
}
@@ -9966,7 +9995,6 @@ internal smallJsont* copySmallJson(smallJsont *self, intmax_t start, intmax_t en
intmax_t n;
if (start == end) {
emptyS(s);
- n = 0;
}
else {
// start < end < len
@@ -14942,7 +14970,7 @@ internal smallJsont* icReplaceManySmallJson(smallJsont *self, const char *paramT
internal bool equalSmallJsonSmallArray(smallJsont *self, smallArrayt *array) {
// sanity checks
- if (self->topIsA != TOP_IS_ARRAY) {
+ if (self->topIsA != TOP_IS_ARRAY || !array) {
return(false);
}
@@ -17701,8 +17729,11 @@ internal smallJsont* zipSmallJson(smallJsont *self, smallArrayt *array1, smallAr
if (!K) {
return(NULL);
}
- castS(k, K);
- sDictSetTiny(&(self->top), ssGet(k), sArrayGetTiny(array2->a, count));
+ if (!isOSmallString(K)) {
+ finishO(K);
+ return(NULL);
+ }
+ sDictSetTiny(&(self->top), ssGet(K), sArrayGetTiny(array2->a, count));
finishO(K);
count++;
if (count == len) {
@@ -17820,9 +17851,12 @@ internal smallJsont* zipCharSmallJson(smallJsont *self, smallArrayt *array1, cha
if (!K) {
return(NULL);
}
- castS(k, K);
+ if (!isOSmallString(K)) {
+ finishO(K);
+ return(NULL);
+ }
e = (smallt *) allocSStringTiny(array2[count]);;
- sDictSetTiny(&(self->top), ssGet(k), e);
+ sDictSetTiny(&(self->top), ssGet(K), e);
finishO(K);
count++;
if (count == len) {
@@ -17940,8 +17974,11 @@ smallJsont* zipJsonSmallJson(smallJsont *self, smallJsont *array1, smallJsont *a
if (!K) {
return(NULL);
}
- castS(k, K);
- sDictSetTiny(&(self->top), ssGet(k), sArrayGetTiny(array2->topA, count));
+ if (!isOSmallString(K)) {
+ finishO(K);
+ return(NULL);
+ }
+ sDictSetTiny(&(self->top), ssGet(K), sArrayGetTiny(array2->topA, count));
finishO(K);
count++;
if (count == len) {
@@ -18006,8 +18043,11 @@ smallJsont* zipJsonSmallArraySmallJson(smallJsont *self, smallJsont *array1, sma
if (!K) {
return(NULL);
}
- castS(k, K);
- sDictSetTiny(&(self->top), ssGet(k), sArrayGetTiny(array2->a, count));
+ if (!isOSmallString(K)) {
+ finishO(K);
+ return(NULL);
+ }
+ sDictSetTiny(&(self->top), ssGet(K), sArrayGetTiny(array2->a, count));
finishO(K);
count++;
if (count == len) {
@@ -18073,9 +18113,12 @@ smallJsont* zipJsonArraySmallJson(smallJsont *self, smallJsont *array1, char** a
if (!K) {
return(NULL);
}
- castS(k, K);
+ if (!isOSmallString(K)) {
+ finishO(K);
+ return(NULL);
+ }
e = (smallt *) allocSStringTiny(array2[count]);;
- sDictSetTiny(&(self->top), ssGet(k), e);
+ sDictSetTiny(&(self->top), ssGet(K), e);
finishO(K);
count++;
if (count == len) {
@@ -18139,8 +18182,11 @@ smallJsont* zipSmallArrayJsonSmallJson(smallJsont *self, smallArrayt *array1, sm
if (!K) {
return(NULL);
}
- castS(k, K);
- sDictSetTiny(&(self->top), ssGet(k), sArrayGetTiny(array2->topA, count));
+ if (!isOSmallString(K)) {
+ finishO(K);
+ return(NULL);
+ }
+ sDictSetTiny(&(self->top), ssGet(K), sArrayGetTiny(array2->topA, count));
finishO(K);
count++;
if (count == len) {
diff --git a/src/json/libsheepyCSmallString.c b/src/json/libsheepyCSmallString.c
@@ -3247,7 +3247,6 @@ internal smallStringt* sliceSmallString(smallStringt *self, intmax_t start, intm
intmax_t n;
if (start == end) {
emptyS(s);
- n = 0;
}
else {
// start < end < len
@@ -3418,7 +3417,6 @@ internal smallStringt* copySmallString(smallStringt *self, intmax_t start, intma
intmax_t n;
if (start == end) {
emptyS(s);
- n = 0;
}
else {
// start < end < len