[PATCH 1/2] cfdisk: data type mismatch, and other, compiler warning fixes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Following warnings will longer appear when one will compile with
gcc flags -Wall -Wextra -pedantic

cfdisk.c:475:3: warning: comparison of unsigned expression < 0 is always false
cfdisk.c:487:16: warning: comparison between signed and unsigned integer expressions
cfdisk.c:492:14: warning: comparison between signed and unsigned integer expressions
cfdisk.c:565:19: warning: comparison between signed and unsigned integer expressions
cfdisk.c:569:19: warning: comparison between signed and unsigned integer expressions
cfdisk.c:1070:14: warning: comparison between signed and unsigned integer expressions
cfdisk.c:1568:5: warning: missing initializer
cfdisk.c:1568:5: warning: (near initialization for 'tmp_ext.volume_label')

mbsalign.c:131:2: warning: comparison of unsigned expression >= 0 is always true

Signed-off-by: Sami Kerola <kerolasa@xxxxxx>
---
 fdisk/cfdisk.c |   15 ++++++++++-----
 lib/mbsalign.c |    6 +++---
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/fdisk/cfdisk.c b/fdisk/cfdisk.c
index 95f1864..7faa44a 100644
--- a/fdisk/cfdisk.c
+++ b/fdisk/cfdisk.c
@@ -427,7 +427,8 @@ fdexit(int ret) {
  */
 static int
 get_string(char *str, int len, char *def) {
-    size_t cells = 0, i = 0;
+    size_t cells = 0;
+    ssize_t i = 0;
     int x, y;
     int use_def = FALSE;
     wint_t c;
@@ -562,11 +563,11 @@ fatal(char *s, int ret) {
 	 char *str = xmalloc(strlen(s) + strlen(err1) + strlen(err2) + 10);
 
 	 sprintf(str, "%s: %s", err1, s);
-	 if (strlen(str) > COLS)
+	 if (strlen(str) > (size_t) COLS)
 	     str[COLS] = 0;
 	 mvaddstr(WARNING_START, (COLS-strlen(str))/2, str);
 	 sprintf(str, "%s", err2);
-	 if (strlen(str) > COLS)
+	 if (strlen(str) > (size_t) COLS)
 	     str[COLS] = 0;
 	 mvaddstr(WARNING_START+1, (COLS-strlen(str))/2, str);
 	 putchar(BELL); /* CTRL-G */
@@ -1067,7 +1068,7 @@ menuUpdate( int y, int x, struct MenuItem *menuItems, int itemLength,
         if(lenName > itemLength || lenName >= sizeof(buff))
             print_warning(_("Menu item too long. Menu may look odd."));
 #endif
-	if (lenName >= sizeof(buff)) {	/* truncate ridiculously long string */
+	if ((size_t) lenName >= sizeof(buff)) {	/* truncate ridiculously long string */
 	    xstrncpy(buff, mi, sizeof(buff));
 	} else if (lenName >= itemLength) {
             snprintf(buff, sizeof(buff),
@@ -1565,7 +1566,11 @@ fill_p_info(void) {
     unsigned long long llsectors;
     struct partition *p;
     partition_table buffer;
-    partition_info tmp_ext = { 0, 0, 0, 0, FREE_SPACE, PRIMARY };
+    partition_info tmp_ext;
+
+    memset(&tmp_ext, 0, sizeof tmp_ext);
+    tmp_ext.id = FREE_SPACE;
+    tmp_ext.num = PRIMARY;
 
     if ((fd = open(disk_device, O_RDWR)) < 0) {
 	 if ((fd = open(disk_device, O_RDONLY)) < 0)
diff --git a/lib/mbsalign.c b/lib/mbsalign.c
index 82ffc09..468e35b 100644
--- a/lib/mbsalign.c
+++ b/lib/mbsalign.c
@@ -106,12 +106,12 @@ rpl_wcswidth (const wchar_t *s, size_t n)
 size_t
 mbs_truncate(char *str, size_t *width)
 {
-	size_t bytes = strlen(str);
+	ssize_t bytes = strlen(str);
 #ifdef HAVE_WIDECHAR
-	size_t sz = mbstowcs(NULL, str, 0);
+	ssize_t sz = mbstowcs(NULL, str, 0);
 	wchar_t *wcs = NULL;
 
-	if (sz == (size_t) -1)
+	if (sz == (ssize_t) -1)
 		goto done;
 
 	wcs = malloc((sz + 1) * sizeof(wchar_t));
-- 
1.7.3.5

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux