summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNan Xiao <xn212516@163.com>2014-07-18 17:51:06 +0800
committerMatt Stancliff <matt@genges.com>2015-01-05 16:39:30 -0500
commitb6a860795c0c97c59c79155640531b8c47c34ea3 (patch)
treefed5f991d2deb91ff5c21e66a4dfff9d7d533651
parent9a753b42519a6d0f1998ff5b1c09e63fcc72749a (diff)
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
-rw-r--r--hiredis.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/hiredis.c b/hiredis.c
index 3a70e1d..10ac8d0 100644
--- a/hiredis.c
+++ b/hiredis.c
@@ -754,17 +754,14 @@ int redisvFormatCommand(char **target, const char *format, va_list ap) {
/* Try to detect printf format */
{
static const char intfmts[] = "diouxX";
+ static const char flags[] = "#0-+ ";
char _format[16];
const char *_p = c+1;
size_t _l = 0;
va_list _cpy;
/* Flags */
- if (*_p != '\0' && *_p == '#') _p++;
- if (*_p != '\0' && *_p == '0') _p++;
- if (*_p != '\0' && *_p == '-') _p++;
- if (*_p != '\0' && *_p == ' ') _p++;
- if (*_p != '\0' && *_p == '+') _p++;
+ while (*_p != '\0' && strchr(flags,*_p) != NULL) _p++;
/* Field width */
while (*_p != '\0' && isdigit(*_p)) _p++;