[dm-devel] [PATCH 1/2] snprintf doesn't return negative values.

Kevin Corry kevcorry at us.ibm.com
Wed Feb 25 14:44:01 UTC 2004


snprintf is never going to return a negative value, and it will always put a
NULL character at the end of the string. See lib/vsprintf.c::vsnprintf().

--- diff/drivers/md/dm-io.c	2004-02-25 13:27:17.000000000 -0600
+++ source/drivers/md/dm-io.c	2004-02-25 13:27:10.000000000 -0600
@@ -58,11 +58,7 @@
 
 static void mk_name(char *str, size_t len, const char *prefix, unsigned count)
 {
-	int r;
-
-	r = snprintf(str, len, "%s-%u", prefix, count);
-	if (r < 0)
-		str[len - 1] = '\0';
+	snprintf(str, len, "%s-%u", prefix, count);
 }
 
 static int bio_set_init(struct bio_set *bs, const char *slab_prefix,
@@ -75,7 +71,6 @@
 	};
 
 
-	int r;
 	unsigned i, size;
 	struct biovec_pool *bp;
 
@@ -85,9 +80,7 @@
 	/*
 	 * Set up the bio pool.
 	 */
-	r = snprintf(bs->name, sizeof(bs->name), "%s-bio", slab_prefix);
-	if (r < 0)
-		bs->name[sizeof(bs->name) - 1] = '\0';
+	snprintf(bs->name, sizeof(bs->name), "%s-bio", slab_prefix);
 
 	bs->bio_slab = kmem_cache_create(bs->name, sizeof(struct bio), 0,
 					 SLAB_HWCACHE_ALIGN, NULL, NULL);




More information about the dm-devel mailing list