Skip to content

Commit 116e677

Browse files
authored
Merge pull request #1028 from Barenboim/master
Allow leading spaces in inline command
2 parents cbe2be4 + b737366 commit 116e677

2 files changed

Lines changed: 14 additions & 17 deletions

File tree

src/protocol/redis_parser.c

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ static int __redis_parse_lf(const char ch, redis_parser_t *parser)
145145

146146
static int __redis_parse_line(redis_parser_t *parser)
147147
{
148-
char *buf = (char *)parser->msgbuf;
149-
char *str = buf + parser->msgidx;
148+
char *str = parser->msgbuf + parser->msgidx;
150149
size_t slen = parser->findidx - parser->msgidx;
151150
char data[32];
152151
int i, n;
@@ -238,7 +237,7 @@ static int __redis_parse_line(redis_parser_t *parser)
238237

239238
static int __redis_parse_crlf(redis_parser_t *parser)
240239
{
241-
char *buf = (char *)parser->msgbuf;
240+
char *buf = parser->msgbuf;
242241

243242
for (; parser->findidx + 1 < parser->msgsize; parser->findidx++)
244243
{
@@ -251,8 +250,6 @@ static int __redis_parse_crlf(redis_parser_t *parser)
251250

252251
static int __redis_parse_nchar(redis_parser_t *parser)
253252
{
254-
//char *buf = (char *)parser->msgbuf;
255-
256253
if (parser->nchar <= parser->msgsize - parser->msgidx)
257254
{
258255
redis_reply_set_string((const char *)parser->msgidx, parser->nchar,
@@ -269,7 +266,7 @@ static int __redis_parse_nchar(redis_parser_t *parser)
269266
//-1 error | 0 continue | 1 finish-one | 2 not-enough
270267
static int __redis_parser_forward(redis_parser_t *parser)
271268
{
272-
char *buf = (char *)parser->msgbuf;
269+
char *buf = parser->msgbuf;
273270

274271
if (parser->msgidx >= parser->msgsize)
275272
return 2;
@@ -363,11 +360,11 @@ static int __redis_parse_done(redis_reply_t *reply, char *buf, int depth)
363360

364361
static int __redis_split_inline_command(redis_parser_t *parser)
365362
{
366-
const char *msg = (const char *)parser->msgbuf;
367-
const char *end = msg + parser->msgsize;
363+
char *msg = parser->msgbuf;
364+
char *end = msg + parser->msgsize;
368365
size_t arr_size = 0;
369366
redis_reply_t **ele;
370-
const char *cur;
367+
char *cur;
371368
int ret;
372369

373370
while (msg != end)
@@ -396,7 +393,7 @@ static int __redis_split_inline_command(redis_parser_t *parser)
396393
return ret;
397394

398395
ele = parser->reply.element;
399-
msg = (const char *)parser->msgbuf;
396+
msg = parser->msgbuf;
400397

401398
while (msg != end)
402399
{
@@ -443,17 +440,17 @@ int redis_parser_append_message(const void *buf, size_t *size,
443440
if (!new_base)
444441
return -1;
445442

446-
parser->msgbuf = new_base;
443+
parser->msgbuf = (char *)new_base;
447444
parser->bufsize = new_size;
448445
}
449446

450-
memcpy((char *)parser->msgbuf + parser->msgsize, buf, *size);
447+
memcpy(parser->msgbuf + parser->msgsize, buf, *size);
451448
parser->msgsize += *size;
452-
453-
if (parser->msgsize && isalpha(*(const char *)parser->msgbuf))
449+
if (parser->msgsize > 0 && (isalpha(*parser->msgbuf) ||
450+
isspace(*parser->msgbuf)))
454451
{
455452
while (parser->msgidx < parser->msgsize &&
456-
*((const char *)parser->msgbuf + parser->msgidx) != '\n')
453+
*(parser->msgbuf + parser->msgidx) != '\n')
457454
{
458455
parser->msgidx++;
459456
}
@@ -503,6 +500,6 @@ int redis_parser_append_message(const void *buf, size_t *size,
503500
} while (parser->status != REDIS_PARSE_END);
504501

505502
*size = parser->msgidx - msgsize_bak;
506-
return __redis_parse_done(&parser->reply, (char *)parser->msgbuf, 0);
503+
return __redis_parse_done(&parser->reply, parser->msgbuf, 0);
507504
}
508505

src/protocol/redis_parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ typedef struct __redis_parser
4545
{
4646
int parse_succ;//check first
4747
int status;
48-
void *msgbuf;
48+
char *msgbuf;
4949
size_t msgsize;
5050
size_t bufsize;
5151
redis_reply_t *cur;

0 commit comments

Comments
 (0)