]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Portably sscanf tv_usec 56/3356/2
authorDavid M. Lee <dlee@respoke.io>
Wed, 27 Jul 2016 15:33:23 +0000 (10:33 -0500)
committerDavid M. Lee <dlee@respoke.io>
Wed, 27 Jul 2016 17:48:17 +0000 (12:48 -0500)
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

funcs/func_cdr.c

index dc865934fcf76e24a46ba943ce0bebe456d1733d..e67bca31884f51ac42ff75d9f36ec3c2e1682a4e 100644 (file)
@@ -223,9 +223,11 @@ STASIS_MESSAGE_TYPE_DEFN_LOCAL(cdr_prop_write_message_type);
 
 static struct timeval cdr_retrieve_time(struct ast_channel *chan, const char *time_name)
 {
-       struct timeval time;
+       struct timeval time = { 0 };
        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 @@ static struct timeval cdr_retrieve_time(struct ast_channel *chan, const char *ti
                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);
        }