MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / redisvFormatCommand

Function redisvFormatCommand

deps/hiredis/hiredis.c:306–534  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

304}
305
306int redisvFormatCommand(char **target, const char *format, va_list ap) {
307 const char *c = format;
308 char *cmd = NULL; /* final command */
309 int pos; /* position in final command */
310 hisds curarg, newarg; /* current argument */
311 int touched = 0; /* was the current argument touched? */
312 char **curargv = NULL, **newargv = NULL;
313 int argc = 0;
314 int totlen = 0;
315 int error_type = 0; /* 0 = no error; -1 = memory error; -2 = format error */
316 int j;
317
318 /* Abort if there is not target to set */
319 if (target == NULL)
320 return -1;
321
322 /* Build the command string accordingly to protocol */
323 curarg = hi_sdsempty();
324 if (curarg == NULL)
325 return -1;
326
327 while(*c != '\0') {
328 if (*c != '%' || c[1] == '\0') {
329 if (*c == ' ') {
330 if (touched) {
331 newargv = hi_realloc(curargv,sizeof(char*)*(argc+1));
332 if (newargv == NULL) goto memory_err;
333 curargv = newargv;
334 curargv[argc++] = curarg;
335 totlen += bulklen(hi_sdslen(curarg));
336
337 /* curarg is put in argv so it can be overwritten. */
338 curarg = hi_sdsempty();
339 if (curarg == NULL) goto memory_err;
340 touched = 0;
341 }
342 } else {
343 newarg = hi_sdscatlen(curarg,c,1);
344 if (newarg == NULL) goto memory_err;
345 curarg = newarg;
346 touched = 1;
347 }
348 } else {
349 char *arg;
350 size_t size;
351
352 /* Set newarg so it can be checked even if it is not touched. */
353 newarg = curarg;
354
355 switch(c[1]) {
356 case 's':
357 arg = va_arg(ap,char*);
358 size = strlen(arg);
359 if (size > 0)
360 newarg = hi_sdscatlen(curarg,arg,size);
361 break;
362 case 'b':
363 arg = va_arg(ap,char*);

Callers 3

redisFormatCommandFunction · 0.85
redisvAppendCommandFunction · 0.85
redisvAsyncCommandFunction · 0.85

Calls 11

hi_sdsemptyFunction · 0.85
bulklenFunction · 0.85
hi_sdslenFunction · 0.85
hi_sdscatvprintfFunction · 0.85
hi_sdsfreeFunction · 0.85
countDigitsFunction · 0.85
hi_reallocFunction · 0.70
hi_sdscatlenFunction · 0.70
hi_sdscatFunction · 0.70
hi_mallocFunction · 0.70
hi_freeFunction · 0.70

Tested by

no test coverage detected