summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorDavid Tardon <dtardon@redhat.com>2015-07-16 18:43:34 +0200
committerDavid Tardon <dtardon@redhat.com>2015-07-16 18:44:52 +0200
commit03eed259ce331998af623cf5da5320441ed55d1f (patch)
tree9da40da61615c6f170278ff23a8911f489e862cd /src/lib
parent4a2e82ddca257374ab04c7bbbc1869e666a2d6b9 (diff)
avoid endless loop when reading broken file
Change-Id: I4956a3438d273a06a11d96031e2759062dce1e95
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/VSDStyles.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/lib/VSDStyles.cpp b/src/lib/VSDStyles.cpp
index ff29267..f8fd33d 100644
--- a/src/lib/VSDStyles.cpp
+++ b/src/lib/VSDStyles.cpp
@@ -7,6 +7,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
+#include <set>
#include <stack>
#include "VSDStyles.h"
#include "VSDTypes.h"
@@ -24,12 +25,18 @@ T getOptionalStyle(const std::map<unsigned, unsigned> &styleMasters, const std::
if (MINUS_ONE == styleIndex)
return style;
std::stack<unsigned> styleIdStack;
+ std::set<unsigned> foundStyles;
styleIdStack.push(styleIndex);
while (true)
{
std::map<unsigned, unsigned>::const_iterator iter = styleMasters.find(styleIdStack.top());
if (iter != styleMasters.end() && iter->second != MINUS_ONE)
- styleIdStack.push(iter->second);
+ {
+ if (foundStyles.insert(iter->second).second)
+ styleIdStack.push(iter->second);
+ else // we already have this style -> stop incoming endless loop
+ break;
+ }
else
break;
}