Skip to content

Commit ca363be

Browse files
authored
Use return value of snprintf instead of calling strlen unnecessarily (#420)
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
1 parent fbe929d commit ca363be

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/cxoConnection.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ static PyObject *cxoConnection_getVersion(cxoConnection *conn, void *unused)
10501050
{
10511051
dpiVersionInfo versionInfo;
10521052
char buffer[25];
1053-
int status;
1053+
int status, len;
10541054

10551055
if (cxoConnection_isConnected(conn) < 0)
10561056
return NULL;
@@ -1059,10 +1059,11 @@ static PyObject *cxoConnection_getVersion(cxoConnection *conn, void *unused)
10591059
Py_END_ALLOW_THREADS
10601060
if (status < 0)
10611061
return cxoError_raiseAndReturnNull();
1062-
snprintf(buffer, sizeof(buffer), "%d.%d.%d.%d.%d", versionInfo.versionNum,
1063-
versionInfo.releaseNum, versionInfo.updateNum,
1064-
versionInfo.portReleaseNum, versionInfo.portUpdateNum);
1065-
return PyUnicode_DecodeASCII(buffer, strlen(buffer), NULL);
1062+
len = snprintf(buffer, sizeof(buffer), "%d.%d.%d.%d.%d",
1063+
versionInfo.versionNum, versionInfo.releaseNum,
1064+
versionInfo.updateNum, versionInfo.portReleaseNum,
1065+
versionInfo.portUpdateNum);
1066+
return PyUnicode_DecodeASCII(buffer, len, NULL);
10661067
}
10671068

10681069

0 commit comments

Comments
 (0)