diff options
| author | 2014-09-09 20:29:34 +0000 | |
|---|---|---|
| committer | 2014-09-09 20:29:36 +0000 | |
| commit | a237e05cd7d86bd322b15b1552dcb93f9f70c0f1 (patch) | |
| tree | c51c3ce1b0b7123be94b6725c9547f99ac2eeeff | |
| parent | d5dfb723b8a33a74d5e86173ce4e72ad400a6375 (diff) | |
| parent | e47d5435de839523c1bb05c283eaec5968167db0 (diff) | |
Merge "Use sscanf() for parsing tag values." into lmp-dev
| -rw-r--r-- | core/jni/com_android_internal_net_NetworkStatsFactory.cpp | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/core/jni/com_android_internal_net_NetworkStatsFactory.cpp b/core/jni/com_android_internal_net_NetworkStatsFactory.cpp index c84a4666904f..2e2d0c7d8dcb 100644 --- a/core/jni/com_android_internal_net_NetworkStatsFactory.cpp +++ b/core/jni/com_android_internal_net_NetworkStatsFactory.cpp @@ -175,17 +175,23 @@ static int readNetworkStatsDetail(JNIEnv* env, jclass clazz, jobject stats, continue; } } - // Skip whitespace. - while (*pos == ' ') { - pos++; - } - // Next field is tag. - rawTag = strtoll(pos, &endPos, 16); - //ALOGI("Index #%d: %s", idx, buffer); - if (pos == endPos) { - ALOGE("bad tag: %s", pos); - fclose(fp); - return -1; + + // Ignore whitespace + while (*pos == ' ') pos++; + + // Find end of tag field + endPos = pos; + while (*endPos != ' ') endPos++; + + // Three digit field is always 0x0, otherwise parse + if (endPos - pos == 3) { + rawTag = 0; + } else { + if (sscanf(pos, "%llx", &rawTag) != 1) { + ALOGE("bad tag: %s", pos); + fclose(fp); + return -1; + } } s.tag = rawTag >> 32; if (limitTag != -1 && s.tag != limitTag) { @@ -193,10 +199,10 @@ static int readNetworkStatsDetail(JNIEnv* env, jclass clazz, jobject stats, continue; } pos = endPos; - // Skip whitespace. - while (*pos == ' ') { - pos++; - } + + // Ignore whitespace + while (*pos == ' ') pos++; + // Parse remaining fields. if (sscanf(pos, "%u %u %llu %llu %llu %llu", &s.uid, &s.set, &s.rxBytes, &s.rxPackets, |