Commit 13f18d2b authored by antirez's avatar antirez
Browse files

Modules: handle NULL replies more gracefully.

After all crashing at every API misuse makes everybody's life more
complex.
parent a81a92ca
...@@ -762,6 +762,11 @@ void RM_RetainString(RedisModuleCtx *ctx, RedisModuleString *str) { ...@@ -762,6 +762,11 @@ void RM_RetainString(RedisModuleCtx *ctx, RedisModuleString *str) {
* and length of the string. The returned pointer and length should only * and length of the string. The returned pointer and length should only
* be used for read only accesses and never modified. */ * be used for read only accesses and never modified. */
const char *RM_StringPtrLen(const RedisModuleString *str, size_t *len) { const char *RM_StringPtrLen(const RedisModuleString *str, size_t *len) {
if (str == NULL) {
const char *errmsg = "(NULL string reply referenced in module)";
if (len) *len = strlen(errmsg);
return errmsg;
}
if (len) *len = sdslen(str->ptr); if (len) *len = sdslen(str->ptr);
return str->ptr; return str->ptr;
} }
...@@ -2203,6 +2208,7 @@ void RM_FreeCallReply(RedisModuleCallReply *reply) { ...@@ -2203,6 +2208,7 @@ void RM_FreeCallReply(RedisModuleCallReply *reply) {
/* Return the reply type. */ /* Return the reply type. */
int RM_CallReplyType(RedisModuleCallReply *reply) { int RM_CallReplyType(RedisModuleCallReply *reply) {
if (!reply) return REDISMODULE_REPLY_UNKNOWN;
return reply->type; return reply->type;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment