Skip to contentSkip to conversation

hwclock: fix signed/unsigned comparison warning on alpha

PATCH Applied Andreas Henriksson 2 participants 6 messages Aug 21, 2015 – Sep 7, 2015 Util-Linux package

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 hwclock: fix signed/unsigned comparison warning on alpha

Fixes the following warning:
sys-utils/hwclock.c: In function 'manipulate_epoch':
sys-utils/hwclock.c:1465:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (epoch_opt == -1)

Full build log available on:
https://buildd.debian.org/status/fetch.php?pkg=util-linux&arch=alpha&ver=2.26.2-9&stamp=1440078034

Detected by/via:
https://qa.debian.org/bls/packages/u/util-linux.html

Please note that this has never actually been (build-)tested on alpha, but should hopefully resolve the warning. Note also that limits.h is already included.

---
 sys-utils/hwclock.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
sys-utils/hwclock.c +2 -2
index f04cf2b..bdb98e2 100644
@@ -137,7 +137,7 @@ int debug;
 bool badyear;
 
 /* User-specified epoch, used when rtc fails to return epoch. */
-unsigned long epoch_option = -1;
+unsigned long epoch_option = ULONG_MAX;
 
 /*
  * Almost all Award BIOS's made between 04/26/94 and 05/31/95 have a nasty
@@ -1452,7 +1452,7 @@ manipulate_epoch(const bool getepoch,
 			printf(_("Kernel is assuming an epoch value of %lu\n"),
 			       epoch);
 	} else if (setepoch) {
-		if (epoch_opt == -1)
+		if (epoch_opt == ULONG_MAX)
 			warnx(_
 			      ("To set the epoch value, you must use the 'epoch' "
 			       "option to tell to what value to set it."));
Signature · 1 line
2.1.4
#1 lore raw

PATCH 2/3 hwclock: fix fgets unchecked return value warning on alpha

Build warning:
sys-utils/hwclock-cmos.c: In function 'is_in_cpuinfo':
sys-utils/hwclock-cmos.c:162:4: warning: ignoring return value of 'fgets', declared with attribute warn_unused_result [-Wunused-result]

    fgets(field, 256, cpuinfo);

Full build log:
https://buildd.debian.org/status/fetch.php?pkg=util-linux&arch=alpha&ver=2.26.2-9&stamp=1440078034

Detected by/via:
https://qa.debian.org/bls/packages/u/util-linux.html

This change has never actually been (build-)tested on alpha, but hopefully the change should fix the warning.

---
 sys-utils/hwclock-cmos.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
sys-utils/hwclock-cmos.c +4 -4
index 8d68808..de678ab 100644
@@ -152,15 +152,15 @@ static int is_in_cpuinfo(char *fmt, char *str)
 
 	sprintf(format, "%s : %s", fmt, "%255s");
 
-	if ((cpuinfo = fopen("/proc/cpuinfo", "r")) != NULL) {
-		while (!feof(cpuinfo)) {
+	cpuinfo = fopen("/proc/cpuinfo", "r");
+	if (cpuinfo) {
+		do {
 			if (fscanf(cpuinfo, format, field) == 1) {
 				if (strncmp(field, str, strlen(str)) == 0)
 					found = 1;
 				break;
 			}
-			fgets(field, 256, cpuinfo);
-		}
+		} while (fgets(field, 256, cpuinfo));
 		fclose(cpuinfo);
 	}
 	return found;
Signature · 1 line
2.1.4
#2 lore raw

PATCH 3/3 hwclock: fix iopl implicit declaration warning on alpha

In reply to Andreas Henriksson

Build warning:
sys-utils/hwclock-cmos.c: In function 'i386_iopl':
sys-utils/hwclock-cmos.c:611:9: warning: implicit declaration of function 'iopl' [-Wimplicit-function-declaration]

  return iopl(level);
         ^

sys-utils/hwclock-cmos.c:611:2: warning: nested extern declaration of 'iopl' [-Wnested-externs]
return iopl(level);
^

Also:
checking sys/io.h usability... yes
checking sys/io.h presence... yes
checking for sys/io.h... yes

Full build log:
https://buildd.debian.org/status/fetch.php?pkg=util-linux&arch=alpha&ver=2.26.2-9&stamp=1440078034

Detected by/via:
https://qa.debian.org/bls/packages/u/util-linux.html

Please note that this has never been (build-)tested, but should hopefully resolve the warning.

---
 sys-utils/hwclock-cmos.c | 5 +++++
 1 file changed, 5 insertions(+)
sys-utils/hwclock-cmos.c +5 -0
index de678ab..7f564e7 100644
@@ -79,9 +79,14 @@ int inb(int c __attribute__ ((__unused__)))
 #endif				/* __i386__ __x86_64__ */
 
 #elif defined(__alpha__)
