am a5746ce3: am b8d727ec: Merge "Use sscanf() for parsing tag values." into lmp-dev

* commit 'a5746ce305bc331c4cb6a5bd1fa152c17813e0f8':
  Use sscanf() for parsing tag values.
This commit is contained in:
Jeff Sharkey
2014-09-09 21:56:04 +00:00
committed by Android Git Automerger

View File

@@ -175,17 +175,23 @@ static int readNetworkStatsDetail(JNIEnv* env, jclass clazz, jobject stats,
continue; continue;
} }
} }
// Skip whitespace.
while (*pos == ' ') { // Ignore whitespace
pos++; while (*pos == ' ') pos++;
}
// Next field is tag. // Find end of tag field
rawTag = strtoll(pos, &endPos, 16); endPos = pos;
//ALOGI("Index #%d: %s", idx, buffer); while (*endPos != ' ') endPos++;
if (pos == endPos) {
ALOGE("bad tag: %s", pos); // Three digit field is always 0x0, otherwise parse
fclose(fp); if (endPos - pos == 3) {
return -1; rawTag = 0;
} else {
if (sscanf(pos, "%llx", &rawTag) != 1) {
ALOGE("bad tag: %s", pos);
fclose(fp);
return -1;
}
} }
s.tag = rawTag >> 32; s.tag = rawTag >> 32;
if (limitTag != -1 && s.tag != limitTag) { if (limitTag != -1 && s.tag != limitTag) {
@@ -193,10 +199,10 @@ static int readNetworkStatsDetail(JNIEnv* env, jclass clazz, jobject stats,
continue; continue;
} }
pos = endPos; pos = endPos;
// Skip whitespace.
while (*pos == ' ') { // Ignore whitespace
pos++; while (*pos == ' ') pos++;
}
// Parse remaining fields. // Parse remaining fields.
if (sscanf(pos, "%u %u %llu %llu %llu %llu", if (sscanf(pos, "%u %u %llu %llu %llu %llu",
&s.uid, &s.set, &s.rxBytes, &s.rxPackets, &s.uid, &s.set, &s.rxBytes, &s.rxPackets,