Bug#934916: libss7: FTBFS on x32 (time_t sprintf format mismatch)

2021-08-07 Thread John Scott
Another (untested) way to fix this issue is to craft the format string
using _Generic:

 strcpy(p, mtp3_timer2str(x));
 p += strlen(p);
-sprintf(p, "(%lis)%c", 
ss7->ss7_sched[ss7->links[i]->mtp3_timer[x]].when.tv_sec - time(NULL),
+#define FORMAT _Generic((time_t){0}, long int: "(%lis)%c", long long int: 
"(%llis)%c")
+sprintf(p, FORMAT, ss7->ss7_sched[ss7->links[i]->mtp3_timer[x]].when.tv_sec - 
time(NULL),
ss7->ss7_sched[ss7->links[i]->mtp3_timer[x]].callback ? ' ' : '!');



Bug#934916: libss7: FTBFS on x32 (time_t sprintf format mismatch)

2019-08-16 Thread Laurence Parry
Package: libss7-2.0
Version: 2.0.0-2
Tags: ftbfs
Usertags: x32
Priority: minor

libss7 2.0 fails to build on x32 because it assumes time_t is of type
long int when it can be long long int (64-bit, on a system with a
32-bit long).

gcc -g -O2 -fdebug-prefix-map=/<>=.
-specs=/usr/share/dpkg/pie-compile.specs -fstack-protector-strong
-Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g
-Wall -Werror -Wstrict-prototypes -Wmissing-prototypes -fPIC -O2  -MD
-MT ss7.o -MF .ss7.o.d -MP -c -o ss7.o ss7.c
ss7.c: In function 'ss7_show_linkset':
ss7.c:654:21: error: format '%li' expects argument of type 'long int',
but argument 3 has type 'long long int' [-Werror=format=]
  sprintf(p, "(%lis)%c",
ss7->ss7_sched[ss7->links[i]->mtp3_timer[x]].when.tv_sec - time(NULL),
   ~~^
~
   %lli

A patch for this might go along the lines of:

+#if defined __x86_64__ && defined __ILP32__
+  sprintf(p, "(%llis)%c",
ss7->ss7_sched[ss7->links[i]->mtp3_timer[x]].when.tv_sec - time(NULL),
+#else
  sprintf(p, "(%lis)%c",
ss7->ss7_sched[ss7->links[i]->mtp3_timer[x]].when.tv_sec - time(NULL),
+#endif

or it might be more appropriate to use strftime(), or cast to long
long int unconditionally (though this pulls it in where not needed on
x86 32-bit).

Minor priority because it's only mentioned as an binary dependency for
asterisk-dahdi (which currently compiles without it), and there it
only:

  * Depend on libss7 and newer libpri (1.4.7) for latest chan_dahdi abilities.

Best regards,
-- 
Laurence "GreenReaper" Parry
https://www.greenreaper.co.uk/