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

Function processBulkItem

deps/hiredis/read.c:351–421  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

349}
350
351static int processBulkItem(redisReader *r) {
352 redisReadTask *cur = r->task[r->ridx];
353 void *obj = NULL;
354 char *p, *s;
355 long long len;
356 unsigned long bytelen;
357 int success = 0;
358
359 p = r->buf+r->pos;
360 s = seekNewline(p,r->len-r->pos);
361 if (s != NULL) {
362 p = r->buf+r->pos;
363 bytelen = s-(r->buf+r->pos)+2; /* include \r\n */
364
365 if (string2ll(p, bytelen - 2, &len) == REDIS_ERR) {
366 __redisReaderSetError(r,REDIS_ERR_PROTOCOL,
367 "Bad bulk string length");
368 return REDIS_ERR;
369 }
370
371 if (len < -1 || (LLONG_MAX > SIZE_MAX && len > (long long)SIZE_MAX)) {
372 __redisReaderSetError(r,REDIS_ERR_PROTOCOL,
373 "Bulk string length out of range");
374 return REDIS_ERR;
375 }
376
377 if (len == -1) {
378 /* The nil object can always be created. */
379 if (r->fn && r->fn->createNil)
380 obj = r->fn->createNil(cur);
381 else
382 obj = (void*)REDIS_REPLY_NIL;
383 success = 1;
384 } else {
385 /* Only continue when the buffer contains the entire bulk item. */
386 bytelen += len+2; /* include \r\n */
387 if (r->pos+bytelen <= r->len) {
388 if ((cur->type == REDIS_REPLY_VERB && len < 4) ||
389 (cur->type == REDIS_REPLY_VERB && s[5] != ':'))
390 {
391 __redisReaderSetError(r,REDIS_ERR_PROTOCOL,
392 "Verbatim string 4 bytes of content type are "
393 "missing or incorrectly encoded.");
394 return REDIS_ERR;
395 }
396 if (r->fn && r->fn->createString)
397 obj = r->fn->createString(cur,s+2,len);
398 else
399 obj = (void*)(long)cur->type;
400 success = 1;
401 }
402 }
403
404 /* Proceed when obj was created. */
405 if (success) {
406 if (obj == NULL) {
407 __redisReaderSetErrorOOM(r);
408 return REDIS_ERR;

Callers 1

processItemFunction · 0.85

Calls 5

seekNewlineFunction · 0.85
__redisReaderSetErrorFunction · 0.85
__redisReaderSetErrorOOMFunction · 0.85
moveToNextTaskFunction · 0.85
string2llFunction · 0.70

Tested by

no test coverage detected