[Asterisk-code-review] Portably sscanf tv usec (asterisk[master])

David M. Lee asteriskteam at digium.com
Wed Jul 27 10:49:32 CDT 2016


David M. Lee has uploaded a new change for review.

  https://gerrit.asterisk.org/3358

Change subject: Portably sscanf tv_usec
......................................................................

Portably sscanf tv_usec

In a timeval, tv_usec is defined as a suseconds_t, which could be
different underlying types on different platforms. Instead of trying to
scanf directly into the timeval, scanf into a long int, then copy that
into the timeval.

Change-Id: I29f22d049d3f7746b6c0cc23fbf4293bdaa5eb95
---
M funcs/func_cdr.c
1 file changed, 7 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/58/3358/1

diff --git a/funcs/func_cdr.c b/funcs/func_cdr.c
index ae15f6a..88c62c0 100644
--- a/funcs/func_cdr.c
+++ b/funcs/func_cdr.c
@@ -226,6 +226,8 @@
 	struct timeval time;
 	char *value = NULL;
 	char tempbuf[128];
+	long int tv_sec;
+	long int tv_usec;
 
 	if (ast_strlen_zero(ast_channel_name(chan))) {
 		/* Format request on a dummy channel */
@@ -234,7 +236,11 @@
 		ast_cdr_getvar(ast_channel_name(chan), time_name, tempbuf, sizeof(tempbuf));
 	}
 
-	if (sscanf(tempbuf, "%ld.%ld", &time.tv_sec, &time.tv_usec) != 2) {
+	/* time.tv_usec is suseconds_t, which could be int or long */
+	if (sscanf(tempbuf, "%ld.%ld", &tv_sec, &tv_usec) == 2) {
+		time.tv_sec = tv_sec;
+		time.tv_usec = tv_usec;
+	} else {
 		ast_log(AST_LOG_WARNING, "Failed to fully extract '%s' from CDR\n", time_name);
 	}
 

-- 
To view, visit https://gerrit.asterisk.org/3358
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I29f22d049d3f7746b6c0cc23fbf4293bdaa5eb95
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: David M. Lee <dlee at digium.com>



More information about the asterisk-code-review mailing list