From b28dbef59dcbf976822f2ff86d67af372b92d11a Mon Sep 17 00:00:00 2001 From: Hongcai Ren Date: Wed, 22 Dec 2021 16:00:21 +0800 Subject: [PATCH] There is mismach between function sdssplitlen() comments and implementation (#4909) when count is 0, return NULL --- src/sds.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/sds.c b/src/sds.c index 280f3ded82..a625c66b7f 100644 --- a/src/sds.c +++ b/src/sds.c @@ -939,15 +939,13 @@ sds *sdssplitlen(const char *s, ssize_t len, const char *sep, int seplen, int *c long start = 0, j; sds *tokens; - if (seplen < 1 || len < 0) return NULL; - + if (seplen < 1 || len <= 0) { + *count = 0; + return NULL; + } tokens = s_malloc(sizeof(sds)*slots); if (tokens == NULL) return NULL; - if (len == 0) { - *count = 0; - return tokens; - } for (j = 0; j < (len-(seplen-1)); j++) { /* make sure there is room for the next element and the final one */ if (slots < elements+2) {