1
1

Fix a meaningless compare of an unsigned against 0. Rework the logic

a bit so that the secondary loop isn't even necessary; makes the whole
thing much simpler, anyway.

This commit was SVN r23860.
Этот коммит содержится в:
Jeff Squyres 2010-10-07 15:04:50 +00:00
родитель d30d66c8b7
Коммит a95ca7444e

Просмотреть файл

@ -142,12 +142,19 @@ char *opal_paffinity_base_print_binding(opal_paffinity_base_cpu_set_t cpumask)
} }
memset(tmp, 0, masksize); memset(tmp, 0, masksize);
masksize = sizeof(opal_paffinity_base_bitmask_t); masksize = sizeof(opal_paffinity_base_bitmask_t);
/* Save the position of the last : before there are all zeros to
the right -- we don't need to print all zeros to the right;
we'll chop them off, below. */
save = 0;
if (4 == masksize) { if (4 == masksize) {
for (i=0, j=0; i < OPAL_PAFFINITY_BITMASK_NUM_ELEMENTS; i++) { for (i=0, j=0; i < OPAL_PAFFINITY_BITMASK_NUM_ELEMENTS; i++) {
sprintf(&tmp[j], "%08lx", cpumask.bitmask[i]); sprintf(&tmp[j], "%08lx", cpumask.bitmask[i]);
j += 8; j += 8;
tmp[j] = ':'; tmp[j] = ':';
if (cpumask.bitmask[i] > 0) {
save = j;
}
j++; j++;
} }
} else if (8 == masksize) { } else if (8 == masksize) {
@ -156,25 +163,20 @@ char *opal_paffinity_base_print_binding(opal_paffinity_base_cpu_set_t cpumask)
j += 16; j += 16;
tmp[j] = ':'; tmp[j] = ':';
j++; j++;
if (cpumask.bitmask[i] > 0) {
save = j;
}
} }
} }
/* find the last non-zero entry */ /* If there were no non-zero values, then ensure to print one
save = OPAL_PAFFINITY_CPU_SET_NUM_BYTES+OPAL_PAFFINITY_BITMASK_NUM_ELEMENTS; field of zeros */
for (i=OPAL_PAFFINITY_CPU_SET_NUM_BYTES+OPAL_PAFFINITY_BITMASK_NUM_ELEMENTS-1; 0 <= i; i--) { if (0 == save) {
if ('0' != tmp[i] && ':' != tmp[i]) { tmp[2 * masksize] = '\0';
tmp[save] = '\0'; } else {
break; tmp[save] = '\0';
} else if (':' == tmp[i]) {
save = i;
}
} }
if ('\0' == tmp[0]) {
/* there was nothing in the mask */
free(tmp);
tmp = NULL;
}
return tmp; return tmp;
} }