Adopt explicit, consistent nullability contracts for pointer/optional-field parameters and honor them at every call site.
Practical rules:
get*From*Object patterns) so developers don’t guess whether NULL is legal.if (obj->field) { use }).no_value; pass/handle the correct canonical value (NULL for absent value).memcpy(dst,NULL,n>0)), enforce the precondition at call sites.Example pattern:
/* Optional pointer is truly nullable; guard before use */
if (nack->consumer) {
addReplyBulkCBuffer(c, nack->consumer->name,
sdslen(nack->consumer->name));
} else {
addReplyBulkCBuffer(c, "", 0);
}
/* Dict configured with no_value: never read dictGetVal() */
if (dictAdd(dst, key, NULL) == DICT_OK) {
/* ... */
}
This standard prevents ambiguous NULL expectations, avoids undefined behavior, and keeps null-safety practical instead of scattered defensive code.
Enter the URL of a public GitHub repository