Skip to content

Commit

Permalink
Merge pull request #480 from cloudQuant/develop
Browse files Browse the repository at this point in the history
fix two bugs about computeHash and roundInputBySignificantFigure
  • Loading branch information
AnthonyFJGarner authored Oct 30, 2024
2 parents 7ed2163 + 585437f commit d1dbbbd
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions include/ccapi_cpp/ccapi_util_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ class UtilString CCAPI_FINAL {
output += ".";
output += c.substr(c.size() + exponent);
} else {
output = std::string(-exponent - c.size() + 1, '0');
output += ".";
output += c;
// output = std::string(-exponent - c.size() + 1, '0');
// output += ".";
// output += c; // use these three code, roundInputBySignificantFigure(0.00123456, 3, 1), output is "000.124"
output = "0.";
output += std::string(-exponent - c.size(), '0');
output += c; // use these three code, roundInputBySignificantFigure(0.00123456, 3, 1), output is "0.00124"
}
return output;
}
Expand Down Expand Up @@ -490,6 +493,8 @@ class UtilAlgorithm CCAPI_FINAL {
EVP_DigestInit_ex(context, EVP_sha512(), NULL);
break;
default:
// Release the context, adding an extra line here to avoid potential memory leaks that may occur in computeHash
EVP_MD_CTX_free(context);
throw std::invalid_argument("invalid shaVersion");
}
EVP_DigestUpdate(context, unhashed.c_str(), unhashed.length());
Expand Down

0 comments on commit d1dbbbd

Please sign in to comment.