From 4e7a7d16561bf6a8334a2521235d82a141a5061f Mon Sep 17 00:00:00 2001 From: Jose Angel Gariburo <563580@gmail.com> Date: Thu, 26 Oct 2017 16:06:43 +0200 Subject: [PATCH] Minor performance and memory issues fixed. --- src/GZipFile.cc | 6 +++++- src/LongestSequencePieceSelector.cc | 2 +- src/Netrc.cc | 6 +++--- src/OptionHandlerImpl.cc | 4 ++-- src/Sqlite3CookieParser.cc | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/GZipFile.cc b/src/GZipFile.cc index 80ef10ee..c665c3df 100644 --- a/src/GZipFile.cc +++ b/src/GZipFile.cc @@ -158,7 +158,11 @@ int GZipFile::onVprintf(const char* format, va_list va) while (static_cast(buflen_) < len) { buflen_ *= 2; } - buf_ = reinterpret_cast(realloc(buf_, buflen_)); + char* buf = reinterpret_cast(realloc(buf_, buflen_)); + if (!buf) { + return -1; + } + buf_ = buf; } else if (len < 0) { return len; diff --git a/src/LongestSequencePieceSelector.cc b/src/LongestSequencePieceSelector.cc index 5686ad6b..2f6d5f19 100644 --- a/src/LongestSequencePieceSelector.cc +++ b/src/LongestSequencePieceSelector.cc @@ -81,7 +81,7 @@ bool LongestSequencePieceSelector::select(size_t& index, } nextIndex = endindex; } - if (mendindex - mstartindex > 0) { + if (mendindex != mstartindex) { index = mendindex - 1; return true; } diff --git a/src/Netrc.cc b/src/Netrc.cc index 005f3162..3daeafff 100644 --- a/src/Netrc.cc +++ b/src/Netrc.cc @@ -168,12 +168,12 @@ void Netrc::parse(const std::string& path) iter != eoi; ++iter) { if (state == GET_TOKEN) { if (util::streq((*iter).first, (*iter).second, "machine")) { - storeAuthenticator(std::move(authenticator)); + storeAuthenticator(authenticator); authenticator = make_unique(); state = SET_MACHINE; } else if (util::streq((*iter).first, (*iter).second, "default")) { - storeAuthenticator(std::move(authenticator)); + storeAuthenticator(authenticator); authenticator = make_unique(); } else { @@ -220,7 +220,7 @@ void Netrc::parse(const std::string& path) if (state != GET_TOKEN) { throw DL_ABORT_EX("Netrc:parse error. EOF reached where a token expected."); } - storeAuthenticator(std::move(authenticator)); + storeAuthenticator(authenticator); } void Netrc::storeAuthenticator(std::unique_ptr authenticator) diff --git a/src/OptionHandlerImpl.cc b/src/OptionHandlerImpl.cc index 6214e84b..e4c3cddf 100644 --- a/src/OptionHandlerImpl.cc +++ b/src/OptionHandlerImpl.cc @@ -638,8 +638,8 @@ void OptimizeConcurrentDownloadsOptionHandler::parseArg( for (;;) { char* end; errno = 0; - strtod(sptr->c_str(), &end); - if (errno != 0 || sptr->c_str() + sptr->size() != end) { + double result = strtod(sptr->c_str(), &end); + if (errno == ERANGE || result == 0.0) { throw DL_ABORT_EX(fmt("Bad number '%s'", sptr->c_str())); } option.put(pref, *sptr); diff --git a/src/Sqlite3CookieParser.cc b/src/Sqlite3CookieParser.cc index 91cb4270..111b4d8d 100644 --- a/src/Sqlite3CookieParser.cc +++ b/src/Sqlite3CookieParser.cc @@ -129,7 +129,7 @@ int cookieRowMapper(void* data, int columns, char** values, char** names) expiryTime, true, // persistent std::move(cookieDomain), - numericHost || (values[0] && values[0][0] != '.'), // hostOnly + numericHost || values[0][0] != '.', // hostOnly std::move(cookiePath), values[2] && strcmp(values[2], "1") == 0, // secure false, lastAccessTime // creation time. Set this later.