Skip to content

Commit

Permalink
Merge pull request #1028 from Barenboim/master
Browse files Browse the repository at this point in the history
Allow leading spaces in inline command
  • Loading branch information
Barenboim authored Aug 26, 2022
2 parents cbe2be4 + b737366 commit 116e677
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
29 changes: 13 additions & 16 deletions src/protocol/redis_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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++)
{
Expand All @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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++;
}
Expand Down Expand Up @@ -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);
}

2 changes: 1 addition & 1 deletion src/protocol/redis_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 116e677

Please sign in to comment.