Page MenuHomePhabricator

DB: fix functions random generation
ClosedPublic

Authored by JackDanielZ on Dec 21 2018, 12:51 AM.

Details

Summary

When the file DB was merged into the destination DB, the nb_occ of the widget functions was just incremented by 1 without taking into account if the function is always used or not. This led to always generate the function at the widget generation.
To fix this, we increment the nb_occ by the frequency (e.g 0.22 = nb_occ / wdg->nb_occ) instead of 1.

@fix T7513

Diff Detail

Branch
arcpatch-D7499
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 8590
Build 7640: arc lint + arc unit
JackDanielZ requested review of this revision.Dec 21 2018, 12:51 AM
JackDanielZ created this revision.
jsuya added a comment.Dec 23 2018, 9:04 PM

The result of calculation is 0 with type casting.
Eventually, max of the random function becomes -1, causing segfault.

src/bin/db.c
2645

Some int *_occ are using _Wdg_Function->nb_occ.
I think we need to check all the code that uses this.

Fix calculation

Hi Junsu,

Thanks for the review, I missed this one... and a few other :-)

jsuya added inline comments.Dec 26 2018, 1:46 AM
src/bin/db.c
2753

i think it need to change rand() to frand()

Replace rand with frand

JackDanielZ added inline comments.Dec 27 2018, 1:23 AM
src/bin/db.c
2753

Super right! :-) Good catch!

This revision is now accepted and ready to land.Dec 27 2018, 2:02 AM
JackDanielZ closed this revision.Dec 27 2018, 3:25 AM