From ff03f67663b53abc89555c98fbbdfe51547d833d Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 11 Jan 2017 13:54:06 +0200 Subject: [PATCH] Fix infinite loop in method VAbstractDetail::CheckLoops(). --HG-- branch : develop --- .../collection/bugs/possible_inf_loop.val | 464 ++++++++++++++++++ src/libs/vlayout/vabstractdetail.cpp | 2 +- .../ValentinaTest/tst_vabstractdetail.cpp | 141 ++++++ src/test/ValentinaTest/tst_vabstractdetail.h | 2 + 4 files changed, 608 insertions(+), 1 deletion(-) create mode 100644 src/app/share/collection/bugs/possible_inf_loop.val diff --git a/src/app/share/collection/bugs/possible_inf_loop.val b/src/app/share/collection/bugs/possible_inf_loop.val new file mode 100644 index 000000000..6a446a701 --- /dev/null +++ b/src/app/share/collection/bugs/possible_inf_loop.val @@ -0,0 +1,464 @@ + + + + 0.3.9 + cm + Timo Virtaneva + Female Basic Block + Differen Dart locations available + Female Basic Block + F-Basic-Bloack-2016 + Stinde Design + Customer + Measured + true + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
diff --git a/src/libs/vlayout/vabstractdetail.cpp b/src/libs/vlayout/vabstractdetail.cpp index 8173e699c..00372a5c2 100644 --- a/src/libs/vlayout/vabstractdetail.cpp +++ b/src/libs/vlayout/vabstractdetail.cpp @@ -588,7 +588,7 @@ QVector VAbstractDetail::CheckLoops(const QVector &points) /*We have found a loop.*/ ekvPoints.append(points.at(i)); ekvPoints.append(points.at(jNext)); - i = jNext; // Skip a loop + jNext > j ? i = jNext : i = j; // Skip a loop break; case BoundedIntersection: ekvPoints.append(points.at(i)); diff --git a/src/test/ValentinaTest/tst_vabstractdetail.cpp b/src/test/ValentinaTest/tst_vabstractdetail.cpp index 9e3e1ca24..63fc8d181 100644 --- a/src/test/ValentinaTest/tst_vabstractdetail.cpp +++ b/src/test/ValentinaTest/tst_vabstractdetail.cpp @@ -841,6 +841,147 @@ void TST_VAbstractDetail::TestCorrectEquidistantPoints() const Comparison(after, expect); } +//--------------------------------------------------------------------------------------------------------------------- +void TST_VAbstractDetail::PossibleInfiniteClearLoops_data() const +{ + QTest::addColumn>("path"); + QTest::addColumn>("expect"); + + QVector path; + path << QPointF(-670.6449010946802, 4046.36220472441); + path << QPointF(-1025.9051277126944, 4046.36220472441); + path << QPointF(-1026.4460203880594, 4010.5247429150854); + path << QPointF(-1027.2972172274538, 3924.202328582098); + path << QPointF(-1028.1383921346433, 3768.5948526129496); + path << QPointF(-1028.5065585022217, 3521.575730066707); + path << QPointF(-1028.2712136539103, 3252.2436039362233); + path << QPointF(-1027.2910122410117, 2850.1024469719814); + path << QPointF(-1025.9446023682538, 2439.350819630564); + path << QPointF(-1025.8983315247287, 2338.629525677473); + path << QPointF(-1025.3536572186458, 2309.970015878699); + path << QPointF(-1024.2100836932389, 2281.714612342931); + path << QPointF(-1022.5102766116828, 2253.846781520112); + path << QPointF(-1020.2969016371525, 2226.349989860186); + path << QPointF(-1017.6126244328227, 2199.207703813094); + path << QPointF(-1014.5001106618688, 2172.403389828782); + path << QPointF(-1011.0020259874652, 2145.9205143571917); + path << QPointF(-1005.1601480132764, 2106.7277181407126); + path << QPointF(-996.3625412018714, 2055.4921956731814); + path << QPointF(-986.7906327138169, 2005.2448233555149); + path << QPointF(-976.785747854512, 1955.8533327872588); + path << QPointF(-961.6606968634906, 1883.0158867454916); + path << QPointF(-947.5864881030896, 1811.4914675744105); + path << QPointF(-939.2629508127773, 1764.2008199992524); + path << QPointF(-933.8852659113251, 1728.8707137815559); + path << QPointF(-930.742733377741, 1705.3464944792456); + path << QPointF(-928.0252775410311, 1681.829576238578); + path << QPointF(-925.7755640643697, 1658.3034255094963); + path << QPointF(-924.036258610932, 1634.7515087419433); + path << QPointF(-922.850026843893, 1611.1572923858625); + path << QPointF(-922.2595344264276, 1587.504242891197); + path << QPointF(-922.3074470217107, 1563.7758267078902); + path << QPointF(-922.613405031688, 1551.8740157480315); + path << QPointF(-960.4086806222392, 841.3228346456693); + path << QPointF(-954.9336313684444, 841.5464781141166); + path << QPointF(-944.0363771538431, 841.3102753632543); + path << QPointF(-933.2160856340209, 840.291423017261); + path << QPointF(-922.4878118569704, 838.5316299985567); + path << QPointF(-911.8666108706839, 836.0726052295611); + path << QPointF(-901.3675377231535, 832.9560576326933); + path << QPointF(-891.005647462372, 829.2236961303737); + path << QPointF(-880.7959951363317, 824.9172296450213); + path << QPointF(-870.7536357930251, 820.0783670990559); + path << QPointF(-860.893624480444, 814.7488174148973); + path << QPointF(-851.2310162465817, 808.9702895149649); + path << QPointF(-841.7808661394299, 802.7844923216785); + path << QPointF(-832.5582292069812, 796.2331347574575); + path << QPointF(-823.578160497228, 789.3579257447218); + path << QPointF(-810.5607800373014, 778.5565764202543); + path << QPointF(-794.2367125298769, 763.3635567727296); + path << QPointF(-779.1539087770976, 747.6258919346988); + path << QPointF(-765.4328091629026, 731.6772532855191); + path << QPointF(-753.193854071231, 715.8513122045474); + path << QPointF(-742.557483886022, 700.4817400711408); + path << QPointF(-733.644138991215, 685.9022082646563); + path << QPointF(-726.5742597707488, 672.446388164451); + path << QPointF(-721.4682866085625, 660.447951149882); + path << QPointF(-718.6229063234249, 651.1532303788147); + path << QPointF(-716.6036430255488, 642.9038041285014); + path << QPointF(-714.137568179324, 630.1235656609365); + path << QPointF(-711.8605525364693, 612.2344502588126); + path << QPointF(-710.4560555432737, 593.4222205889721); + path << QPointF(-709.4234847119759, 563.5940176156308); + path << QPointF(-708.952111561728, 520.4666582691573); + path << QPointF(-708.4401766852314, 497.3858267716535); + path << QPointF(-400.92922424489655, 469.03937007874015); + path << QPointF(-708.4401766852314, 440.6929133858268); + path << QPointF(-708.7078446526739, 341.66122584661264); + path << QPointF(-709.3427685457568, 299.60322373665383); + path << QPointF(-710.6909230403871, 257.048095841136); + path << QPointF(-713.0251717477311, 214.57984397612822); + path << QPointF(-715.632864794307, 183.1716335401434); + path << QPointF(-717.7953694429818, 162.55016633308693); + path << QPointF(-720.3578834261159, 142.27891915519677); + path << QPointF(-723.3545146951046, 122.43089223348173); + path << QPointF(-725.0465030138121, 112.71059563115871); + path << QPointF(-219.59055118110237, -35.52755905511811); + path << QPointF(-218.99352387527398, -33.21125072212394); + path << QPointF(-217.35724543521775, -28.699086141666157); + path << QPointF(-215.20035586903225, -24.33136255454731); + path << QPointF(-212.53403014110648, -20.10796717265881); + path << QPointF(-209.36944321582945, -16.02878720789205); + path << QPointF(-205.71777005759026, -12.093709872138447); + path << QPointF(-201.59018563077785, -8.302622377289406); + path << QPointF(-196.99786489978123, -4.65541193523633); + path << QPointF(-189.3170483291933, 0.5638303631539586); + path << QPointF(-177.47808861476295, 6.996342387787443); + path << QPointF(-163.981333042598, 12.855376387191757); + path << QPointF(-148.91618132781048, 18.141834666235646); + path << QPointF(-132.37203318551252, 22.856619529787864); + path << QPointF(-114.43828833081622, 27.00063328271716); + path << QPointF(-95.20434647883366, 30.574778229892296); + path << QPointF(-74.75960734467688, 33.57995667618201); + path << QPointF(-53.193470643458, 36.01707092645505); + path << QPointF(-30.595336090289106, 37.887023285580185); + path << QPointF(-7.0546034002822875, 39.19071605842615); + path << QPointF(17.339327711450373, 39.929051549861704); + path << QPointF(29.858267716535437, 40.06299212598426); + path << QPointF(-45.73228346456693, 1589.6692913385828); + path << QPointF(-45.73228346456693, 4046.36220472441); + path << QPointF(-297.70078740157487, 4046.36220472441); + path << QPointF(-297.70078740157487, 2118.8031496062995); + path << QPointF(-222.1102362204725, 1589.6692913385828); + path << QPointF(-297.70078740157487, 1060.535433070866); + path << QPointF(-373.2913385826772, 1589.6692913385828); + path << QPointF(-297.70078740157487, 2118.8031496062995); + path << QPointF(-297.70078740157487, 4046.36220472441); + path << QPointF(-670.6449010946802, 4046.36220472441); + path << QPointF(-670.6449010946802, 2024.3149606299214); + path << QPointF(-622.7555214134819, 1570.7716535433071); + path << QPointF(-670.6449010946802, 1117.2283464566929); + path << QPointF(-718.5342807758785, 1570.7716535433071); + path << QPointF(-670.6449010946802, 2024.3149606299214); + + QVector expect; + expect << QPointF(-670.6449010946802, 4046.36220472441); + expect << QPointF(-670.6449010946802, 4046.36220472441); + expect << QPointF(-670.6449010946802, 2024.3149606299214); + expect << QPointF(-670.6449010946802, 2024.3149606299214); + expect << QPointF(-670.6449010946802, 2024.3149606299214); + + QTest::newRow("Possible infinite loop") << path << expect; +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VAbstractDetail::PossibleInfiniteClearLoops() const +{ + QFETCH(QVector, path); + QFETCH(QVector, expect); + + QVector res = VAbstractDetail::CheckLoops(path); + Comparison(res, expect); +} + //--------------------------------------------------------------------------------------------------------------------- void TST_VAbstractDetail::Case3() const { diff --git a/src/test/ValentinaTest/tst_vabstractdetail.h b/src/test/ValentinaTest/tst_vabstractdetail.h index 0fa1c2739..5749853f2 100644 --- a/src/test/ValentinaTest/tst_vabstractdetail.h +++ b/src/test/ValentinaTest/tst_vabstractdetail.h @@ -53,6 +53,8 @@ private slots: void CorrectEquidistantPoints() const; void TestCorrectEquidistantPoints_data(); void TestCorrectEquidistantPoints() const; + void PossibleInfiniteClearLoops_data() const; + void PossibleInfiniteClearLoops() const; private: void Case3() const;