4 ms·
I know it's not your code, but related to this comment, it looks like it missing a check for lks == null? https://github.com/robdelacruz/lkwebserver/blob/main/
by dajtxx 3y ago
I know it's not your code, but related to this comment, it looks like it missing a check for lks == null?
https://github.com/robdelacruz/lkwebserver/blob/main/lkstring.c#L47 https://github.com/robdelacruz/lkwebserver/blob/main/lkstrin...
- denotational 3y agoThat assert is checking a library invariant; it should never fail unless there’s a bug in the string library itself (although I’m not entirely sure this string library would tolerate a malloc failure from a quick glance through). This is distinct from checking the parameters; if lks is null then the user of the API has made an error. Some libraries may sanitise user parameters, others don’t. At any rate, an assert would be the wrong choice to check user parameters since this would result in a (recoverable) user error leading to an abort unless the assert is disabled at compile time (-DNDEBUG), returning an error would be a better choice.
- gpderetta 3y agoassert is an acceptable way to deal with precondition failures.
- robdelacruz 3y agoThanks, much of the asserts were scaffolding while I was programming the helper functions. They function similar to comments, reminding me of the internal conditions that should always be valid.