From a95ca7444ec49ef8be2921b84f36877ec25b1f99 Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Thu, 7 Oct 2010 15:04:50 +0000 Subject: [PATCH] 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. --- .../paffinity/base/paffinity_base_wrappers.c | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/opal/mca/paffinity/base/paffinity_base_wrappers.c b/opal/mca/paffinity/base/paffinity_base_wrappers.c index 672eb09b1d..ba6805175c 100644 --- a/opal/mca/paffinity/base/paffinity_base_wrappers.c +++ b/opal/mca/paffinity/base/paffinity_base_wrappers.c @@ -142,12 +142,19 @@ char *opal_paffinity_base_print_binding(opal_paffinity_base_cpu_set_t cpumask) } memset(tmp, 0, masksize); 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) { for (i=0, j=0; i < OPAL_PAFFINITY_BITMASK_NUM_ELEMENTS; i++) { sprintf(&tmp[j], "%08lx", cpumask.bitmask[i]); j += 8; tmp[j] = ':'; + if (cpumask.bitmask[i] > 0) { + save = j; + } j++; } } else if (8 == masksize) { @@ -156,25 +163,20 @@ char *opal_paffinity_base_print_binding(opal_paffinity_base_cpu_set_t cpumask) j += 16; tmp[j] = ':'; j++; + if (cpumask.bitmask[i] > 0) { + save = j; + } } } - - /* find the last non-zero entry */ - save = OPAL_PAFFINITY_CPU_SET_NUM_BYTES+OPAL_PAFFINITY_BITMASK_NUM_ELEMENTS; - for (i=OPAL_PAFFINITY_CPU_SET_NUM_BYTES+OPAL_PAFFINITY_BITMASK_NUM_ELEMENTS-1; 0 <= i; i--) { - if ('0' != tmp[i] && ':' != tmp[i]) { - tmp[save] = '\0'; - break; - } else if (':' == tmp[i]) { - save = i; - } + + /* If there were no non-zero values, then ensure to print one + field of zeros */ + if (0 == save) { + tmp[2 * masksize] = '\0'; + } else { + tmp[save] = '\0'; } - if ('\0' == tmp[0]) { - /* there was nothing in the mask */ - free(tmp); - tmp = NULL; - } - + return tmp; }