]> git.tdb.fi Git - libs/gltk.git/commitdiff
Fix a crash if the linear program contains an empty column
authorMikko Rasa <tdb@tdb.fi>
Tue, 27 Nov 2012 07:38:29 +0000 (09:38 +0200)
committerMikko Rasa <tdb@tdb.fi>
Tue, 27 Nov 2012 14:50:31 +0000 (16:50 +0200)
source/layout.cpp

index b95ab92ffd0f85685216a7501ad35131e0e45f3e..74b33f0bce1933de385720eed1eabe6e821956b2 100644 (file)
@@ -383,10 +383,14 @@ bool Layout::LinearProgram::solve()
        pricing out the constraint rows. */
        for(vector<Column>::iterator i=columns.begin(); i!=columns.end(); ++i)
        {
-               float objective = i->values.front();
-               i->values.front() = 0.0f;
-               for(vector<float>::iterator j=i->values.begin(); j!=i->values.end(); ++j)
-                       i->values.front() += *j;
+               float objective = 0.0f;
+               if(!i->values.empty())
+               {
+                       objective = i->values.front();
+                       i->values.front() = 0.0f;
+                       for(vector<float>::iterator j=i->values.begin(); j!=i->values.end(); ++j)
+                               i->values.front() += *j;
+               }
                i->values.resize(n_rows+1, 0.0f);
                i->values.back() = objective;
        }