Skip to contentSkip to conversation

bitmap_scnlistprintf() should always zero-terminate its output buffer

PATCH New Jan Beulich 1 participant 1 message Sep 5, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bitmap_scnlistprintf() should always zero-terminate its output buffer

... as long as it has non-zero size. So far this would not happen if the passed in CPU mask was empty.

Also fix the comment describing the return value to actually match reality.

xen/common/bitmap.c +4 -3
@@ -363,9 +363,8 @@ static inline int bscnl_emit(char *buf, 
  * the range.  Output format is compatible with the format
  * accepted as input by bitmap_parselist().
  *
- * The return value is the number of characters which would be
- * generated for the given input, excluding the trailing '\0', as
- * per ISO C99.
+ * The return value is the number of characters which were output,
+ * excluding the trailing '\0'.
  */
 int bitmap_scnlistprintf(char *buf, unsigned int buflen,
 	const unsigned long *maskp, int nmaskbits)
@@ -383,6 +382,8 @@ int bitmap_scnlistprintf(char *buf, unsi
 			rbot = cur;
 		}
 	}
+	if (!len && buflen)
+		*buf = 0;
 	return len;
 }
 EXPORT_SYMBOL(bitmap_scnlistprintf);