Skip to content

Commit 41d65bb

Browse files
committed
Eliminate static code analysis warnings
1 parent 234540e commit 41d65bb

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/njsDbObject.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,10 @@ static napi_value njsDbObject_getKeys(napi_env env, napi_callback_info info)
356356
static bool njsDbObject_getKeysHelper(napi_env env, napi_callback_info info,
357357
napi_value *returnValue)
358358
{
359-
int32_t arrayPos, index, exists, size;
360359
njsDbObjectType *objType = NULL;
360+
int32_t index, exists, size;
361361
napi_value arr, temp;
362+
uint32_t arrayPos;
362363
njsDbObject *obj;
363364

364365
// get object instance from caller
@@ -368,7 +369,8 @@ static bool njsDbObject_getKeysHelper(napi_env env, napi_callback_info info,
368369
// determine the size of the collection and create an array of that length
369370
if (dpiObject_getSize(obj->handle, &size) < 0)
370371
return njsUtils_throwErrorDPI(env, obj->type->oracleDb);
371-
NJS_CHECK_NAPI(env, napi_create_array_with_length(env, size, &arr))
372+
NJS_CHECK_NAPI(env, napi_create_array_with_length(env, (size_t) size,
373+
&arr))
372374

373375
// iterate over the elements in the collection
374376
arrayPos = 0;
@@ -570,9 +572,10 @@ static napi_value njsDbObject_getValues(napi_env env, napi_callback_info info)
570572
static bool njsDbObject_getValuesHelper(napi_env env, napi_callback_info info,
571573
napi_value *returnValue)
572574
{
573-
int32_t arrayPos, index, exists, size;
574575
njsDbObjectType *objType = NULL;
576+
int32_t index, exists, size;
575577
napi_value arr, temp;
578+
uint32_t arrayPos;
576579
njsDbObject *obj;
577580
dpiData data;
578581

@@ -583,7 +586,8 @@ static bool njsDbObject_getValuesHelper(napi_env env, napi_callback_info info,
583586
// determine the size of the collection and create an array of that length
584587
if (dpiObject_getSize(obj->handle, &size) < 0)
585588
return njsUtils_throwErrorDPI(env, obj->type->oracleDb);
586-
NJS_CHECK_NAPI(env, napi_create_array_with_length(env, size, &arr))
589+
NJS_CHECK_NAPI(env, napi_create_array_with_length(env, (size_t) size,
590+
&arr))
587591

588592
// iterate over the elements in the collection
589593
arrayPos = 0;
@@ -1254,8 +1258,9 @@ static bool njsDbObjectType_populate(njsDbObjectType *objType,
12541258
objType->fqn = malloc(objType->fqnLength + 1);
12551259
if (!objType->fqn)
12561260
return njsBaton_setError(baton, errInsufficientMemory);
1257-
sprintf(objType->fqn, "%.*s.%.*s", (int) info->schemaLength, info->schema,
1258-
(int) info->nameLength, info->name);
1261+
(void) snprintf(objType->fqn, objType->fqnLength + 1, "%.*s.%.*s",
1262+
(int) info->schemaLength, info->schema, (int) info->nameLength,
1263+
info->name);
12591264

12601265
// set whether or not the class is a collection or not
12611266
NJS_CHECK_NAPI(env, napi_get_boolean(env, info->isCollection, &temp))

src/njsUtils.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,16 @@ bool njsUtils_addTypeProperties(napi_env env, napi_value obj,
127127
temp))
128128

129129
// set the type name
130-
sprintf(propertyName, "%sName", propertyNamePrefix);
130+
(void) snprintf(propertyName, sizeof(propertyName), "%sName",
131+
propertyNamePrefix);
131132
NJS_CHECK_NAPI(env, napi_create_string_utf8(env, typeName, typeNameLength,
132133
&temp))
133134
NJS_CHECK_NAPI(env, napi_set_named_property(env, obj, propertyName, temp))
134135

135136
// set the type class, if applicable
136137
if (objType) {
137-
sprintf(propertyName, "%sClass", propertyNamePrefix);
138+
(void) snprintf(propertyName, sizeof(propertyName), "%sClass",
139+
propertyNamePrefix);
138140
NJS_CHECK_NAPI(env, napi_get_reference_value(env,
139141
objType->jsDbObjectConstructor, &temp))
140142
NJS_CHECK_NAPI(env, napi_set_named_property(env, obj, propertyName,
@@ -481,7 +483,7 @@ bool njsUtils_getIntArg(napi_env env, napi_value *args, int index,
481483
NJS_CHECK_NAPI(env, napi_get_value_double(env, args[index], &doubleValue))
482484

483485
// if the value is not an integer, return an error
484-
*result = (uint32_t) doubleValue;
486+
*result = (int32_t) doubleValue;
485487
if ((double) *result != doubleValue)
486488
return njsUtils_throwError(env, errInvalidParameterValue, index + 1);
487489

0 commit comments

Comments
 (0)