[Home]

Summary:ASTERISK-05487: [post-1.2] [patch] time_t printf/scanf handling
Reporter:Luigi Rizzo (rizzo)Labels:
Date Opened:2005-11-07 04:41:12.000-0600Date Closed:2011-06-07 14:10:11
Priority:MinorRegression?No
Status:Closed/CompleteComponents:Core/General
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) patch.time
Description:unfortunately, time_t is defined as different integer types (int, int32_t, long) on different platforms, and so trying to compile asterisk with pedantic
compiler flags (including -Wall -Werror) causes problems.
The standards on time_t do not seem to enforce a particular type for time_t.

After a bit of discussion and thinking, i don't see a good solution other
than us settling on some integer type, and explictly casting time_t to
that type when doing a printf.

Given that:
+ i don't believe asterisk will ever run on 16-bit platforms, so int is
  at least 32 bits on all supported platforms;
+ 32 bit suffice for time_t until 2037;
i believe using %d as a format and casting to (int) is a reasonable approach.
The attached patch implements this.



****** ADDITIONAL INFORMATION ******

NOTE: the approach described above is safe for printf. It may be questionable
for scanf() in the case we have a platform with 64-bit int and 32-bit time_t.
I am not sure if we do have such a platform among the supported ones.
Comments:By: Tilghman Lesher (tilghman) 2005-11-22 12:39:13.000-0600

I'll note that we already have ast_time_t defined in "asterisk/time.h", and it needs to reflect the same type.

By: Russell Bryant (russell) 2005-12-26 11:00:18.000-0600

ast_time_t was created so that we didn't receive a warning when assigning a value to the tv_sec member of a timeval structure, since its type is different on different platforms.  

I'm going to go ahead and merge these casts.  If you think ast_time_t should be changed, let's open another issue to discuss it.

By: Russell Bryant (russell) 2005-12-26 11:36:20.000-0600

added to 1.2 and the trunk

By: Russell Bryant (russell) 2005-12-27 11:23:42.000-0600

I just noticed that on one of my machines, using gcc 4.0.2, the changes to scanf cause warnings of the following type to be introduced:

chan_sip.c:12049: warning: dereferencing type-punned pointer will break strict-aliasing rules

Should we just revert all of the changes to the scanf variants?

By: Digium Subversion (svnbot) 2008-01-15 16:09:00.000-0600

Repository: asterisk
Revision: 7634

U   branches/1.2/apps/app_chanspy.c
U   branches/1.2/apps/app_externalivr.c
U   branches/1.2/apps/app_queue.c
U   branches/1.2/apps/app_sms.c
U   branches/1.2/asterisk.c
U   branches/1.2/channels/chan_agent.c
U   branches/1.2/channels/chan_iax2.c
U   branches/1.2/channels/chan_sip.c
U   branches/1.2/cli.c
U   branches/1.2/config.c
U   branches/1.2/pbx/pbx_dundi.c
U   branches/1.2/res/res_monitor.c

------------------------------------------------------------------------
r7634 | russell | 2008-01-15 16:09:00 -0600 (Tue, 15 Jan 2008) | 2 lines

cast time_t to an int in printf/scanf (issue ASTERISK-5487)

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=7634

By: Digium Subversion (svnbot) 2008-01-15 16:09:02.000-0600

Repository: asterisk
Revision: 7635

_U  trunk/
U   trunk/apps/app_chanspy.c
U   trunk/apps/app_externalivr.c
U   trunk/apps/app_queue.c
U   trunk/apps/app_sms.c
U   trunk/asterisk.c
U   trunk/channels/chan_agent.c
U   trunk/channels/chan_iax2.c
U   trunk/channels/chan_sip.c
U   trunk/cli.c
U   trunk/config.c
U   trunk/pbx/pbx_dundi.c
U   trunk/res/res_monitor.c

------------------------------------------------------------------------
r7635 | russell | 2008-01-15 16:09:01 -0600 (Tue, 15 Jan 2008) | 10 lines

Merged revisions 7634 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.2

........
r7634 | russell | 2005-12-26 13:19:12 -0500 (Mon, 26 Dec 2005) | 2 lines

cast time_t to an int in printf/scanf (issue ASTERISK-5487)

........

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=7635

By: Digium Subversion (svnbot) 2008-01-15 16:09:18.000-0600

Repository: asterisk
Revision: 7653

