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. */
| 484 | * returned. Otherwise if the key holds a wrong type NULL is returned and |
| 485 | * an error is sent to the client. */ |
| 486 | robj *lookupStringForBitCommand(client *c, uint64_t maxbit) { |
| 487 | size_t byte = maxbit >> 3; |
| 488 | robj *o = lookupKeyWrite(c->db,c->argv[1]); |
| 489 | if (checkType(c,o,OBJ_STRING)) return NULL; |
| 490 | |
| 491 | if (o == NULL) { |
| 492 | o = createObject(OBJ_STRING,sdsnewlen(NULL, byte+1)); |
| 493 | dbAdd(c->db,c->argv[1],o); |
| 494 | } else { |
| 495 | o = dbUnshareStringValue(c->db,c->argv[1],o); |
| 496 | o->m_ptr = sdsgrowzero(szFromObj(o),byte+1); |
| 497 | } |
| 498 | return o; |
| 499 | } |
| 500 | |
| 501 | /* Return a pointer to the string object content, and stores its length |
| 502 | * in 'len'. The user is required to pass (likely stack allocated) buffer |
no test coverage detected