Overflow in pj_math_stat_update

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Ravi,

The code maintains the accumulation of integer division residue from
the previous line:
    stat->mean += delta/stat->n;
This mean residue (mean_res_) can be considered as an approximation to
'decimal' part of mean.

Regards,
nanang


2008/7/29 Ravi Inder Singh <raviinder at gmail.com>:
> Hi Nanag,
>    Will provide you details soon, but i cannot understand for what this code
> is used in pj_math_stat_update, i cannot get it
> -------------------------------------------------
> stat->mean_res_ += delta % stat->n;
>     if (stat->mean_res_ >= stat->n) {
>  ++stat->mean;
>  stat->mean_res_ -= stat->n;
>     } else if (stat->mean_res_ <= -stat->n) {
>  --stat->mean;
>  stat->mean_res_ += stat->n;
> -----------------------------------------------------
> Regards,
> Ravi
>
> On Mon, Jul 28, 2008 at 6:25 PM, Nanang Izzuddin <nanang at pjsip.org> wrote:
>>
>> Hi Ravi,f
>>
>> m afraid the sample data you've given is not detail enough, i.e:
>> beside the new sample to be added (=91) and the mean (=95), could you
>> give a bit more detail on pj_math_stat instance fields values (at
>> least samples number/'n' and mean residu/'mean_res_') right before the
>> overflow happens.
>>
>> Or if you could give a simple snippet code to reproduce the problem,
>> something like:
>>
>> #define PJ_HAS_FLOATING_POINT       0
>> #include <pj/math.h>
>>
>> int main() {
>>    pj_math_stat ms;
>>
>>    pj_math_stat_init(&ms);
>>
>>
>>    ms.mean_res_ = 0;
>>    ms.mean = 95;
>>    ms.n = 1000;
>>    pj_math_stat_update(&ms, 91);
>> }
>>
>>
>> Regards,
>> nanang
>>
>>
>> 2008/7/23 Ravi Inder Singh <raviinder at gmail.com>:
>> > Hi Benny,
>> >    I don't have floating points so compiled off PJ_HAS_FLOATING_POINT &
>> > val(
>> > Jitter ) = 91 & mean = (95), so its simply taking integer values of
>> > delta.
>> > Its comes to be -4.
>> > Did i done something wrong please let me know ?
>> >
>> > Regards,
>> > Ravi Inder Singh
>> >
>> > On Tue, Jul 22, 2008 at 5:35 PM, Benny Prijono <bennylp at pjsip.org>
>> > wrote:
>> >>
>> >> On Tue, Jul 22, 2008 at 12:41 PM, Ravi Inder Singh
>> >> <raviinder at gmail.com>
>> >> wrote:
>> >>>
>> >>> Hi all,
>> >>>  Inside fuction pj_math_stat_update,calling from
>> >>> pjmedia_rtcp_xr_rx_rtp
>> >>> is leading to overflow in mean calculation, as jitter value is less
>> >>> than
>> >>> mean value & delta comes out to be in minus value.
>> >>>
>> >>>    delta = val - stat->mean; {leads to minus value, coz while setting
>> >>> we
>> >>> make it divide by 16 in this code
>> >>>
>> >>> #if defined(PJMEDIA_HAS_RTCP_XR) && (PJMEDIA_HAS_RTCP_XR != 0)
>> >>>         pjmedia_rtcp_xr_rx_rtp(&sess->xr_session, seq,
>> >>>                    0,                /* lost    */
>> >>>                    0,                /* dup     */
>> >>>                    discarded,            /* discard */
>> >>>                    (sess->jitter >> 4),        /* jitter  */
>> >>>                    -1, 0);            /* toh     */
>> >>> #endif
>> >>>
>> >>> }
>> >>> This all leads to some overflow value in int variable, leading wrong
>> >>> results.
>> >>
>> >> Minus value in delta variable is perfectly fine, and unless you give
>> >> negative "val" value, the "fmean_" and "mean" variable will never have
>> >> negative value.
>> >>
>> >> Do you have sample data to prove your observation?
>> >>
>> >> Cheers
>> >>  Benny
>> >>
>> >>
>> >> _______________________________________________
>> >> Visit our blog: http://blog.pjsip.org
>> >>
>> >> pjsip mailing list
>> >> pjsip at lists.pjsip.org
>> >> http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
>> >>
>> >
>> >
>> >
>> > --
>> > Thanks & Regards,
>> > Ravi Inder Singh
>> > _______________________________________________
>> > Visit our blog: http://blog.pjsip.org
>> >
>> > pjsip mailing list
>> > pjsip at lists.pjsip.org
>> > http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
>> >
>> >
>>
>> _______________________________________________
>> Visit our blog: http://blog.pjsip.org
>>
>> pjsip mailing list
>> pjsip at lists.pjsip.org
>> http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
>
>
>
> --
> Thanks & Regards,
> Ravi Inder Singh
>
> _______________________________________________
> Visit our blog: http://blog.pjsip.org
>
> pjsip mailing list
> pjsip at lists.pjsip.org
> http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
>
>



[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux