Repository: valkey-io/valkey
File: src/sds.c (C)

Code before:
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    case 'a':
    case 'A': return 10;
    case 'b':
    case 'B': return 11;
    case 'c':
    case 'C': return 12;
    case 'd':
    case 'D': return 13;
    case 'e':
    case 'E': return 14;
    case 'f':
    case 'F': return 15;
    default: return 0;
    }
}

static inline bool is_ptr_exceeds_end(const char *ptr, size_t len, const char *end) {
    if (end == NULL) {
        return false;
    }
    return (ptr + len) >= end;
}

/* Helper function for sdssplitargs that parses a single argument. It
 * populates the number characters needed to store the parsed argument
 * in len, if provided, or will copy the parsed string into dst, if provided.
 * If the string is able to be parsed, this function returns the number of
 * characters that were parsed. If the argument can't be parsed, it
 * returns 0. */
static int sdsparsearg(const char *arg, const char *end, unsigned int *len, char *dst) {
    const char *p = arg;
    int inq = 0;  /* set to 1 if we are in "quotes" */
    int insq = 0; /* set to 1 if we are in 'single quotes' */
    int done = 0;

    if (is_ptr_exceeds_end(p, 0, end)) {
        return 0;
    }

    while (!done) {
        int new_char = -1;
        if (inq) {

Review comment (bug):
We don't use underscore style (snake case) in function names. Use camelCase instead. (For the public sds functions we use just lowercase and "sds" prefix, but this is internal so I think camelCase and no sds prefix is better.)

Also "is exceeds" is incorrect grammar. Better is "is exceeding".

```suggestion
static inline bool isPtrExceedingEnd(const char *ptr, size_t len, const char *end) {
```

Code after:
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    case 'a':
    case 'A': return 10;
    case 'b':
    case 'B': return 11;
    case 'c':
    case 'C': return 12;
    case 'd':
    case 'D': return 13;
    case 'e':
    case 'E': return 14;
    case 'f':
    case 'F': return 15;
    default: return 0;
    }
}

static inline bool isPtrExceedingEnd(const char *ptr, size_t len, const char *end) {
    if (end == NULL) {
        return false;
    }
    return (ptr + len) >= end;
}

/* Helper function for sdssplitargs that parses a single argument. It
 * populates the number characters needed to store the parsed argument
 * in len, if provided, or will copy the parsed string into dst, if provided.
 * If the string is able to be parsed, this function returns the number of
 * characters that were parsed. If the argument can't be parsed, it
 * returns 0. */
static int sdsparsearg(const char *arg, const char *end, unsigned int *len, char *dst) {
    const char *p = arg;
    int inq = 0;  /* set to 1 if we are in "quotes" */
    int insq = 0; /* set to 1 if we are in 'single quotes' */
    int done = 0;

    if (isPtrExceedingEnd(p, 0, end)) {
        return 0;
    }

    while (!done) {
        int new_char = -1;
        if (inq) {