diff options
author | David M. Lee <dlee@respoke.io> | 2016-07-27 10:33:23 -0500 |
---|---|---|
committer | David M. Lee <dlee@digium.com> | 2016-07-27 13:09:01 -0500 |
commit | feb1a434122a3cd3cbe4a6e75a4bd76a677bdb0d (patch) | |
tree | 56e04edc332a10b989f28e47f0721224959a3362 /funcs | |
parent | 49461f37b75aa27275d1c4811007e2a7f94ac002 (diff) |
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
Diffstat (limited to 'funcs')
-rw-r--r-- | funcs/func_cdr.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/funcs/func_cdr.c b/funcs/func_cdr.c index ae15f6aa9..8dcb2bd0b 100644 --- a/funcs/func_cdr.c +++ b/funcs/func_cdr.c @@ -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); } |