All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sbitmap: initialize weight to zero
@ 2016-09-19 13:34 Colin King
  2016-09-19 14:20 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2016-09-19 13:34 UTC (permalink / raw)
  To: Jens Axboe, linux-block; +Cc: linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Variable weight is not being initialized to zero before it is
used to compute the weight sum. Ensure it is initialized to zero.

Found with static analysis with cppcheck:
[lib/sbitmap.c:177]: (error) Uninitialized variable: weight

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 lib/sbitmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/sbitmap.c b/lib/sbitmap.c
index e408089..2cecf05 100644
--- a/lib/sbitmap.c
+++ b/lib/sbitmap.c
@@ -169,7 +169,7 @@ EXPORT_SYMBOL_GPL(sbitmap_any_bit_clear);
 
 unsigned int sbitmap_weight(const struct sbitmap *sb)
 {
-	unsigned int i, weight;
+	unsigned int i, weight = 0;
 
 	for (i = 0; i < sb->map_nr; i++) {
 		const struct sbitmap_word *word = &sb->map[i];
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] sbitmap: initialize weight to zero
  2016-09-19 13:34 [PATCH] sbitmap: initialize weight to zero Colin King
@ 2016-09-19 14:20 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2016-09-19 14:20 UTC (permalink / raw)
  To: Colin King, linux-block; +Cc: linux-kernel

On 09/19/2016 07:34 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Variable weight is not being initialized to zero before it is
> used to compute the weight sum. Ensure it is initialized to zero.
>
> Found with static analysis with cppcheck:
> [lib/sbitmap.c:177]: (error) Uninitialized variable: weight

Thanks, applied. Strange, this is an old issue, it was just moved to 
this file. It should have triggered on mainline too. My compiler doesn't 
complain here:

$ gcc --version
gcc (Ubuntu 6.2.0-3ubuntu11~16.04) 6.2.0 20160901

-- 
Jens Axboe

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-09-19 14:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-19 13:34 [PATCH] sbitmap: initialize weight to zero Colin King
2016-09-19 14:20 ` Jens Axboe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.