_U  team/russell/ast_malloc/
U   team/russell/ast_malloc/Makefile
U   team/russell/ast_malloc/UPGRADE.txt
U   team/russell/ast_malloc/apps/app_chanspy.c
U   team/russell/ast_malloc/apps/app_externalivr.c
U   team/russell/ast_malloc/apps/app_queue.c
U   team/russell/ast_malloc/apps/app_sms.c
U   team/russell/ast_malloc/apps/app_voicemail.c
U   team/russell/ast_malloc/asterisk.c
U   team/russell/ast_malloc/cdr/cdr_tds.c
U   team/russell/ast_malloc/channels/chan_agent.c
U   team/russell/ast_malloc/channels/chan_iax2.c
U   team/russell/ast_malloc/channels/chan_sip.c
U   team/russell/ast_malloc/channels/chan_zap.c
U   team/russell/ast_malloc/cli.c
U   team/russell/ast_malloc/config.c
U   team/russell/ast_malloc/configs/extconfig.conf.sample
U   team/russell/ast_malloc/configs/func_odbc.conf.sample
U   team/russell/ast_malloc/configs/zapata.conf.sample
U   team/russell/ast_malloc/funcs/func_odbc.c
U   team/russell/ast_malloc/funcs/func_strings.c
U   team/russell/ast_malloc/include/asterisk/logger.h
U   team/russell/ast_malloc/logger.c
U   team/russell/ast_malloc/pbx/pbx_dundi.c
U   team/russell/ast_malloc/pbx.c
U   team/russell/ast_malloc/res/res_monitor.c

------------------------------------------------------------------------
r7653 | russell | 2008-01-15 16:09:17 -0600 (Tue, 15 Jan 2008) | 78 lines

Merged revisions 7633,7635-7636,7638-7640,7642-7643,7646-7649 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk

................
r7633 | tilghman | 2005-12-26 11:48:12 -0500 (Mon, 26 Dec 2005) | 2 lines

Bug 6057 - Deprecate builtins that have been replaced by functions

................
r7635 | russell | 2005-12-26 13:35:28 -0500 (Mon, 26 Dec 2005) | 10 lines

Merged revisions 7634 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.2

........
r7634 | russell | 2005-12-26 13:19:12 -0500 (Mon, 26 Dec 2005) | 2 lines

cast time_t to an int in printf/scanf (issue ASTERISK-5487)

........

................
r7636 | jdixon | 2005-12-26 15:01:35 -0500 (Mon, 26 Dec 2005) | 3 lines

Added support for Feature Group C CAMA trunks (both DP and MF), and support
for Feature Group D Tamdem trunks inbound (outbound was already there)

................
r7638 | tilghman | 2005-12-26 15:34:46 -0500 (Mon, 26 Dec 2005) | 3 lines

Merged revisions 7637 via svnmerge from
/branches/1.2

................
r7639 | russell | 2005-12-26 16:38:50 -0500 (Mon, 26 Dec 2005) | 5 lines

- normalize some loops
- simplify and reduce code by keeping track of return value
- replace some simple if/then sections with conditional expressions
(issue ASTERISK-5907)

................
r7640 | markster | 2005-12-26 18:56:44 -0500 (Mon, 26 Dec 2005) | 2 lines

Don't do DTMF detect on pseudo's!

................
r7642 | tilghman | 2005-12-26 21:02:23 -0500 (Mon, 26 Dec 2005) | 2 lines

Add SQL_ESC to allow single ticks to be escaped

................
r7643 | tilghman | 2005-12-26 21:05:56 -0500 (Mon, 26 Dec 2005) | 2 lines

Reduce warnings on signedness conversions

................
r7646 | tilghman | 2005-12-27 01:24:28 -0500 (Tue, 27 Dec 2005) | 2 lines

Bug 5183 - Inline stack backtraces

................
r7647 | tilghman | 2005-12-27 01:42:29 -0500 (Tue, 27 Dec 2005) | 2 lines

Bug 5854 - Allow quotation of the second field in extconfig, for the purpose of including commas (for LDAP configuration)

................
r7648 | tilghman | 2005-12-27 01:50:25 -0500 (Tue, 27 Dec 2005) | 2 lines

Bug 5906 - ARRAY dialplan function

................
r7649 | tilghman | 2005-12-27 02:13:37 -0500 (Tue, 27 Dec 2005) | 2 lines

Bug 5382 - Allow VM_CATEGORY in voicemail emails

................

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=7653