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

Bug#805884: ion: FTBFS on sparc64, tv_usec wrong type in printf



Source: ion
Severity: important
Tags: upstream patch
User: debian-sparc@lists.debian.org
Usertags: sparc64

Dear Maintainer,

The ion package currently fails to build on sparc64. The build log
can be seen here:

https://buildd.debian.org/status/fetch.php?pkg=ion&arch=sparc64&ver=3.2.1%2Bdfsg-1&stamp=1448045105

The error that stops the build is this:

   gcc -DHAVE_CONFIG_H -I. -I..   -D_FORTIFY_SOURCE=2 -I./dtnperf/al_bp/src/bp_implementations -I./dtnperf/al_bp/src -I./../bp/include -I./../bp/library -fmessage-length=0 -Dlinux -fno-strict-aliasing -DENABLE_BPACS -DENABLE_IMC -Wall -Werror -g -include ./../config.h  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -DNOEXPAT -c -o dtnperf/dtnperf/src/dtnperf_vION-csv_tools.o `test -f 'dtnperf/dtnperf/src/csv_tools.c' || echo './'`dtnperf/dtnperf/src/csv_tools.c
    dtnperf/dtnperf/src/csv_tools.c: In function 'csv_print_rx_time':
    dtnperf/dtnperf/src/csv_tools.c:24:15: error: format '%ld' expects argument of type 'long int', but argument 4 has type '__suseconds_t {aka int}' [-Werror=format=]
      sprintf(buf, "%ld.%ld;", result->tv_sec, result->tv_usec);
               ^  
    cc1: all warnings being treated as errors

What's happening is that Werror is enabled for format expressions and
in the sprintf call here:

    sprintf(buf, "%ld.%ld;", result->tv_sec, result->tv_usec);

The last argument 'result->tv_usec' does not match the flag '%ld'
which is for 'long'.  Apparantly on sparc64 'tv_usec' is type 'int'.
A simple solution which will work on all archs is to add a cast to
'long' to the fourth argument:

    sprintf(buf, "%ld.%ld;", result->tv_sec, (long)result->tv_usec);

On archs where 'tv_usec' is long the cast will do nothing and on
sparc64 the cast will widen the int to a long.

I've attached a patch that implements this change and which allows the
package to build on sparc64.

If you're going to suggest a change for upstream I'd ask them to
consider changing it to this:

    sprintf(buf, "%lld.%lld;", (long long)result->tv_sec, (long long)result->tv_usec);

By using the format flags for and casting to 'long long' the format
will work with any width of 'tv_sec' and 'tv_usec'. And because 'long
long' will be the widest integer on the platform it won't truncate
values.

Thanks!
David


-- System Information:
Debian Release: stretch/sid
  APT prefers unreleased
  APT policy: (500, 'unreleased'), (500, 'unstable')
Architecture: sparc64

Kernel: Linux 4.3.0-gentoo (SMP w/1 CPU core)
Locale: LANG=en_SG.UTF-8, LC_CTYPE=en_SG.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: unable to detect
--- a/contrib/dtnperf/dtnperf/src/csv_tools.c
+++ b/contrib/dtnperf/dtnperf/src/csv_tools.c
@@ -21,7 +21,7 @@
 	struct timeval * result = malloc(sizeof(struct timeval));
 	char buf[50];
 	sub_time(time, start_time, result);
-	sprintf(buf, "%ld.%ld;", result->tv_sec, result->tv_usec);
+	sprintf(buf, "%ld.%ld;", result->tv_sec, (long)result->tv_usec);
 	fwrite(buf, strlen(buf), 1, file);
 }
 

Reply to: