diff options
Diffstat (limited to 'hiredis.c')
-rw-r--r-- | hiredis.c | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -525,6 +525,7 @@ int redisvFormatCommand(char **target, const char *format, va_list ap) { char *cmd = NULL; /* final command */ int pos; /* position in final command */ sds current; /* current argument */ + int interpolated = 0; /* did we do interpolation on an argument? */ char **argv = NULL; int argc = 0, j; int totlen = 0; @@ -541,6 +542,7 @@ int redisvFormatCommand(char **target, const char *format, va_list ap) { if (sdslen(current) != 0) { addArgument(current, &argv, &argc, &totlen); current = sdsempty(); + interpolated = 0; } } else { current = sdscatlen(current,c,1); @@ -549,12 +551,17 @@ int redisvFormatCommand(char **target, const char *format, va_list ap) { switch(c[1]) { case 's': arg = va_arg(ap,char*); - current = sdscat(current,arg); + size = strlen(arg); + if (size > 0) + current = sdscatlen(current,arg,size); + interpolated = 1; break; case 'b': arg = va_arg(ap,char*); size = va_arg(ap,size_t); - current = sdscatlen(current,arg,size); + if (size > 0) + current = sdscatlen(current,arg,size); + interpolated = 1; break; case '%': cmd = sdscat(cmd,"%"); @@ -566,7 +573,7 @@ int redisvFormatCommand(char **target, const char *format, va_list ap) { } /* Add the last argument if needed */ - if (sdslen(current) != 0) { + if (interpolated || sdslen(current) != 0) { addArgument(current, &argv, &argc, &totlen); } else { sdsfree(current); |