Load an LZF compressed string in RDB format. The returned value * changes according to 'flags'. For more info check the * rdbGenericLoadStringObject() function. */
| 388 | * changes according to 'flags'. For more info check the |
| 389 | * rdbGenericLoadStringObject() function. */ |
| 390 | void *rdbLoadLzfStringObject(rio *rdb, int flags, size_t *lenptr) { |
| 391 | int plain = flags & RDB_LOAD_PLAIN; |
| 392 | int sds = flags & RDB_LOAD_SDS; |
| 393 | uint64_t len, clen; |
| 394 | unsigned char *c = NULL; |
| 395 | char *val = NULL; |
| 396 | |
| 397 | if ((clen = rdbLoadLen(rdb,NULL)) == RDB_LENERR) return NULL; |
| 398 | if ((len = rdbLoadLen(rdb,NULL)) == RDB_LENERR) return NULL; |
| 399 | if ((c = (unsigned char*)ztrymalloc(clen)) == NULL) { |
| 400 | serverLog(g_pserver->loading? LL_WARNING: LL_VERBOSE, "rdbLoadLzfStringObject failed allocating %llu bytes", (unsigned long long)clen); |
| 401 | goto err; |
| 402 | } |
| 403 | |
| 404 | /* Allocate our target according to the uncompressed size. */ |
| 405 | if (plain) { |
| 406 | val = (char*)ztrymalloc(len); |
| 407 | } else { |
| 408 | val = sdstrynewlen(SDS_NOINIT,len); |
| 409 | } |
| 410 | if (!val) { |
| 411 | serverLog(g_pserver->loading? LL_WARNING: LL_VERBOSE, "rdbLoadLzfStringObject failed allocating %llu bytes", (unsigned long long)len); |
| 412 | goto err; |
| 413 | } |
| 414 | |
| 415 | if (lenptr) *lenptr = len; |
| 416 | |
| 417 | /* Load the compressed representation and uncompress it to target. */ |
| 418 | if (rioRead(rdb,c,clen) == 0) goto err; |
| 419 | if (lzf_decompress(c,clen,val,len) != len) { |
| 420 | rdbReportCorruptRDB("Invalid LZF compressed string"); |
| 421 | goto err; |
| 422 | } |
| 423 | zfree(c); |
| 424 | |
| 425 | if (plain || sds) { |
| 426 | return val; |
| 427 | } else { |
| 428 | return createObject(OBJ_STRING,val); |
| 429 | } |
| 430 | err: |
| 431 | zfree(c); |
| 432 | if (plain) |
| 433 | zfree(val); |
| 434 | else |
| 435 | sdsfree(val); |
| 436 | return NULL; |
| 437 | } |
| 438 | |
| 439 | /* Save a string object as [len][data] on disk. If the object is a string |
| 440 | * representation of an integer value we try to save it in a special form */ |
no test coverage detected