clang compiler warnings: Fix -Wabsolute-value warnings

This patch fixes several warnings caught by clang - in this case, usage of the
abs function on non-integer values. This patch uses labs and fabs, as
appropriate, in the various affected files.

Review: https://reviewboard.asterisk.org/r/4525

ASTERISK-24917
Reported by: dkdegroot
patches:
  rb4525.patch submitted by dkdegroot (License 6600)


git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/11@433749 65c4cc65-6c06-0410-ace0-fbb531ad65f3
changes/61/61/1
Matthew Jordan 10 years ago
parent b8d7aa442d
commit 297b8df31b

@ -3129,7 +3129,8 @@ static int valid_exit(struct queue_ent *qe, char digit)
static int say_position(struct queue_ent *qe, int ringing)
{
int res = 0, avgholdmins, avgholdsecs, announceposition = 0;
int res = 0, announceposition = 0;
long avgholdmins, avgholdsecs;
int say_thanks = 1;
time_t now;
@ -3203,23 +3204,23 @@ static int say_position(struct queue_ent *qe, int ringing)
}
}
/* Round hold time to nearest minute */
avgholdmins = abs(((qe->parent->holdtime + 30) - (now - qe->start)) / 60);
avgholdmins = labs(((qe->parent->holdtime + 30) - (now - qe->start)) / 60);
/* If they have specified a rounding then round the seconds as well */
if (qe->parent->roundingseconds) {
avgholdsecs = (abs(((qe->parent->holdtime + 30) - (now - qe->start))) - 60 * avgholdmins) / qe->parent->roundingseconds;
avgholdsecs = (labs(((qe->parent->holdtime + 30) - (now - qe->start))) - 60 * avgholdmins) / qe->parent->roundingseconds;
avgholdsecs *= qe->parent->roundingseconds;
} else {
avgholdsecs = 0;
}
ast_verb(3, "Hold time for %s is %d minute(s) %d seconds\n", qe->parent->name, avgholdmins, avgholdsecs);
ast_verb(3, "Hold time for %s is %ld minute(s) %ld seconds\n", qe->parent->name, avgholdmins, avgholdsecs);
/* If the hold time is >1 min, if it's enabled, and if it's not
supposed to be only once and we have already said it, say it */
if ((avgholdmins+avgholdsecs) > 0 && qe->parent->announceholdtime &&
((qe->parent->announceholdtime == ANNOUNCEHOLDTIME_ONCE && !qe->last_pos) ||
!(qe->parent->announceholdtime == ANNOUNCEHOLDTIME_ONCE))) {
if ((avgholdmins+avgholdsecs) > 0 && qe->parent->announceholdtime &&
((qe->parent->announceholdtime == ANNOUNCEHOLDTIME_ONCE && !qe->last_pos) ||
!(qe->parent->announceholdtime == ANNOUNCEHOLDTIME_ONCE))) {
res = play_file(qe->chan, qe->parent->sound_holdtime);
if (res) {
goto playout;
@ -5568,11 +5569,11 @@ static int try_calling(struct queue_ent *qe, const struct ast_flags opts, char *
}
if (!res2 && qe->parent->reportholdtime) {
if (!play_file(peer, qe->parent->sound_reporthold)) {
int holdtime, holdtimesecs;
long holdtime, holdtimesecs;
time(&now);
holdtime = abs((now - qe->start) / 60);
holdtimesecs = abs((now - qe->start) % 60);
holdtime = labs((now - qe->start) / 60);
holdtimesecs = labs((now - qe->start) % 60);
if (holdtime > 0) {
ast_say_number(peer, holdtime, AST_DIGIT_ANY, ast_channel_language(peer), NULL);
if (play_file(peer, qe->parent->sound_minutes) < 0) {

@ -6062,7 +6062,7 @@ static unsigned int calc_txpeerstamp(struct iax2_trunk_peer *tpeer, int sampms,
ms = ast_tvdiff_ms(*now, tpeer->txtrunktime);
/* Predict from last value */
pred = tpeer->lastsent + sampms;
if (abs(ms - pred) < MAX_TIMESTAMP_SKEW)
if (labs(ms - pred) < MAX_TIMESTAMP_SKEW)
ms = pred;
/* We never send the same timestamp twice, so fudge a little if we must */
@ -6134,7 +6134,8 @@ static unsigned int calc_timestamp(struct chan_iax2_pvt *p, unsigned int ts, str
ms = 0;
if (voice) {
/* On a voice frame, use predicted values if appropriate */
if (p->notsilenttx && abs(ms - p->nextpred) <= MAX_TIMESTAMP_SKEW) {
adjust = (ms - p->nextpred);
if (p->notsilenttx && abs(adjust) <= MAX_TIMESTAMP_SKEW) {
/* Adjust our txcore, keeping voice and non-voice synchronized */
/* AN EXPLANATION:
When we send voice, we usually send "calculated" timestamps worked out
@ -6153,7 +6154,6 @@ static unsigned int calc_timestamp(struct chan_iax2_pvt *p, unsigned int ts, str
changing at all. But if a consistent different starts to develop it
will be eliminated over the course of 10 frames (200-300msecs)
*/
adjust = (ms - p->nextpred);
if (adjust < 0)
p->offset = ast_tvsub(p->offset, ast_samp2tv(abs(adjust), 10000));
else if (adjust > 0)
@ -6175,9 +6175,9 @@ static unsigned int calc_timestamp(struct chan_iax2_pvt *p, unsigned int ts, str
* silent periods are multiples of
* frame size too) */
if (iaxdebug && abs(ms - p->nextpred) > MAX_TIMESTAMP_SKEW )
if (iaxdebug && abs(adjust) > MAX_TIMESTAMP_SKEW )
ast_debug(1, "predicted timestamp skew (%d) > max (%d), using real ts instead.\n",
abs(ms - p->nextpred), MAX_TIMESTAMP_SKEW);
abs(adjust), MAX_TIMESTAMP_SKEW);
if (f->samples >= rate) /* check to make sure we don't core dump */
{
@ -6203,11 +6203,12 @@ static unsigned int calc_timestamp(struct chan_iax2_pvt *p, unsigned int ts, str
} else {
/* On a dataframe, use last value + 3 (to accomodate jitter buffer shrinking) if appropriate unless
it's a genuine frame */
adjust = (ms - p->lastsent);
if (genuine) {
/* genuine (IAX LAGRQ etc) must keep their clock-based stamps */
if (ms <= p->lastsent)
ms = p->lastsent + 3;
} else if (abs(ms - p->lastsent) <= MAX_TIMESTAMP_SKEW) {
} else if (abs(adjust) <= MAX_TIMESTAMP_SKEW) {
/* non-genuine frames (!?) (DTMF, CONTROL) should be pulled into the predicted stream stamps */
ms = p->lastsent + 3;
}

@ -384,7 +384,7 @@ AST_TEST_DEFINE(test_sip_rtpqos_1)
for (j = 1.0; j < 10.0; j += 0.3) {
*lookup[i].d8 = j;
ast_str_substitute_variables(&buffer, 0, chan, ast_str_buffer(varstr));
if (sscanf(ast_str_buffer(buffer), "%lf", &cmpdbl) != 1 || fabs(j - cmpdbl > .05)) {
if (sscanf(ast_str_buffer(buffer), "%lf", &cmpdbl) != 1 || abs(j - cmpdbl > .05)) {
res = AST_TEST_FAIL;
ast_test_status_update(test, "%s != %f != %s\n", ast_str_buffer(varstr), j, ast_str_buffer(buffer));
break;

@ -139,7 +139,7 @@ static int check_resync(jitterbuf *jb, long ts, long now, long ms, const enum jb
/* check for drastic change in delay */
if (jb->info.conf.resync_threshold != -1) {
if (abs(*delay - jb->info.last_delay) > threshold) {
if (labs(*delay - jb->info.last_delay) > threshold) {
jb->info.cnt_delay_discont++;
/* resync the jitterbuffer on 3 consecutive discontinuities,
* or immediately if a control frame */

@ -1080,8 +1080,8 @@ static struct ast_custom_function calendar_busy_function = {
static int add_event_to_list(struct eventlist *events, struct ast_calendar_event *event, time_t start, time_t end)
{
struct evententry *entry, *iter;
int event_startdiff = abs(start - event->start);
int event_enddiff = abs(end - event->end);
long event_startdiff = labs(start - event->start);
long event_enddiff = labs(end - event->end);
int i = 0;
if (!(entry = ast_calloc(1, sizeof(*entry)))) {
@ -1094,16 +1094,16 @@ static int add_event_to_list(struct eventlist *events, struct ast_calendar_event
if (start == end) {
AST_LIST_TRAVERSE_SAFE_BEGIN(events, iter, list) {
int startdiff = abs(iter->event->start - start);
long startdiff = labs(iter->event->start - start);
ast_debug(10, "Comparing %s with startdiff %d to %s with startdiff %d\n", event->summary, event_startdiff, iter->event->summary, startdiff);
ast_debug(10, "Comparing %s with startdiff %ld to %s with startdiff %ld\n", event->summary, event_startdiff, iter->event->summary, startdiff);
++i;
if (startdiff > event_startdiff) {
AST_LIST_INSERT_BEFORE_CURRENT(entry, list);
return i;
}
if (startdiff == event_startdiff) {
int enddiff = abs(iter->event->end - end);
long enddiff = labs(iter->event->end - end);
if (enddiff > event_enddiff) {
AST_LIST_INSERT_BEFORE_CURRENT(entry, list);

@ -3123,10 +3123,10 @@ static int ast_rtp_raw_write(struct ast_rtp_instance *instance, struct ast_frame
if (ast_tvzero(frame->delivery)) {
/* If this isn't an absolute delivery time, Check if it is close to our prediction,
and if so, go with our prediction */
if (abs(rtp->lastts - pred) < MAX_TIMESTAMP_SKEW) {
if (abs((int)rtp->lastts - pred) < MAX_TIMESTAMP_SKEW) {
rtp->lastts = pred;
} else {
ast_debug(3, "Difference is %d, ms is %u\n", abs(rtp->lastts - pred), ms);
ast_debug(3, "Difference is %d, ms is %u\n", abs((int)rtp->lastts - pred), ms);
mark = 1;
}
}
@ -3137,11 +3137,11 @@ static int ast_rtp_raw_write(struct ast_rtp_instance *instance, struct ast_frame
rtp->lastts = rtp->lastts + ms * 90;
/* If it's close to our prediction, go for it */
if (ast_tvzero(frame->delivery)) {
if (abs(rtp->lastts - pred) < 7200) {
if (abs((int)rtp->lastts - pred) < 7200) {
rtp->lastts = pred;
rtp->lastovidtimestamp += frame->samples;
} else {
ast_debug(3, "Difference is %d, ms is %u (%u), pred/ts/samples %u/%d/%d\n", abs(rtp->lastts - pred), ms, ms * 90, rtp->lastts, pred, frame->samples);
ast_debug(3, "Difference is %d, ms is %u (%u), pred/ts/samples %u/%d/%d\n", abs((int)rtp->lastts - pred), ms, ms * 90, rtp->lastts, pred, frame->samples);
rtp->lastovidtimestamp = rtp->lastts;
}
}
@ -3151,11 +3151,11 @@ static int ast_rtp_raw_write(struct ast_rtp_instance *instance, struct ast_frame
rtp->lastts = rtp->lastts + ms;
/* If it's close to our prediction, go for it */
if (ast_tvzero(frame->delivery)) {
if (abs(rtp->lastts - pred) < 7200) {
if (abs((int)rtp->lastts - pred) < 7200) {
rtp->lastts = pred;
rtp->lastotexttimestamp += frame->samples;
} else {
ast_debug(3, "Difference is %d, ms is %u, pred/ts/samples %u/%d/%d\n", abs(rtp->lastts - pred), ms, rtp->lastts, pred, frame->samples);
ast_debug(3, "Difference is %d, ms is %u, pred/ts/samples %u/%d/%d\n", abs((int)rtp->lastts - pred), ms, rtp->lastts, pred, frame->samples);
rtp->lastotexttimestamp = rtp->lastts;
}
}

Loading…
Cancel
Save