ditch fixed length buffer

Change-Id: I06bbe4ee92ebeb7d1bc305d5a7da9ee9a4fa0cb8
Reviewed-on: https://gerrit.libreoffice.org/33706
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
This commit is contained in:
Caolán McNamara 2017-01-30 15:04:09 +00:00
parent f67061be4f
commit b87df03423

View File

@ -240,27 +240,22 @@ void Connection::construct(const ::rtl::OUString& url, const Sequence< PropertyV
} }
} }
char dpbBuffer[1 + 3 + 257 + 257 + 5 ]; // Expand as needed std::string dpbBuffer;
int dpbLength = 0;
{ {
char* dpb;
char userName[256] = ""; char userName[256] = "";
char userPassword[256] = ""; char userPassword[256] = "";
dpb = dpbBuffer; dpbBuffer.push_back(isc_dpb_version1);
*dpb++ = isc_dpb_version1; dpbBuffer.push_back(isc_dpb_sql_dialect);
dpbBuffer.push_back(1); // 1 byte long
*dpb++ = isc_dpb_sql_dialect; dpbBuffer.push_back(FIREBIRD_SQL_DIALECT);
*dpb++ = 1; // 1 byte long
*dpb++ = FIREBIRD_SQL_DIALECT;
// set UTF8 as default character set // set UTF8 as default character set
const char sCharset[] = "UTF8"; const char sCharset[] = "UTF8";
*dpb++ = isc_dpb_set_db_charset; dpbBuffer.push_back(isc_dpb_set_db_charset);
int nCharsetLength = sizeof(sCharset) - 1; int nCharsetLength = sizeof(sCharset) - 1;
*dpb++ = (char) nCharsetLength; dpbBuffer.push_back(nCharsetLength);
strcpy(dpb, sCharset); dpbBuffer.append(sCharset);
dpb+= nCharsetLength;
// Do any more dpbBuffer additions here // Do any more dpbBuffer additions here
@ -277,22 +272,18 @@ void Connection::construct(const ::rtl::OUString& url, const Sequence< PropertyV
if (strlen(userName)) if (strlen(userName))
{ {
int nUsernameLength = strlen(userName); int nUsernameLength = strlen(userName);
*dpb++ = isc_dpb_user_name; dpbBuffer.push_back(isc_dpb_user_name);
*dpb++ = (char) nUsernameLength; dpbBuffer.push_back(nUsernameLength);
strcpy(dpb, userName); dpbBuffer.append(userName);
dpb+= nUsernameLength;
} }
if (strlen(userPassword)) if (strlen(userPassword))
{ {
int nPasswordLength = strlen(userPassword); int nPasswordLength = strlen(userPassword);
*dpb++ = isc_dpb_password; dpbBuffer.push_back(isc_dpb_password);
*dpb++ = (char) nPasswordLength; dpbBuffer.push_back(nPasswordLength);
strcpy(dpb, userPassword); dpbBuffer.append(userPassword);
dpb+= nPasswordLength;
} }
dpbLength = dpb - dpbBuffer;
} }
ISC_STATUS_ARRAY status; /* status vector */ ISC_STATUS_ARRAY status; /* status vector */
@ -303,8 +294,8 @@ void Connection::construct(const ::rtl::OUString& url, const Sequence< PropertyV
m_sFirebirdURL.getLength(), m_sFirebirdURL.getLength(),
OUStringToOString(m_sFirebirdURL,RTL_TEXTENCODING_UTF8).getStr(), OUStringToOString(m_sFirebirdURL,RTL_TEXTENCODING_UTF8).getStr(),
&m_aDBHandle, &m_aDBHandle,
dpbLength, dpbBuffer.size(),
dpbBuffer, dpbBuffer.c_str(),
0); 0);
if (aErr) if (aErr)
{ {
@ -322,8 +313,8 @@ void Connection::construct(const ::rtl::OUString& url, const Sequence< PropertyV
m_sFirebirdURL.getLength(), m_sFirebirdURL.getLength(),
OUStringToOString(m_sFirebirdURL, RTL_TEXTENCODING_UTF8).getStr(), OUStringToOString(m_sFirebirdURL, RTL_TEXTENCODING_UTF8).getStr(),
&m_aDBHandle, &m_aDBHandle,
dpbLength, dpbBuffer.size(),
dpbBuffer); dpbBuffer.c_str());
if (aErr) if (aErr)
{ {
evaluateStatusVector(status, "isc_attach_database", *this); evaluateStatusVector(status, "isc_attach_database", *this);