1

为什么存在“使用受污染的变量“len”作为循环边界”?它与“静态”有关吗?

527    int i = 0;
528
 CID 90251 (#1 of 1): Untrusted loop bound (TAINTED_SCALAR)
 3. tainted_data: Using tainted variable "len" as a loop boundary.
529    for (i = 0; i < len; i++) {

这里的功能:

static jintArray getAvailableCoreNums(JNIEnv *env, jobject clazz) {
 int len = getCoreNums(POSSIBLE_CORES);
 int coreNums[len];
 int i = 0;

 for (i = 0; i < len; i++) {
     coreNums[i] = i + 1;
 }

 jintArray args = (*env)->NewIntArray(env, len);
 if (args == NULL){
     LOGE("Can not new Int Array");
     return NULL;
 }

 (*env)->SetIntArrayRegion(env, args, 0, len, coreNums);
 return args;
}

以及getCoreNums()的功能

int getCoreNums(const char *sys)
{
     char rts[RTS_SIZE];
     memset(rts, 0, RTS_SIZE);

     const char * split = "-";
     if (0 == catEntry(sys, rts)) {
         int start, end;
         sscanf(rts, "%d-%d", &start, &end);
         LOGD("get %s core number %d\n", sys, end + 1);
         return end + 1;
     } else {
         LOGD("get %s core number failed\n", sys);
         return 0;
     }
 }

如何消除这种警告?

4

0 回答 0