+# ifdef HAVE_SYS_IO_H
+#  include <sys/io.h>
+# else
 /* <asm/io.h> fails to compile, probably because of u8 etc */
 extern unsigned int inb(unsigned long port);
 extern void outb(unsigned char b, unsigned long port);
+extern int iopl(int level);
+# endif
 #else
 static void outb(int a __attribute__ ((__unused__)),
 	  int b __attribute__ ((__unused__)))
Signature · 1 line
2.1.4
maintainer
#3 lore raw
In reply to Andreas Henriksson
Quoted 2 lines · Andreas Henriksson
 sys-utils/hwclock.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Applied all three patches. It would be nice to test it on alphas. Thanks.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#4 lore raw

Hello!

Quoted 6 lines · Karel Zak
Quoted 2 lines · Andreas Henriksson
 sys-utils/hwclock.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Applied all three patches. It would be nice to test it on alphas. Thanks.

The alpha buildds has now caught up and a full build log of 2.27-rc2 is available here:
https://buildd.debian.org/status/fetch.php?pkg=util-linux&arch=alpha&ver=2.27~rc2-2&stamp=1441074407

(Other architectures build logs available by clicking "Installed" on this page:
https://buildd.debian.org/status/package.php?p=util-linux&suite=experimental )

The committed patches seems to have had the desired effect and fixed the compiler warnings they where aiming at.

Remaining warnings for alpha arch specific code in hwclock:

gcc -DHAVE_CONFIG_H -I. -include config.h -I./include -DLOCALEDIR=\"/usr/share/locale\" -D_PATH_LOCALSTATEDIR=\"/run\" -D_FORTIFY_SOURCE=2 -fsigned-char -fno-common -Wall -Werror=sequence-point -Wextra -Wmissing-declarations -Wmissing-parameter-type -Wmissing-prototypes -Wno-missing-field-initializers -Wredundant-decls -Wsign-compare -Wtype-limits -Wuninitialized -Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-parameter -Wunused-result -Wunused-variable -Wnested-externs -Wpointer-arith -Wstrict-prototypes -Wimplicit-function-declaration -g -O2 -Wformat -Werror=format-security -c -o sys-utils/hwclock.o sys-utils/hwclock.c In file included from ./include/nls.h:24:0,
from ./include/closestream.h:11,
from sys-utils/hwclock.c:77:
sys-utils/hwclock.c: In function 'manipulate_epoch':
sys-utils/hwclock.c:1471:12: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long unsigned int' [-Wformat=]
("Not setting the epoch to %d - testing only.\n"),
^
sys-utils/hwclock.c:1470:11: note: in expansion of macro '_'

    printf(_
           ^
gcc -DHAVE_CONFIG_H -I.  -include config.h -I./include -DLOCALEDIR=\"/usr/share/locale\" -D_PATH_LOCALSTATEDIR=\"/run\" -D_FORTIFY_SOURCE=2 -fsigned-char -fno-common -Wall -Werror=sequence-point -Wextra -Wmissing-declarations -Wmissing-parameter-type -Wmissing-prototypes -Wno-missing-field-initializers -Wredundant-decls -Wsign-compare -Wtype-limits -Wuninitialized -Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-parameter -Wunused-result -Wunused-variable -Wnested-externs -Wpointer-arith -Wstrict-prototypes -Wimplicit-function-declaration -g -O2 -Wformat -Werror=format-security -c -o sys-utils/hwclock-cmos.o sys-utils/hwclock-cmos.c
sys-utils/hwclock-cmos.c: In function 'set_cmos_epoch':
sys-utils/hwclock-cmos.c:183:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (epoch_option != -1) {
                   ^

sys-utils/hwclock-cmos.c: In function 'atomic':
sys-utils/hwclock-cmos.c:290:3: warning: output constraint '=' for operand 0 is not at the beginning
asm volatile ("rpcc %0":"r=" (ts1));
^
sys-utils/hwclock-cmos.c:292:3: warning: output constraint '=' for operand 0 is not at the beginning
asm volatile ("rpcc %0":"r=" (ts2));
^
sys-utils/hwclock-cmos.c:290:3: warning: output constraint '=' for operand 0 is not at the beginning
asm volatile ("rpcc %0":"r=" (ts1));
^
sys-utils/hwclock-cmos.c:292:3: warning: output constraint '=' for operand 0 is not at the beginning
asm volatile ("rpcc %0":"r=" (ts2));
^
sys-utils/hwclock-cmos.c:285:1: warning: output constraint '=' for operand 0 is not at the beginning
atomic(const char *name, unsigned long (*op) (unsigned long), unsigned long arg)
^
sys-utils/hwclock-cmos.c:285:1: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:678:1: warning: output constraint '=' for operand 0 is not at the beginning
}
^
sys-utils/hwclock-cmos.c:678:1: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:678:1: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:678:1: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:678:1: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:678:1: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:678:1: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:678:1: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:678:1: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:678:1: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:678:1: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:678:1: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:678:1: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:678:1: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:678:1: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:678:1: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:285:1: warning: output constraint '=' for operand 0 is not at the beginning
atomic(const char *name, unsigned long (*op) (unsigned long), unsigned long arg)
^
sys-utils/hwclock-cmos.c:285:1: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:285:1: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:285:1: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:285:1: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:285:1: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:285:1: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:285:1: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:285:1: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:285:1: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:285:1: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:285:1: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:285:1: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:285:1: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:285:1: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:285:1: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:290:3: warning: output constraint '=' for operand 0 is not at the beginning
asm volatile ("rpcc %0":"r=" (ts1));
^
sys-utils/hwclock-cmos.c:290:3: warning: output constraint '=' for operand 0 is not at the beginning sys-utils/hwclock-cmos.c:292:3: warning: output constraint '=' for operand 0 is not at the beginning
asm volatile ("rpcc %0":"r=" (ts2));
^
sys-utils/hwclock-cmos.c:292:3: warning: output constraint '=' for operand 0 is not at the beginning

The first warning should be trivially fixed by the attached patch, changing a %d to %lu for printing epoch_opt.
The hwclock-cmos.c sign/unsigned comparison could be fixed by including limits.h and using ULONG_MAX instead of -1 in epoch_option comparison, similar to what was done in hwclock.c already. Not sure how to deal with the assembler warnings....

Regards,
Andreas Henriksson

From: Andreas Henriksson <[email protected]>
Subject: hwclock: fix format warning in alpha code

sys-utils/hwclock.c +1 -1
index bdb98e2..4b201d7 100644
@@ -1458,7 +1458,7 @@ manipulate_epoch(const bool getepoch,
 			       "option to tell to what value to set it."));
 		else if (testing)
 			printf(_
-			       ("Not setting the epoch to %d - testing only.\n"),
+			       ("Not setting the epoch to %lu - testing only.\n"),
 			       epoch_opt);
 		else if (set_epoch_rtc(epoch_opt))
 			printf(_
maintainer Applied
#5 lore raw
Quoted 1 line · Andreas Henriksson

The first warning should be trivially fixed by the attached patch,

Applied, thanks.

Quoted 1 line

Not sure how to deal with the assembler warnings....

Me too :-)

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com