From ca363bed8f914c1add9499e39c33432f2f1f198b Mon Sep 17 00:00:00 2001 From: Alex Henrie Date: Sat, 18 Apr 2020 16:55:29 -0600 Subject: [PATCH] Use return value of snprintf instead of calling strlen unnecessarily (#420) Signed-off-by: Alex Henrie --- src/cxoConnection.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/cxoConnection.c b/src/cxoConnection.c index b2b158e2..eb9ef790 100644 --- a/src/cxoConnection.c +++ b/src/cxoConnection.c @@ -1050,7 +1050,7 @@ static PyObject *cxoConnection_getVersion(cxoConnection *conn, void *unused) { dpiVersionInfo versionInfo; char buffer[25]; - int status; + int status, len; if (cxoConnection_isConnected(conn) < 0) return NULL; @@ -1059,10 +1059,11 @@ static PyObject *cxoConnection_getVersion(cxoConnection *conn, void *unused) Py_END_ALLOW_THREADS if (status < 0) return cxoError_raiseAndReturnNull(); - snprintf(buffer, sizeof(buffer), "%d.%d.%d.%d.%d", versionInfo.versionNum, - versionInfo.releaseNum, versionInfo.updateNum, - versionInfo.portReleaseNum, versionInfo.portUpdateNum); - return PyUnicode_DecodeASCII(buffer, strlen(buffer), NULL); + len = snprintf(buffer, sizeof(buffer), "%d.%d.%d.%d.%d", + versionInfo.versionNum, versionInfo.releaseNum, + versionInfo.updateNum, versionInfo.portReleaseNum, + versionInfo.portUpdateNum); + return PyUnicode_DecodeASCII(buffer, len, NULL); }