diff --git a/src/protocol/redis_parser.c b/src/protocol/redis_parser.c index 6ca52efefb..e18a0e7f11 100644 --- a/src/protocol/redis_parser.c +++ b/src/protocol/redis_parser.c @@ -145,8 +145,7 @@ static int __redis_parse_lf(const char ch, redis_parser_t *parser) static int __redis_parse_line(redis_parser_t *parser) { - char *buf = (char *)parser->msgbuf; - char *str = buf + parser->msgidx; + char *str = parser->msgbuf + parser->msgidx; size_t slen = parser->findidx - parser->msgidx; char data[32]; int i, n; @@ -238,7 +237,7 @@ static int __redis_parse_line(redis_parser_t *parser) static int __redis_parse_crlf(redis_parser_t *parser) { - char *buf = (char *)parser->msgbuf; + char *buf = parser->msgbuf; for (; parser->findidx + 1 < parser->msgsize; parser->findidx++) { @@ -251,8 +250,6 @@ static int __redis_parse_crlf(redis_parser_t *parser) static int __redis_parse_nchar(redis_parser_t *parser) { - //char *buf = (char *)parser->msgbuf; - if (parser->nchar <= parser->msgsize - parser->msgidx) { redis_reply_set_string((const char *)parser->msgidx, parser->nchar, @@ -269,7 +266,7 @@ static int __redis_parse_nchar(redis_parser_t *parser) //-1 error | 0 continue | 1 finish-one | 2 not-enough static int __redis_parser_forward(redis_parser_t *parser) { - char *buf = (char *)parser->msgbuf; + char *buf = parser->msgbuf; if (parser->msgidx >= parser->msgsize) return 2; @@ -363,11 +360,11 @@ static int __redis_parse_done(redis_reply_t *reply, char *buf, int depth) static int __redis_split_inline_command(redis_parser_t *parser) { - const char *msg = (const char *)parser->msgbuf; - const char *end = msg + parser->msgsize; + char *msg = parser->msgbuf; + char *end = msg + parser->msgsize; size_t arr_size = 0; redis_reply_t **ele; - const char *cur; + char *cur; int ret; while (msg != end) @@ -396,7 +393,7 @@ static int __redis_split_inline_command(redis_parser_t *parser) return ret; ele = parser->reply.element; - msg = (const char *)parser->msgbuf; + msg = parser->msgbuf; while (msg != end) { @@ -443,17 +440,17 @@ int redis_parser_append_message(const void *buf, size_t *size, if (!new_base) return -1; - parser->msgbuf = new_base; + parser->msgbuf = (char *)new_base; parser->bufsize = new_size; } - memcpy((char *)parser->msgbuf + parser->msgsize, buf, *size); + memcpy(parser->msgbuf + parser->msgsize, buf, *size); parser->msgsize += *size; - - if (parser->msgsize && isalpha(*(const char *)parser->msgbuf)) + if (parser->msgsize > 0 && (isalpha(*parser->msgbuf) || + isspace(*parser->msgbuf))) { while (parser->msgidx < parser->msgsize && - *((const char *)parser->msgbuf + parser->msgidx) != '\n') + *(parser->msgbuf + parser->msgidx) != '\n') { parser->msgidx++; } @@ -503,6 +500,6 @@ int redis_parser_append_message(const void *buf, size_t *size, } while (parser->status != REDIS_PARSE_END); *size = parser->msgidx - msgsize_bak; - return __redis_parse_done(&parser->reply, (char *)parser->msgbuf, 0); + return __redis_parse_done(&parser->reply, parser->msgbuf, 0); } diff --git a/src/protocol/redis_parser.h b/src/protocol/redis_parser.h index dcb6cf499a..29e6188e22 100644 --- a/src/protocol/redis_parser.h +++ b/src/protocol/redis_parser.h @@ -45,7 +45,7 @@ typedef struct __redis_parser { int parse_succ;//check first int status; - void *msgbuf; + char *msgbuf; size_t msgsize; size_t bufsize; redis_reply_t *cur;