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
| 417 | * will also parse bit offsets prefixed by "#". In such a case the offset |
| 418 | * is multiplied by 'bits'. This is useful for the BITFIELD command. */ |
| 419 | int getBitOffsetFromArgument(client *c, robj *o, uint64_t *offset, int hash, int bits) { |
| 420 | long long loffset; |
| 421 | const char *err = "bit offset is not an integer or out of range"; |
| 422 | char *p = szFromObj(o); |
| 423 | size_t plen = sdslen(p); |
| 424 | int usehash = 0; |
| 425 | |
| 426 | /* Handle #<offset> form. */ |
| 427 | if (p[0] == '#' && hash && bits > 0) usehash = 1; |
| 428 | |
| 429 | if (string2ll(p+usehash,plen-usehash,&loffset) == 0) { |
| 430 | addReplyError(c,err); |
| 431 | return C_ERR; |
| 432 | } |
| 433 | |
| 434 | /* Adjust the offset by 'bits' for #<offset> form. */ |
| 435 | if (usehash) loffset *= bits; |
| 436 | |
| 437 | /* Limit offset to server.proto_max_bulk_len (512MB in bytes by default) */ |
| 438 | if ((loffset < 0) || (loffset >> 3) >= g_pserver->proto_max_bulk_len) |
| 439 | { |
| 440 | addReplyError(c,err); |
| 441 | return C_ERR; |
| 442 | } |
| 443 | |
| 444 | *offset = loffset; |
| 445 | return C_OK; |
| 446 | } |
| 447 | |
| 448 | /* This helper function for BITFIELD parses a bitfield type in the form |
| 449 | * <sign><bits> where sign is 'u' or 'i' for unsigned and signed, and |
no test coverage detected