Bug#790349: bs1770gain: Fail to build when clock_t is not long int

Petter Reinholdtsen pere at hungry.com
Sun Jun 28 11:23:33 UTC 2015


Package: bs1770gain
Version: 0.4.5-1
Severity: wishlist
Tags: patch

I noticed a build failure on the non-official x32 architecture, build
log available from
<URL: http://buildd.debian-ports.org/status/fetch.php?pkg=bs1770gain&arch=x32&ver=0.4.5-1&stamp=1435292575 >.

The build fail like this:

bs1770gain.c: In function 'main':
bs1770gain.c:647:5: error: format '%ld' expects argument of type 'long int', but argument 3 has type 'clock_t' [-Werror=format=]
     fprintf(stderr, "Duration: %ld ms.\n",(t2-t1)/CLOCKS_PER_MILLIS);
     ^
cc1: all warnings being treated as errors

The reason is that clock_t is not of type 'long int' on this platform.

Based on the information available from
<URL: http://stackoverflow.com/questions/1083142/what-s-the-correct-way-to-use-printf-to-print-a-clock-t >,
refering to
<URL: http://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/types.h.html >
where it is stated that "clock_t shall be integer or real-floating
types", I guess the best way to make this code portable is to cast it to
a known type before printing it.  I suggest using uintmax_t and the %ju
format specifier like this:

diff --git a/bs1770gain/bs1770gain.c b/bs1770gain/bs1770gain.c
index 1bfda59..a624212 100755
--- a/bs1770gain/bs1770gain.c
+++ b/bs1770gain/bs1770gain.c
@@ -644,7 +644,7 @@ int main(int argc, char **argv)
   root.vmt->cleanup(&root);
 
   if (options.time)
-    fprintf(stderr, "Duration: %ld ms.\n",(t2-t1)/CLOCKS_PER_MILLIS);
+    fprintf(stderr, "Duration: %ju ms.\n",(uintmax_t)((t2-t1)/CLOCKS_PER_MILLIS));
 // cleanup:
   sox_quit();
   // still reachable: 9,689 bytes in 51 blocks

-- 
Happy hacking
Petter Reinholdtsen



More information about the pkg-multimedia-maintainers mailing list