]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
clang compiler warnings: Fix -Wabsolute-value warnings
authorMatthew Jordan <mjordan@digium.com>
Mon, 30 Mar 2015 02:44:57 +0000 (02:44 +0000)
committerMatthew Jordan <mjordan@digium.com>
Mon, 30 Mar 2015 02:44:57 +0000 (02:44 +0000)
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)
........

Merged revisions 433749 from http://svn.asterisk.org/svn/asterisk/branches/11

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/13@433750 65c4cc65-6c06-0410-ace0-fbb531ad65f3

apps/app_queue.c
channels/chan_iax2.c
channels/sip/dialplan_functions.c
main/jitterbuf.c
res/res_calendar.c
res/res_rtp_asterisk.c

index 7b4faf0c058e1d5b49c7ea13b311729b2c7aa82f..9e5b8f51947273d3a0cd09e108f30135315f7c07 100644 (file)
@@ -3683,7 +3683,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;
 
@@ -3757,23 +3758,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;
@@ -6577,11 +6578,11 @@ static int try_calling(struct queue_ent *qe, struct ast_flags opts, char **opt_a
                                }
                                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) {
index e1fbbd10d54cf9c3a0769cb8493205d1a6480322..eeec1e1f11d1dd67b88b4c90efa938687e2abd87 100644 (file)
@@ -5999,7 +5999,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 */
@@ -6072,7 +6072,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
@@ -6091,7 +6092,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)
@@ -6113,9 +6113,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 */
                                {
@@ -6141,11 +6141,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;
                        }
index c3e113a8325914b1508c8e82042b4db39e43c93c..5ee66fbdb164be9d87d250dfc96bf44a19c6eefb 100644 (file)
@@ -386,7 +386,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;
index 4add56892c2bbf258dd015b04e08001574882137..1bfe508dac80fc5ddf772055d4ea1a2147b4afe9 100644 (file)
@@ -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 */
index 980e14125aec8297f1c968c5fa52c1d606a12d64..5b911ca5b747ccfd227671be4f3155beee0b7644 100644 (file)
@@ -1106,8 +1106,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)))) {
@@ -1120,16 +1120,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);
index f4910dbb931c1738c12855416e7a9050fcc7e32b..8300ef412c6f0540eb513b6aef770105d537cb17 100644 (file)
@@ -3147,10 +3147,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;
                        }
                }
@@ -3161,11 +3161,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;
                        }
                }
@@ -3175,11 +3175,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;
                        }
                }