This is an helper function for commands implementations that need to write * bits to a string object. The command creates or pad with zeroes the string * so that the 'maxbit' bit can be addressed. The object is finally * returned. Otherwise if the key holds a wrong type NULL is returned and * an error is sent to the client. */
| 478 | * returned. Otherwise if the key holds a wrong type NULL is returned and |
| 479 | * an error is sent to the client. */ |
| 480 | robj *lookupStringForBitCommand(client *c, uint64_t maxbit) { |
| 481 | size_t byte = maxbit >> 3; |
| 482 | robj *o = lookupKeyWrite(c->db,c->argv[1]); |
| 483 | if (checkType(c,o,OBJ_STRING)) return NULL; |
| 484 | |
| 485 | if (o == NULL) { |
| 486 | o = createObject(OBJ_STRING,sdsnewlen(NULL, byte+1)); |
| 487 | dbAdd(c->db,c->argv[1],o); |
| 488 | } else { |
| 489 | o = dbUnshareStringValue(c->db,c->argv[1],o); |
| 490 | o->ptr = sdsgrowzero(o->ptr,byte+1); |
| 491 | } |
| 492 | return o; |
| 493 | } |
| 494 | |
| 495 | /* Return a pointer to the string object content, and stores its length |
| 496 | * in 'len'. The user is required to pass (likely stack allocated) buffer |
no test coverage detected