You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In many functions in file “sds.h”, the parameter “sds s” is dereferenced without checking if it is NULL. The same error is also present in some functions in file “sds.c”, such as: sdscat, sdsMakeRoomFor, sdsRemoveFreeSpace, sdsdup, sdsupdatelen, sdscatrepr, sdscmp, sdstoupper, sdstolower, sdsrange, sdstrim, sdscatfmt, sdsclear, sdslen, sdscatvprintf, sdscatprintf, sdscpy, sdscpylen, sdscatsds, sdscatlen, sdsgrowzero, sdsIncrLen, sdsAllocSize e sdsAllocPtr.
This functions should check for a parameter with value NULL and possibly return an error code in such case.
Minimal example:
intsdsTest(void) {
sdsx=NULL;
test_cond("Create a string and obtain the length",
sdslen(x) ==3&&memcmp(x,"foo\0",4) ==0)
sdsfree(x);
test_report();
return0;
}
Forcing the variable “sds s = NULL” while running the test programs generates a segmentation fault (due to the attempt to dereference NULL).
The text was updated successfully, but these errors were encountered:
This is not an error, even strlen() from string.h doesn't check for NULL. The rationale behind this design decision is that you cannot check the length of something that doesn't exist.
These functions don't check for NULL because s != NULL is a pre-condition; if, for example, sdslen receives NULL as an argument, I'm pretty sure that it's caller's fault.
Also, making each and every function check for NULL hurts performance, as it causes many (unnecessary) branches.
In many functions in file “sds.h”, the parameter “sds s” is dereferenced without checking if it is NULL. The same error is also present in some functions in file “sds.c”, such as:
sdscat
,sdsMakeRoomFor
,sdsRemoveFreeSpace
,sdsdup
,sdsupdatelen
,sdscatrepr
,sdscmp
,sdstoupper
,sdstolower
,sdsrange
,sdstrim
,sdscatfmt
,sdsclear
,sdslen
,sdscatvprintf
,sdscatprintf
,sdscpy
,sdscpylen
,sdscatsds
,sdscatlen
,sdsgrowzero
,sdsIncrLen
,sdsAllocSize
esdsAllocPtr
.This functions should check for a parameter with value NULL and possibly return an error code in such case.
Minimal example:
Forcing the variable “sds s = NULL” while running the test programs generates a segmentation fault (due to the attempt to dereference NULL).
The text was updated successfully, but these errors were encountered: