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

mc_strtoll function impl maybe something wrong ? #35

Description

@gerryyang

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;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions