Skip to content
Snippets Groups Projects
Commit 1fafef0f authored by David Smith's avatar David Smith
Browse files

In PostgresStmt, add a bounds check and clarifying comment

parent ae2d25bb
No related branches found
No related tags found
No related merge requests found
......@@ -80,9 +80,15 @@ void PostgresStmt::bindOptionalString(const std::string &paramName, const option
}
const unsigned int paramIdx = getParamIdx(paramName); // starts from 1.
if (paramIdx==0 || paramIdx>m_paramValues.size()) {
throw exception::Exception(std::string("Bad index for paramName ") + paramName);
}
const unsigned int idx = paramIdx - 1;
if (paramValue) {
// we must not cause the vector m_paramValues to resize, otherwise the c-pointers can be invalidated
m_paramValues[idx] = paramValue.value();
m_paramValuesPtrs[idx] = m_paramValues[idx].c_str();
} else {
......@@ -111,6 +117,7 @@ void PostgresStmt::bindOptionalUint64(const std::string &paramName, const option
const unsigned int idx = paramIdx - 1;
if (paramValue) {
// we must not cause the vector m_paramValues to resize, otherwise the c-pointers can be invalidated
m_paramValues[idx] = std::to_string(paramValue.value());
m_paramValuesPtrs[idx] = m_paramValues[idx].c_str();
} else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment