Use sscanf() for parsing tag values.

Neither strtoll() nor strtoull() can parse the %llx formatted tag
values coming from the kernel.  We know the lowest 32 bits will never
be set, so fast-path the 3-character case as 0x0.

Bug: 17365163
Change-Id: I238bbd2830c9335e7ab7a53362d6e12b46e0bcb3
This commit is contained in:
Jeff Sharkey
2014-09-09 12:29:41 -07:00
parent a53dd7f9ef
commit 14966ee4ae

View File

@@ -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,