twemcache icon indicating copy to clipboard operation
twemcache copied to clipboard

mc_strtoll function impl maybe something wrong ?

Open gerryyang opened this issue 6 years ago • 0 comments

original codes are from here: https://github.com/twitter/twemcache/blob/master/src/mc_util.c

bool 
mc_strtoll(const char *str, int64_t *out)
{
    char *endptr;
    long long ll;

    errno = 0;
    *out = 0LL;

    ll = std::strtoll(str, &endptr, 10);

    if (errno == ERANGE) {
        return false;
    }

#if 0
    // bug: if str is "123 abc"
    if (isspace(*endptr) || (*endptr == '\0' && endptr != str)) {
        *out = ll;
        return true;
    }
#endif
    
    std::string s(endptr);
    if (std::all_of(s.begin(), s.end(), [](unsigned char c) { return std::isspace(c); }) || *endptr == '\0' && endptr != str) {
        *out = ll;
        return true;
    }
    return false;
}

gerryyang avatar Oct 31 '18 09:10 gerryyang