Index: apps/app_queue.c
===================================================================
--- apps/app_queue.c	(revision 432991)
+++ apps/app_queue.c	(working copy)
@@ -5284,7 +5284,7 @@
 
 			if ((status = get_member_status(qe->parent, qe->max_penalty, qe->min_penalty, qe->parent->leavewhenempty, 0))) {
 				*reason = QUEUE_LEAVEEMPTY;
-				ast_queue_log(qe->parent->name, ast_channel_uniqueid(qe->chan), "NONE", "EXITEMPTY", "%d|%d|%ld", qe->pos, qe->opos, (long) time(NULL) - qe->start);
+				ast_queue_log(qe->parent->name, ast_channel_uniqueid(qe->chan), "NONE", "EXITEMPTY", "%d|%d|%ld", qe->pos, qe->opos, (long) (time(NULL) - qe->start));
 				leave_queue(qe);
 				break;
 			}
@@ -5702,8 +5702,8 @@
 
 	ast_queue_log(queue_data->queue->name, caller->uniqueid, queue_data->member->membername, "ATTENDEDTRANSFER", "%s|%ld|%ld|%d",
 			ast_str_buffer(transfer_str),
-			(long) queue_data->starttime - queue_data->holdstart,
-			(long) time(NULL) - queue_data->starttime, queue_data->caller_pos);
+			(long) (queue_data->starttime - queue_data->holdstart),
+			(long) (time(NULL) - queue_data->starttime), queue_data->caller_pos);
 }
 
 /*!
@@ -5789,8 +5789,8 @@
 	ast_queue_log(queue_data->queue->name, caller_snapshot->uniqueid, queue_data->member->membername,
 			"BLINDTRANSFER", "%s|%s|%ld|%ld|%d",
 			exten, context,
-			(long) queue_data->starttime - queue_data->holdstart,
-			(long) time(NULL) - queue_data->starttime, queue_data->caller_pos);
+			(long) (queue_data->starttime - queue_data->holdstart),
+			(long) (time(NULL) - queue_data->starttime), queue_data->caller_pos);
 
 	send_agent_complete(queue_data->queue->name, caller_snapshot, member_snapshot, queue_data->member,
 			queue_data->holdstart, queue_data->starttime, TRANSFER);
@@ -6657,7 +6657,7 @@
 			} else if (ast_check_hangup(qe->chan)) {
 				/* Caller must have hung up just before being connected */
 				ast_log(LOG_NOTICE, "Caller was about to talk to agent on %s but the caller hungup.\n", ast_channel_name(peer));
-				ast_queue_log(queuename, ast_channel_uniqueid(qe->chan), member->membername, "ABANDON", "%d|%d|%ld", qe->pos, qe->opos, (long) time(NULL) - qe->start);
+				ast_queue_log(queuename, ast_channel_uniqueid(qe->chan), member->membername, "ABANDON", "%d|%d|%ld", qe->pos, qe->opos, (long) (time(NULL) - qe->start));
 				record_abandoned(qe);
 				ast_channel_publish_dial(qe->chan, peer, member->interface, ast_hangup_cause_to_dial_status(ast_channel_hangupcause(peer)));
 				ast_autoservice_chan_hangup_peer(qe->chan, peer);
@@ -6705,7 +6705,7 @@
 		/* use  pbx_builtin_setvar to set a load of variables with one call */
 		if (qe->parent->setqueueentryvar) {
 			snprintf(interfacevar, sizeof(interfacevar), "QEHOLDTIME=%ld,QEORIGINALPOS=%d",
-				(long) time(NULL) - qe->start, qe->opos);
+				(long) (time(NULL) - qe->start), qe->opos);
 			pbx_builtin_setvar_multiple(qe->chan, interfacevar);
 			pbx_builtin_setvar_multiple(peer, interfacevar);
 		}
@@ -6831,7 +6831,7 @@
 			}
 		}
 		qe->handled++;
-		ast_queue_log(queuename, ast_channel_uniqueid(qe->chan), member->membername, "CONNECT", "%ld|%s|%ld", (long) time(NULL) - qe->start, ast_channel_uniqueid(peer),
+		ast_queue_log(queuename, ast_channel_uniqueid(qe->chan), member->membername, "CONNECT", "%ld|%s|%ld", (long) (time(NULL) - qe->start), ast_channel_uniqueid(peer),
 													(long)(orig - to > 0 ? (orig - to) / 1000 : 0));
 
 		blob = ast_json_pack("{s: s, s: s, s: s, s: i, s: i}",
@@ -6838,7 +6838,7 @@
 				     "Queue", queuename,
 				     "Interface", member->interface,
 				     "MemberName", member->membername,
-				     "HoldTime", (long) time(NULL) - qe->start,
+				     "HoldTime", (long) (time(NULL) - qe->start),
 				     "RingTime", (long)(orig - to > 0 ? (orig - to) / 1000 : 0));
 		queue_publish_multi_channel_blob(qe->chan, peer, queue_agent_connect_type(), blob);
 
@@ -7898,7 +7898,7 @@
 			reason = QUEUE_TIMEOUT;
 			res = 0;
 			ast_queue_log(args.queuename, ast_channel_uniqueid(chan),"NONE", "EXITWITHTIMEOUT", "%d|%d|%ld",
-				qe.pos, qe.opos, (long) time(NULL) - qe.start);
+				qe.pos, qe.opos, (long) (time(NULL) - qe.start));
 			break;
 		}
 
