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

Function processAggregateItem

deps/hiredis/read.c:449–526  ·  view source on GitHub ↗

Process the array, map and set types. */

Source from the content-addressed store, hash-verified

447
448/* Process the array, map and set types. */
449static int processAggregateItem(redisReader *r) {
450 redisReadTask *cur = r->task[r->ridx];
451 void *obj;
452 char *p;
453 long long elements;
454 int root = 0, len;
455
456 /* Set error for nested multi bulks with depth > 7 */
457 if (r->ridx == r->tasks - 1) {
458 if (redisReaderGrow(r) == REDIS_ERR)
459 return REDIS_ERR;
460 }
461
462 if ((p = readLine(r,&len)) != NULL) {
463 if (string2ll(p, len, &elements) == REDIS_ERR) {
464 __redisReaderSetError(r,REDIS_ERR_PROTOCOL,
465 "Bad multi-bulk length");
466 return REDIS_ERR;
467 }
468
469 root = (r->ridx == 0);
470
471 if (elements < -1 || (LLONG_MAX > SIZE_MAX && elements > SIZE_MAX) ||
472 (r->maxelements > 0 && elements > r->maxelements))
473 {
474 __redisReaderSetError(r,REDIS_ERR_PROTOCOL,
475 "Multi-bulk length out of range");
476 return REDIS_ERR;
477 }
478
479 if (elements == -1) {
480 if (r->fn && r->fn->createNil)
481 obj = r->fn->createNil(cur);
482 else
483 obj = (void*)REDIS_REPLY_NIL;
484
485 if (obj == NULL) {
486 __redisReaderSetErrorOOM(r);
487 return REDIS_ERR;
488 }
489
490 moveToNextTask(r);
491 } else {
492 if (cur->type == REDIS_REPLY_MAP) elements *= 2;
493
494 if (r->fn && r->fn->createArray)
495 obj = r->fn->createArray(cur,elements);
496 else
497 obj = (void*)(long)cur->type;
498
499 if (obj == NULL) {
500 __redisReaderSetErrorOOM(r);
501 return REDIS_ERR;
502 }
503
504 /* Modify task stack when there are more than 0 elements. */
505 if (elements > 0) {
506 cur->elements = elements;

Callers 1

processItemFunction · 0.85

Calls 6

redisReaderGrowFunction · 0.85
readLineFunction · 0.85
__redisReaderSetErrorFunction · 0.85
__redisReaderSetErrorOOMFunction · 0.85
moveToNextTaskFunction · 0.85
string2llFunction · 0.70

Tested by

no test coverage detected