Skip to content
This repository has been archived by the owner on Nov 2, 2021. It is now read-only.

mc_strtoll function impl maybe something wrong ? #35

Open
gerryyang opened this issue Oct 31, 2018 · 0 comments
Open

mc_strtoll function impl maybe something wrong ? #35

gerryyang opened this issue Oct 31, 2018 · 0 comments

Comments

@gerryyang
Copy link

gerryyang commented Oct 31, 2018

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;
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant