3 ms·
You use sdslen() instead of strlen(). Ditto for everything else. Failure to do so results in subtle bugs.
by jdsully 7y ago
You use sdslen() instead of strlen(). Ditto for everything else. Failure to do so results in subtle bugs.
- CJefferson 7y agoThen (in my opinion) the library shouldn't advertise itself as compatible with Null terminated C strings, as users will assume that means they can use strlen (or more likely, other functions which use strlen themselves). In a similar system I work on, we have a list of functions (like strlen, Strcat), where we carefully vet every occurrence in the code base. It's annoying but the only way to stop subtle bugs we've found.
- jdsully 7y agoRedis doesn’t really have this problem because its mostly developed by Antirez.
- stouset 7y agoThen why bother making these strings superficially compatible with C strings? Just printf or am I missing something?
- jdsully 7y agoThe same reason std::string has the c_str() method. It’s convenient.