diff --git a/src/v3/Action.cpp b/src/v3/Action.cpp index 1bcfed3..463bd31 100644 --- a/src/v3/Action.cpp +++ b/src/v3/Action.cpp @@ -40,16 +40,14 @@ const std::chrono::high_resolution_clock::time_point etcdv3::Action::startTimepo } std::string etcdv3::detail::string_plus_one(std::string const &value) { - // referred from the Go implementation in etcd. - char *s = static_cast(calloc(value.size() + 1, sizeof(char))); - std::memcpy(s, value.c_str(), value.size()); - for (int i = value.size() - 1; i >= 0; --i) { - if (static_cast(s[i]) < 0xff) { + // Referred from the Go implementation in etcd. + for (int32_t i = value.size() - 1; i >= 0; --i) { + if (static_cast(value[i]) < 0xff) { + std::string s = value.substr(0, i + 1); s[i] = s[i] + 1; - std::string ret = std::string(s, i + 1); - free(s); - return ret; + return s; } } + return {etcdv3::NUL}; }