From: Sami Kerola Date: Sun, 23 Jan 2011 14:40:18 +0000 (+0100) Subject: cfdisk: data type mismatch, and other, compiler warning fixes X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2897f29a10ba95a96af2139b982ddaddfd49a60d;p=util-linux cfdisk: data type mismatch, and other, compiler warning fixes 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 --- diff --git a/fdisk/cfdisk.c b/fdisk/cfdisk.c index 95f1864d..7faa44a3 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 82ffc09c..468e35b5 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));