@@ -7964,7 +7964,7 @@
 			record_abandoned(&qe);
 			reason = QUEUE_TIMEOUT;
 			res = 0;
-			ast_queue_log(qe.parent->name, ast_channel_uniqueid(qe.chan),"NONE", "EXITWITHTIMEOUT", "%d|%d|%ld", qe.pos, qe.opos, (long) time(NULL) - qe.start);
+			ast_queue_log(qe.parent->name, ast_channel_uniqueid(qe.chan),"NONE", "EXITWITHTIMEOUT", "%d|%d|%ld", qe.pos, qe.opos, (long) (time(NULL) - qe.start));
 			break;
 		}
 
@@ -7993,7 +7993,7 @@
 				record_abandoned(&qe);
 				ast_queue_log(args.queuename, ast_channel_uniqueid(chan), "NONE", "ABANDON",
 					"%d|%d|%ld", qe.pos, qe.opos,
-					(long) time(NULL) - qe.start);
+					(long) (time(NULL) - qe.start));
 				res = -1;
 			} else if (qcontinue) {
 				reason = QUEUE_CONTINUE;
@@ -8001,7 +8001,7 @@
 			}
 		} else if (qe.valid_digits) {
 			ast_queue_log(args.queuename, ast_channel_uniqueid(chan), "NONE", "EXITWITHKEY",
-				"%s|%d|%d|%ld", qe.digits, qe.pos, qe.opos, (long) time(NULL) - qe.start);
+				"%s|%d|%d|%ld", qe.digits, qe.pos, qe.opos, (long) (time(NULL) - qe.start));
 		}
 	}
 
Index: funcs/func_cdr.c
===================================================================
--- funcs/func_cdr.c	(revision 432991)
+++ funcs/func_cdr.c	(working copy)
@@ -284,14 +284,16 @@
 			struct timeval fmt_time;
 			struct ast_tm tm;
 			/* tv_usec is suseconds_t, which could be int or long */
+			long int tv_sec;
 			long int tv_usec;
 
-			if (sscanf(tempbuf, "%ld.%ld", &fmt_time.tv_sec, &tv_usec) != 2) {
+			if (sscanf(tempbuf, "%ld.%ld", &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(payload->chan));
 				return;
 			}
-			if (fmt_time.tv_sec) {
+			if (tv_sec) {
+				fmt_time.tv_sec = tv_sec;
 				fmt_time.tv_usec = tv_usec;
 				ast_localtime(&fmt_time, &tm, NULL);
 				ast_strftime(tempbuf, sizeof(tempbuf), "%Y-%m-%d %T", &tm);
Index: main/cdr.c
===================================================================
--- main/cdr.c	(revision 432991)
+++ main/cdr.c	(working copy)
@@ -1257,11 +1257,11 @@
 	/* 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,
+			(long)cdr->start.tv_sec,
 			(long)cdr->start.tv_usec,
-			cdr->answer.tv_sec,
+			(long)cdr->answer.tv_sec,
 			(long)cdr->answer.tv_usec,
-			cdr->end.tv_sec,
+			(long)cdr->end.tv_sec,
 			(long)cdr->end.tv_usec,
 			ast_cdr_disp2str(cdr->disposition));
 }
@@ -1296,7 +1296,7 @@
 		cdr->answer = ast_tvnow();
 		/* 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,
+			(long)cdr->answer.tv_sec,
 			(long)cdr->answer.tv_usec);
 	}
 }
Index: main/cli.c
===================================================================
--- main/cli.c	(revision 432991)
+++ main/cli.c	(working copy)
@@ -1644,7 +1644,7 @@
 		ast_str_buffer(write_transpath),
 		ast_str_strlen(read_transpath) ? "Yes" : "No",
 		ast_str_buffer(read_transpath),
-		ast_channel_whentohangup(chan)->tv_sec,
+		(long)ast_channel_whentohangup(chan)->tv_sec,
 		cdrtime,
 		bridge ? bridge->uniqueid : "(Not bridged)",
 		ast_channel_context(chan),
Index: main/manager.c
===================================================================
--- main/manager.c	(revision 432991)
+++ main/manager.c	(working copy)
@@ -4420,7 +4420,7 @@
 		S_OR(ast_channel_dialed(chan)->number.str, ""),
 		S_COR(effective_id.number.valid, effective_id.number.str, "<unknown>"),
 		S_COR(effective_id.name.valid, effective_id.name.str, "<unknown>"),
-		ast_channel_whentohangup(chan)->tv_sec,
+		(long)ast_channel_whentohangup(chan)->tv_sec,
 		bridge ? bridge->uniqueid : "",
 		ast_channel_linkedid(chan),
 		ast_channel_appl(chan),
Index: main/rtp_engine.c
===================================================================
--- main/rtp_engine.c	(revision 432991)
+++ main/rtp_engine.c	(working copy)
@@ -1947,7 +1947,7 @@
 	if (payload->report->type == AST_RTP_RTCP_SR) {
 		char sec[32];
 		char usec[32];
-		snprintf(sec, sizeof(sec), "%lu", payload->report->sender_information.ntp_timestamp.tv_sec);
+		snprintf(sec, sizeof(sec), "%lu", (unsigned long)payload->report->sender_information.ntp_timestamp.tv_sec);
 		snprintf(usec, sizeof(usec), "%lu", (unsigned long)payload->report->sender_information.ntp_timestamp.tv_usec);
 		json_rtcp_sender_info = ast_json_pack("{s: s, s: s, s: i, s: i, s: i}",
 				"ntp_timestamp_sec", sec,
