[asterisk-commits] dlee: trunk r392076 - in /trunk: funcs/func_cdr.c main/cdr.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jun 17 13:58:58 CDT 2013


Author: dlee
Date: Mon Jun 17 13:58:56 2013
New Revision: 392076

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=392076
Log:
Fix build warnings related to printf/scanf of tv_usec.

The type of tv_usec is suseconds_t. On Linux, this is usually a long int, but
the specification is actually pretty lax on what it might actually be. And,
sadly, there's no printf/scanf width specifier for suseconds_t. So it could
bit an int or a long, but there's not a great way to tell which it is.

This patch fixes scanf by reading into a long temporary variable that's then
stored into the tv_usec. It fixes printf by casting the tv_usec to a long
first.

This patch also adds some missing width specifiers for some debug statements,
which would cause ".000001" to be displayed at ".1".

Modified:
    trunk/funcs/func_cdr.c
    trunk/main/cdr.c

Modified: trunk/funcs/func_cdr.c
URL: http://svnview.digium.com/svn/asterisk/trunk/funcs/func_cdr.c?view=diff&rev=392076&r1=392075&r2=392076
==============================================================================
--- trunk/funcs/func_cdr.c (original)
+++ trunk/funcs/func_cdr.c Mon Jun 17 13:58:56 2013
@@ -248,11 +248,14 @@
 				|| !strcasecmp("answer", args.variable)) {
 			struct timeval fmt_time;
 			struct ast_tm tm;
-			if (sscanf(tempbuf, "%ld.%ld", &fmt_time.tv_sec, &fmt_time.tv_usec) != 2) {
+			/* tv_usec is suseconds_t, which could be int or long */
+			long int tv_usec;
+			if (sscanf(tempbuf, "%ld.%ld", &fmt_time.tv_sec, &tv_usec) != 2) {
 				ast_log(AST_LOG_WARNING, "Unable to parse %s (%s) from the CDR for channel %s\n",
 						args.variable, tempbuf, ast_channel_name(chan));
 				return 0;
 			}
+			fmt_time.tv_usec = tv_usec;
 			ast_localtime(&fmt_time, &tm, NULL);
 			ast_strftime(tempbuf, sizeof(*tempbuf), "%Y-%m-%d %T", &tm);
 		} else if (!strcasecmp("disposition", args.variable)) {

Modified: trunk/main/cdr.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/cdr.c?view=diff&rev=392076&r1=392075&r2=392076
==============================================================================
--- trunk/main/cdr.c (original)
+++ trunk/main/cdr.c Mon Jun 17 13:58:56 2013
@@ -1119,14 +1119,15 @@
 		}
 	}
 
-	ast_debug(1, "Finalized CDR for %s - start %ld.%ld answer %ld.%ld end %ld.%ld dispo %s\n",
+	/* tv_usec is suseconds_t, which could be int or long */
+	ast_debug(1, "Finalized CDR for %s - start %ld.%06ld answer %ld.%06ld end %ld.%06ld dispo %s\n",
 			cdr->party_a.snapshot->name,
 			cdr->start.tv_sec,
-			cdr->start.tv_usec,
+			(long)cdr->start.tv_usec,
 			cdr->answer.tv_sec,
-			cdr->answer.tv_usec,
+			(long)cdr->answer.tv_usec,
 			cdr->end.tv_sec,
-			cdr->end.tv_usec,
+			(long)cdr->end.tv_usec,
 			ast_cdr_disp2str(cdr->disposition));
 }
 
@@ -1151,9 +1152,10 @@
 
 	if (cdr->party_a.snapshot->state == AST_STATE_UP && ast_tvzero(cdr->answer)) {
 		cdr->answer = ast_tvnow();
-		CDR_DEBUG(mod_cfg, "%p - Set answered time to %ld.%ld\n", cdr,
+		/* tv_usec is suseconds_t, which could be int or long */
+		CDR_DEBUG(mod_cfg, "%p - Set answered time to %ld.%06ld\n", cdr,
 			cdr->answer.tv_sec,
-			cdr->answer.tv_usec);
+			(long)cdr->answer.tv_usec);
 	}
 }
 




More information about the asterisk-commits mailing list