From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1M1TPJ-0005OA-1v for mharc-grub-devel@gnu.org; Tue, 05 May 2009 18:46:37 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M1TPG-0005Na-NC for grub-devel@gnu.org; Tue, 05 May 2009 18:46:34 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M1TPC-0005MH-76 for grub-devel@gnu.org; Tue, 05 May 2009 18:46:34 -0400 Received: from [199.232.76.173] (port=53595 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M1TPC-0005ME-2D for grub-devel@gnu.org; Tue, 05 May 2009 18:46:30 -0400 Received: from c60.cesmail.net ([216.154.195.49]:63306) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.60) (envelope-from ) id 1M1TPB-0006Bx-FB for grub-devel@gnu.org; Tue, 05 May 2009 18:46:29 -0400 Received: from unknown (HELO smtprelay2.cesmail.net) ([192.168.1.112]) by c60.cesmail.net with ESMTP; 05 May 2009 18:46:28 -0400 Received: from [192.168.0.22] (static-72-92-88-10.phlapa.fios.verizon.net [72.92.88.10]) by smtprelay2.cesmail.net (Postfix) with ESMTPSA id E689A34C6D; Tue, 5 May 2009 18:45:28 -0400 (EDT) From: Pavel Roskin To: The development of GRUB 2 Content-Type: text/plain Date: Tue, 05 May 2009 18:46:27 -0400 Message-Id: <1241563587.2871.69.camel@mj> Mime-Version: 1.0 X-Mailer: Evolution 2.26.1 (2.26.1-2.fc11) Content-Transfer-Encoding: 7bit X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Bean Subject: [PATCH] Warning fix in raid6_recover X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 May 2009 22:46:34 -0000 Hello! This is an fix for this warning: disk/raid6_recover.c: In function 'grub_raid6_recover': disk/raid6_recover.c:95: warning: 'err[1]' may be used uninitialized in this function disk/raid6_recover.c:95: warning: 'err[0]' may be used uninitialized in this function The warning about err[0] appears to be legitimate. For some values of disknr err[0] will never be set. Namely, it will happen if disknr is equal p or p+1, for negative disknr and for disknr being more or equal array->total_devs. It's better to have a check for that case. The warning about err[1] is incorrect and can be easily eliminated once we realize that err[nerr++] is always err[1]. Since both err[0] and err[1] are only assigned positive values, we can initialize them with -1. This would also eliminate nerr, as we can check err[1] instead. It would be great to give better names to most variables. err[0] and err[1] could become separate variables. There is no need for them to be an array. And they are not error codes, despite what their names imply. Unfortunately, I'm not familiar enough with RAID6 to suggest better names. ChangeLog: * disk/raid6_recover.c (grub_raid6_recover): Fix warnings about uninitialized err[0] and err[1]. Initialize them with -1. Add sanity check for err[0]. Eliminate nerr variable. Index: disk/raid6_recover.c =================================================================== --- disk/raid6_recover.c (revision 2191) +++ disk/raid6_recover.c (working copy) @@ -92,7 +92,7 @@ char *buf, grub_disk_addr_t sector, int size) { int i, q, pos; - int err[2], nerr; + int err[2] = { -1, -1 }; char *pbuf = 0, *qbuf = 0; size <<= GRUB_DISK_SECTOR_BITS; @@ -115,7 +115,6 @@ if (pos == (int) array->total_devs) pos = 0; - nerr = 1; for (i = 0; i < (int) array->total_devs - 2; i++) { if (pos == disknr) @@ -131,10 +130,11 @@ } else { - if (nerr >= 2) + /* Too many bad devices */ + if (err[1] >= 0) goto quit; - err[nerr++] = i; + err[1] = i; grub_errno = GRUB_ERR_NONE; } } @@ -144,8 +144,13 @@ pos = 0; } - if (nerr == 1) + /* Invalid disknr or p */ + if (err[0] < 0) + goto quit; + + if (err[1] < 0) { + /* One bad device */ if ((array->device[p]) && (! grub_disk_read (array->device[p], sector, 0, size, buf))) { @@ -169,6 +174,7 @@ } else { + /* Two bad devices */ grub_uint8_t c; if ((! array->device[p]) || (! array->device[q])) -- Regards, Pavel Roskin