Fix redisvFormatCommand format parsing

Flags can occur in any order in format string, so we can't assume any order.

In original code, the redisvFormatCommand can process " %#+d" correctly,
but can't process "%+#d".

Closes #257
This commit is contained in:
Nan Xiao 2014-07-18 17:51:06 +08:00 committed by Matt Stancliff
parent 9a753b4251
commit b6a860795c

View File

@ -754,17 +754,14 @@ int redisvFormatCommand(char **target, const char *format, va_list ap) {
/* Try to detect printf format */ /* Try to detect printf format */
{ {
static const char intfmts[] = "diouxX"; static const char intfmts[] = "diouxX";
static const char flags[] = "#0-+ ";
char _format[16]; char _format[16];
const char *_p = c+1; const char *_p = c+1;
size_t _l = 0; size_t _l = 0;
va_list _cpy; va_list _cpy;
/* Flags */ /* Flags */
if (*_p != '\0' && *_p == '#') _p++; while (*_p != '\0' && strchr(flags,*_p) != NULL) _p++;
if (*_p != '\0' && *_p == '0') _p++;
if (*_p != '\0' && *_p == '-') _p++;
if (*_p != '\0' && *_p == ' ') _p++;
if (*_p != '\0' && *_p == '+') _p++;
/* Field width */ /* Field width */
while (*_p != '\0' && isdigit(*_p)) _p++; while (*_p != '\0' && isdigit(*_p)) _p++;