From 4aa47d68930a3ff4e750a6044f51524a76185899 Mon Sep 17 00:00:00 2001 From: "David M. Lee" Date: Mon, 17 Jun 2013 18:58:56 +0000 Subject: [PATCH] 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". git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@392076 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- funcs/func_cdr.c | 5 ++++- main/cdr.c | 14 ++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/funcs/func_cdr.c b/funcs/func_cdr.c index 0f900feda8..492716dcf6 100644 --- a/funcs/func_cdr.c +++ b/funcs/func_cdr.c @@ -248,11 +248,14 @@ static int cdr_read(struct ast_channel *chan, const char *cmd, char *parse, || !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)) { diff --git a/main/cdr.c b/main/cdr.c index b73f9cec2a..2ec6848373 100644 --- a/main/cdr.c +++ b/main/cdr.c @@ -1119,14 +1119,15 @@ static void cdr_object_finalize(struct cdr_object *cdr) } } - 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 @@ static void cdr_object_check_party_a_answer(struct cdr_object *cdr) { 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); } }