This helper function used by GETBIT / SETBIT parses the bit offset argument * making sure an error is returned if it is negative or if it overflows * Redis 512 MB limit for the string value or more (server.proto_max_bulk_len). * * If the 'hash' argument is true, and 'bits is positive, then the command * will also parse bit offsets prefixed by "#". In such a case the offset * is multiplied by
| 411 | * will also parse bit offsets prefixed by "#". In such a case the offset |
| 412 | * is multiplied by 'bits'. This is useful for the BITFIELD command. */ |
| 413 | int getBitOffsetFromArgument(client *c, robj *o, uint64_t *offset, int hash, int bits) { |
| 414 | long long loffset; |
| 415 | char *err = "bit offset is not an integer or out of range"; |
| 416 | char *p = o->ptr; |
| 417 | size_t plen = sdslen(p); |
| 418 | int usehash = 0; |
| 419 | |
| 420 | /* Handle #<offset> form. */ |
| 421 | if (p[0] == '#' && hash && bits > 0) usehash = 1; |
| 422 | |
| 423 | if (string2ll(p+usehash,plen-usehash,&loffset) == 0) { |
| 424 | addReplyError(c,err); |
| 425 | return C_ERR; |
| 426 | } |
| 427 | |
| 428 | /* Adjust the offset by 'bits' for #<offset> form. */ |
| 429 | if (usehash) loffset *= bits; |
| 430 | |
| 431 | /* Limit offset to server.proto_max_bulk_len (512MB in bytes by default) */ |
| 432 | if ((loffset < 0) || (loffset >> 3) >= server.proto_max_bulk_len) |
| 433 | { |
| 434 | addReplyError(c,err); |
| 435 | return C_ERR; |
| 436 | } |
| 437 | |
| 438 | *offset = loffset; |
| 439 | return C_OK; |
| 440 | } |
| 441 | |
| 442 | /* This helper function for BITFIELD parses a bitfield type in the form |
| 443 | * <sign><bits> where sign is 'u' or 'i' for unsigned and signed, and |
no test coverage detected