diff --git a/src/libs/vdxf/libdxfrw/drw_base.h b/src/libs/vdxf/libdxfrw/drw_base.h index 2e8f38d52..4da31789c 100644 --- a/src/libs/vdxf/libdxfrw/drw_base.h +++ b/src/libs/vdxf/libdxfrw/drw_base.h @@ -158,6 +158,7 @@ BAD_READ_BLOCKS, /*!< error in block read process. */ BAD_READ_ENTITIES, /*!< error in entities read process. */ BAD_READ_OBJECTS, /*!< error in objects read process. */ BAD_READ_SECTION, /*!< error in sections read process. */ +BAD_CODE_PARSED, /*!< error in any parseCodes() method. */ }; enum class DebugLevel { diff --git a/src/libs/vdxf/libdxfrw/drw_entities.cpp b/src/libs/vdxf/libdxfrw/drw_entities.cpp index 9491adf18..6aebcb27b 100644 --- a/src/libs/vdxf/libdxfrw/drw_entities.cpp +++ b/src/libs/vdxf/libdxfrw/drw_entities.cpp @@ -1,6 +1,7 @@ /****************************************************************************** ** libDXFrw - Library to read/write DXF files (ascii & binary) ** ** ** +** Copyright (C) 2016-2022 A. Stebich (librecad@mail.lordofbikes.de) ** ** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** ** ** ** This library is free software, licensed under the terms of the GNU ** @@ -14,6 +15,7 @@ #include "drw_entities.h" #include "intern/dxfreader.h" #include "intern/drw_dbg.h" +#include "drw_reserve.h" #include "../vmisc/diagnostic.h" @@ -194,7 +196,7 @@ bool DRW_Entity::parseDxfGroups(int code, dxfReader *reader){ return true; } -void DRW_Point::parseCode(int code, dxfReader *reader){ +bool DRW_Point::parseCode(int code, dxfReader *reader){ switch (code) { case 10: basePoint.x = reader->getDouble(); @@ -219,24 +221,26 @@ void DRW_Point::parseCode(int code, dxfReader *reader){ extPoint.z = reader->getDouble(); break; default: - DRW_Entity::parseCode(code, reader); - break; + return DRW_Entity::parseCode(code, reader); } + + return true; } -void DRW_ASTMNotch::parseCode(int code, dxfReader *reader) +bool DRW_ASTMNotch::parseCode(int code, dxfReader *reader) { switch (code) { case 50: angle = reader->getDouble(); break; default: - DRW_Point::parseCode(code, reader); - break; + return DRW_Point::parseCode(code, reader); } + + return true; } -void DRW_Line::parseCode(int code, dxfReader *reader){ +bool DRW_Line::parseCode(int code, dxfReader *reader){ switch (code) { case 11: secPoint.x = reader->getDouble(); @@ -248,9 +252,10 @@ void DRW_Line::parseCode(int code, dxfReader *reader){ secPoint.z = reader->getDouble(); break; default: - DRW_Point::parseCode(code, reader); - break; + return DRW_Point::parseCode(code, reader); } + + return true; } void DRW_Circle::applyExtrusion(){ @@ -262,15 +267,16 @@ void DRW_Circle::applyExtrusion(){ } } -void DRW_Circle::parseCode(int code, dxfReader *reader){ +bool DRW_Circle::parseCode(int code, dxfReader *reader){ switch (code) { case 40: radious = reader->getDouble(); break; default: - DRW_Point::parseCode(code, reader); - break; + return DRW_Point::parseCode(code, reader); } + + return true; } void DRW_Arc::applyExtrusion(){ @@ -293,7 +299,7 @@ void DRW_Arc::applyExtrusion(){ } } -void DRW_Arc::parseCode(int code, dxfReader *reader){ +bool DRW_Arc::parseCode(int code, dxfReader *reader){ switch (code) { case 50: staangle = reader->getDouble()/ ARAD; @@ -302,12 +308,13 @@ void DRW_Arc::parseCode(int code, dxfReader *reader){ endangle = reader->getDouble()/ ARAD; break; default: - DRW_Circle::parseCode(code, reader); - break; + return DRW_Circle::parseCode(code, reader); } + + return true; } -void DRW_Ellipse::parseCode(int code, dxfReader *reader){ +bool DRW_Ellipse::parseCode(int code, dxfReader *reader){ switch (code) { case 40: ratio = reader->getDouble(); @@ -319,9 +326,10 @@ void DRW_Ellipse::parseCode(int code, dxfReader *reader){ endparam = reader->getDouble(); break; default: - DRW_Line::parseCode(code, reader); - break; + return DRW_Line::parseCode(code, reader); } + + return true; } void DRW_Ellipse::applyExtrusion(){ @@ -406,7 +414,7 @@ void DRW_Trace::applyExtrusion(){ } } -void DRW_Trace::parseCode(int code, dxfReader *reader){ +bool DRW_Trace::parseCode(int code, dxfReader *reader){ switch (code) { case 12: thirdPoint.x = reader->getDouble(); @@ -427,27 +435,25 @@ void DRW_Trace::parseCode(int code, dxfReader *reader){ fourPoint.z = reader->getDouble(); break; default: - DRW_Line::parseCode(code, reader); - break; + return DRW_Line::parseCode(code, reader); } + + return true; } -void DRW_Solid::parseCode(int code, dxfReader *reader){ - DRW_Trace::parseCode(code, reader); -} - -void DRW_3Dface::parseCode(int code, dxfReader *reader){ +bool DRW_3Dface::parseCode(int code, dxfReader *reader){ switch (code) { case 70: invisibleflag = reader->getInt32(); break; default: - DRW_Trace::parseCode(code, reader); - break; + return DRW_Trace::parseCode(code, reader); } + + return true; } -void DRW_Block::parseCode(int code, dxfReader *reader){ +bool DRW_Block::parseCode(int code, dxfReader *reader){ switch (code) { case 2: name = reader->getUtf8String(); @@ -456,12 +462,13 @@ void DRW_Block::parseCode(int code, dxfReader *reader){ flags = reader->getInt32(); break; default: - DRW_Point::parseCode(code, reader); - break; + return DRW_Point::parseCode(code, reader); } + + return true; } -void DRW_Insert::parseCode(int code, dxfReader *reader){ +bool DRW_Insert::parseCode(int code, dxfReader *reader){ switch (code) { case 2: name = reader->getUtf8String(); @@ -492,9 +499,10 @@ void DRW_Insert::parseCode(int code, dxfReader *reader){ rowspace = reader->getDouble(); break; default: - DRW_Point::parseCode(code, reader); - break; + return DRW_Point::parseCode(code, reader); } + + return true; } void DRW_LWPolyline::applyExtrusion(){ @@ -510,7 +518,7 @@ void DRW_LWPolyline::applyExtrusion(){ } } -void DRW_LWPolyline::parseCode(int code, dxfReader *reader){ +bool DRW_LWPolyline::parseCode(int code, dxfReader *reader){ switch (code) { case 10: { vertex = new DRW_Vertex2D(); @@ -547,8 +555,7 @@ void DRW_LWPolyline::parseCode(int code, dxfReader *reader){ break; case 90: vertexnum = reader->getInt32(); - vertlist.reserve(static_cast(vertexnum)); - break; + return DRW::reserve( vertlist, vertexnum); case 210: haveExtrusion = true; extPoint.x = reader->getDouble(); @@ -560,12 +567,13 @@ void DRW_LWPolyline::parseCode(int code, dxfReader *reader){ extPoint.z = reader->getDouble(); break; default: - DRW_Entity::parseCode(code, reader); - break; + return DRW_Entity::parseCode(code, reader); } + + return true; } -void DRW_Text::parseCode(int code, dxfReader *reader){ +bool DRW_Text::parseCode(int code, dxfReader *reader){ switch (code) { case 40: height = reader->getDouble(); @@ -595,12 +603,13 @@ void DRW_Text::parseCode(int code, dxfReader *reader){ style = reader->getUtf8String(); break; default: - DRW_Line::parseCode(code, reader); - break; + return DRW_Line::parseCode(code, reader); } + + return true; } -void DRW_MText::parseCode(int code, dxfReader *reader){ +bool DRW_MText::parseCode(int code, dxfReader *reader){ switch (code) { case 1: text += reader->getString(); @@ -608,8 +617,7 @@ void DRW_MText::parseCode(int code, dxfReader *reader){ break; case 11: hasXAxisVec = true; - DRW_Text::parseCode(code, reader); - break; + return DRW_Text::parseCode(code, reader); case 3: text += reader->getString(); break; @@ -675,9 +683,10 @@ void DRW_MText::parseCode(int code, dxfReader *reader){ // Actually: Mtext line spacing style break; default: - DRW_Text::parseCode(code, reader); - break; + return DRW_Text::parseCode(code, reader); } + + return true; } void DRW_MText::updateAngle(){ @@ -686,7 +695,7 @@ void DRW_MText::updateAngle(){ } } -void DRW_Polyline::parseCode(int code, dxfReader *reader){ +bool DRW_Polyline::parseCode(int code, dxfReader *reader){ switch (code) { case 70: flags = reader->getInt32(); @@ -713,12 +722,13 @@ void DRW_Polyline::parseCode(int code, dxfReader *reader){ curvetype = reader->getInt32(); break; default: - DRW_Point::parseCode(code, reader); - break; + return DRW_Point::parseCode(code, reader); } + + return true; } -void DRW_Vertex::parseCode(int code, dxfReader *reader){ +bool DRW_Vertex::parseCode(int code, dxfReader *reader){ switch (code) { case 70: flags = reader->getInt32(); @@ -751,12 +761,13 @@ void DRW_Vertex::parseCode(int code, dxfReader *reader){ identifier = reader->getInt32(); break; default: - DRW_Point::parseCode(code, reader); - break; + return DRW_Point::parseCode(code, reader); } + + return true; } -void DRW_Hatch::parseCode(int code, dxfReader *reader){ +bool DRW_Hatch::parseCode(int code, dxfReader *reader){ switch (code) { case 2: name = reader->getUtf8String(); @@ -838,8 +849,7 @@ void DRW_Hatch::parseCode(int code, dxfReader *reader){ break; case 91: loopsnum = reader->getInt32(); - looplist.reserve(static_cast(loopsnum)); - break; + return DRW::reserve( looplist, loopsnum); case 92: loop = new DRW_HatchLoop(reader->getInt32()); looplist.push_back(loop); @@ -858,12 +868,13 @@ void DRW_Hatch::parseCode(int code, dxfReader *reader){ clearEntities(); break; default: - DRW_Point::parseCode(code, reader); - break; + return DRW_Point::parseCode(code, reader); } + + return true; } -void DRW_Spline::parseCode(int code, dxfReader *reader){ +bool DRW_Spline::parseCode(int code, dxfReader *reader){ switch (code) { case 210: normalVec.x = reader->getDouble(); @@ -949,12 +960,13 @@ void DRW_Spline::parseCode(int code, dxfReader *reader){ weightlist.push_back(reader->getDouble()); break; default: - DRW_Entity::parseCode(code, reader); - break; + return DRW_Entity::parseCode(code, reader); } + + return true; } -void DRW_Image::parseCode(int code, dxfReader *reader){ +bool DRW_Image::parseCode(int code, dxfReader *reader){ switch (code) { case 12: vVector.x = reader->getDouble(); @@ -987,12 +999,13 @@ void DRW_Image::parseCode(int code, dxfReader *reader){ fade = reader->getInt32(); break; default: - DRW_Line::parseCode(code, reader); - break; + return DRW_Line::parseCode(code, reader); } + + return true; } -void DRW_Dimension::parseCode(int code, dxfReader *reader){ +bool DRW_Dimension::parseCode(int code, dxfReader *reader){ switch (code) { case 1: text = reader->getUtf8String(); @@ -1107,12 +1120,13 @@ void DRW_Dimension::parseCode(int code, dxfReader *reader){ extPoint.z = reader->getDouble(); break; default: - DRW_Entity::parseCode(code, reader); - break; + return DRW_Entity::parseCode(code, reader); } + + return true; } -void DRW_Leader::parseCode(int code, dxfReader *reader){ +bool DRW_Leader::parseCode(int code, dxfReader *reader){ switch (code) { case 3: style = reader->getUtf8String(); @@ -1197,12 +1211,13 @@ void DRW_Leader::parseCode(int code, dxfReader *reader){ offsettext.z = reader->getDouble(); break; default: - DRW_Entity::parseCode(code, reader); - break; + return DRW_Entity::parseCode(code, reader); } + + return true; } -void DRW_Viewport::parseCode(int code, dxfReader *reader){ +bool DRW_Viewport::parseCode(int code, dxfReader *reader){ switch (code) { case 40: pswidth = reader->getDouble(); @@ -1223,7 +1238,8 @@ void DRW_Viewport::parseCode(int code, dxfReader *reader){ centerPY = reader->getDouble(); break; default: - DRW_Point::parseCode(code, reader); - break; + return DRW_Point::parseCode(code, reader); } + + return true; } diff --git a/src/libs/vdxf/libdxfrw/drw_entities.h b/src/libs/vdxf/libdxfrw/drw_entities.h index 39d8f2106..5b8cba949 100644 --- a/src/libs/vdxf/libdxfrw/drw_entities.h +++ b/src/libs/vdxf/libdxfrw/drw_entities.h @@ -1,6 +1,7 @@ /****************************************************************************** ** libDXFrw - Library to read/write DXF files (ascii & binary) ** ** ** +** Copyright (C) 2016-2022 A. Stebich (librecad@mail.lordofbikes.de) ** ** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** ** ** ** This library is free software, licensed under the terms of the GNU ** @@ -183,7 +184,7 @@ public: protected: //parses dxf pair to read entity - bool parseCode(int code, dxfReader *reader); + virtual bool parseCode(int code, dxfReader *reader); //calculates extrusion axis (normal vector) void calculateAxis(DRW_Coord extPoint); //apply extrusion to @extPoint and return data in @point @@ -239,10 +240,10 @@ public: eType = DRW::POINT; } - virtual void applyExtrusion() override{} + void applyExtrusion() override {} protected: - void parseCode(int code, dxfReader *reader); + bool parseCode(int code, dxfReader *reader) override; public: DRW_Coord basePoint; /*!< base point, code 10, 20 & 30 */ @@ -262,7 +263,7 @@ public: } protected: - void parseCode(int code, dxfReader *reader); + bool parseCode(int code, dxfReader *reader); public: double angle{0}; /*!< angle, code 50 */ @@ -282,10 +283,10 @@ public: eType = DRW::LINE; } - virtual void applyExtrusion() override{} + void applyExtrusion() override{} protected: - void parseCode(int code, dxfReader *reader); + bool parseCode(int code, dxfReader *reader) override; public: DRW_Coord secPoint; /*!< second point, code 11, 21 & 31 */ @@ -330,10 +331,10 @@ public: eType = DRW::CIRCLE; } - virtual void applyExtrusion() override; + void applyExtrusion() override; protected: - void parseCode(int code, dxfReader *reader); + bool parseCode(int code, dxfReader *reader) override; public: double radious; /*!< radius, code 40 */ @@ -355,7 +356,7 @@ public: eType = DRW::ARC; } - virtual void applyExtrusion() override; + void applyExtrusion() override; //! center point in OCS const DRW_Coord & center() const { return basePoint; } @@ -372,7 +373,7 @@ public: protected: //! interpret code in dxf reading process or dispatch to inherited class - void parseCode(int code, dxfReader *reader); + bool parseCode(int code, dxfReader *reader) override; public: double staangle; /*!< start angle, code 50 in radians*/ @@ -400,11 +401,11 @@ public: } void toPolyline(DRW_Polyline *pol, int parts = 128); - virtual void applyExtrusion() override; + void applyExtrusion() override; protected: //! interpret code in dxf reading process or dispatch to inherited class - void parseCode(int code, dxfReader *reader); + bool parseCode(int code, dxfReader *reader) override; private: void correctAxis(); @@ -431,10 +432,10 @@ public: eType = DRW::TRACE; } - virtual void applyExtrusion() override; + void applyExtrusion() override; protected: - void parseCode(int code, dxfReader *reader); + bool parseCode(int code, dxfReader *reader) override; public: DRW_Coord thirdPoint; /*!< third point, code 12, 22 & 32 */ @@ -453,10 +454,6 @@ public: eType = DRW::SOLID; } -protected: - //! interpret code in dxf reading process or dispatch to inherited class - void parseCode(int code, dxfReader *reader); - public: //! first corner (2D) const DRW_Coord & firstCorner() const { return basePoint; } @@ -498,7 +495,7 @@ public: eType = DRW::E3DFACE; } - virtual void applyExtrusion() override {} + void applyExtrusion() override {} //! first corner in WCS const DRW_Coord & firstCorner() const { return basePoint; } @@ -513,7 +510,7 @@ public: protected: //! interpret code in dxf reading process or dispatch to inherited class - void parseCode(int code, dxfReader *reader); + bool parseCode(int code, dxfReader *reader) override; public: int invisibleflag; /*!< invisible edge flag, code 70 */ @@ -536,10 +533,10 @@ public: layer = '0'; } - virtual void applyExtrusion() override {} + void applyExtrusion() override {} protected: - void parseCode(int code, dxfReader *reader); + bool parseCode(int code, dxfReader *reader) override; public: UTF8STRING name; /*!< block name, code 2 */ @@ -570,7 +567,7 @@ public: } protected: - void parseCode(int code, dxfReader *reader); + bool parseCode(int code, dxfReader *reader) override; public: UTF8STRING name; /*!< block name, code 2 */ @@ -624,7 +621,7 @@ public: ~DRW_LWPolyline() { for(DRW_Vertex2D *item : vertlist) delete item; } - virtual void applyExtrusion() override; + void applyExtrusion() override; void addVertex (DRW_Vertex2D v) { DRW_Vertex2D *vert = new DRW_Vertex2D(); vert->x = v.x; @@ -644,7 +641,7 @@ public: } protected: - void parseCode(int code, dxfReader *reader); + bool parseCode(int code, dxfReader *reader) override; public: int vertexnum; /*!< number of vertex, code 90 */ @@ -699,10 +696,10 @@ public: eType = DRW::TEXT; } - virtual void applyExtrusion() override {} //RLZ TODO + void applyExtrusion() override {} //RLZ TODO protected: - void parseCode(int code, dxfReader *reader); + bool parseCode(int code, dxfReader *reader) override; public: double height; /*!< height text, code 40 */ @@ -747,7 +744,7 @@ public: } protected: - void parseCode(int code, dxfReader *reader); + bool parseCode(int code, dxfReader *reader) override; void updateAngle(); //recalculate angle if 'haveXAxis' is true public: @@ -797,7 +794,7 @@ public: } protected: - void parseCode(int code, dxfReader *reader); + bool parseCode(int code, dxfReader *reader) override; public: double stawidth; /*!< Start width, code 40 */ @@ -876,7 +873,7 @@ public: } protected: - void parseCode(int code, dxfReader *reader); + bool parseCode(int code, dxfReader *reader) override; public: int flags; /*!< polyline flag, code 70, default 0 */ @@ -960,10 +957,10 @@ public: for(DRW_Coord *item : controllist) delete item; for(DRW_Coord *item : fitlist) delete item; } - virtual void applyExtrusion() override {} + void applyExtrusion() override {} protected: - void parseCode(int code, dxfReader *reader); + bool parseCode(int code, dxfReader *reader) override; public: // double ex; /*!< normal vector x coordinate, code 210 */ @@ -1074,10 +1071,10 @@ public: looplist.push_back(v); } - virtual void applyExtrusion() override {} + void applyExtrusion() override {} protected: - void parseCode(int code, dxfReader *reader); + bool parseCode(int code, dxfReader *reader) override; public: UTF8STRING name; /*!< hatch pattern name, code 2 */ @@ -1171,7 +1168,7 @@ public: } protected: - void parseCode(int code, dxfReader *reader); + bool parseCode(int code, dxfReader *reader) override; public: duint32 ref; /*!< Hard reference to imagedef object, code 340 */ @@ -1255,10 +1252,10 @@ public: } virtual ~DRW_Dimension() = default; - virtual void applyExtrusion() override {} + void applyExtrusion() override {} protected: - void parseCode(int code, dxfReader *reader); + bool parseCode(int code, dxfReader *reader) override; public: DRW_Coord getDefPoint() const {return defPoint;} /*!< Definition point, code 10, 20 & 30 */ @@ -1561,10 +1558,10 @@ public: for(DRW_Coord *item : vertexlist) delete item; } - virtual void applyExtrusion() override {} + void applyExtrusion() override {} protected: - void parseCode(int code, dxfReader *reader); + bool parseCode(int code, dxfReader *reader) override; public: UTF8STRING style; /*!< Dimension style name, code 3 */ @@ -1623,10 +1620,10 @@ public: eType = DRW::VIEWPORT; } - virtual void applyExtrusion() override {} + void applyExtrusion() override {} protected: - void parseCode(int code, dxfReader *reader); + bool parseCode(int code, dxfReader *reader) override; public: double pswidth; /*!< Width in paper space units, code 40 */ diff --git a/src/libs/vdxf/libdxfrw/drw_header.cpp b/src/libs/vdxf/libdxfrw/drw_header.cpp index 92df3ef3a..e2bc28deb 100644 --- a/src/libs/vdxf/libdxfrw/drw_header.cpp +++ b/src/libs/vdxf/libdxfrw/drw_header.cpp @@ -39,12 +39,12 @@ void DRW_Header::addComment(const std::string &c){ comments += c; } -void DRW_Header::parseCode(int code, dxfReader *reader){ +bool DRW_Header::parseCode(int code, dxfReader *reader){ if (nullptr == curr && 9 != code) { DRW_DBG("invalid header code: "); DRW_DBG(code); DRW_DBG("\n"); - return; + return false; } switch (code) { @@ -108,6 +108,8 @@ void DRW_Header::parseCode(int code, dxfReader *reader){ default: break; } + + return true; } void DRW_Header::write(dxfWriter *writer, DRW::Version ver){ diff --git a/src/libs/vdxf/libdxfrw/drw_header.h b/src/libs/vdxf/libdxfrw/drw_header.h index 0748c7e2b..08440f465 100644 --- a/src/libs/vdxf/libdxfrw/drw_header.h +++ b/src/libs/vdxf/libdxfrw/drw_header.h @@ -1,6 +1,7 @@ /****************************************************************************** ** libDXFrw - Library to read/write DXF files (ascii & binary) ** ** ** +** Copyright (C) 2016-2022 A. Stebich (librecad@mail.lordofbikes.de) ** ** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** ** ** ** This library is free software, licensed under the terms of the GNU ** @@ -84,7 +85,7 @@ public: void addComment(const std::string &c); protected: - void parseCode(int code, dxfReader *reader); + bool parseCode(int code, dxfReader *reader); private: bool getDouble(std::string key, double *varDouble); bool getInt(std::string key, int *varInt); diff --git a/src/libs/vdxf/libdxfrw/drw_objects.cpp b/src/libs/vdxf/libdxfrw/drw_objects.cpp index 9389b9224..7bcd706f1 100644 --- a/src/libs/vdxf/libdxfrw/drw_objects.cpp +++ b/src/libs/vdxf/libdxfrw/drw_objects.cpp @@ -1,6 +1,7 @@ /****************************************************************************** ** libDXFrw - Library to read/write DXF files (ascii & binary) ** ** ** +** Copyright (C) 2016-2022 A. Stebich (librecad@mail.lordofbikes.de) ** ** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** ** ** ** This library is free software, licensed under the terms of the GNU ** @@ -16,13 +17,14 @@ #include "intern/dxfreader.h" #include "intern/dxfwriter.h" #include "intern/drw_dbg.h" +#include "drw_reserve.h" //! Base class for tables entries /*! * Base class for tables entries * @author Rallaz */ -void DRW_TableEntry::parseCode(int code, dxfReader *reader){ +bool DRW_TableEntry::parseCode(int code, dxfReader *reader){ switch (code) { case 5: handle = static_cast(reader->getHandleString()); @@ -101,6 +103,8 @@ void DRW_TableEntry::parseCode(int code, dxfReader *reader){ default: break; } + + return true; } //! Class to handle dimstyle entries @@ -108,7 +112,7 @@ void DRW_TableEntry::parseCode(int code, dxfReader *reader){ * Class to handle ldim style symbol table entries * @author Rallaz */ -void DRW_Dimstyle::parseCode(int code, dxfReader *reader){ +bool DRW_Dimstyle::parseCode(int code, dxfReader *reader){ switch (code) { case 105: handle = static_cast(reader->getHandleString()); @@ -321,9 +325,10 @@ void DRW_Dimstyle::parseCode(int code, dxfReader *reader){ dimblk2 = reader->getUtf8String(); break; default: - DRW_TableEntry::parseCode(code, reader); - break; + return DRW_TableEntry::parseCode(code, reader); } + + return true; } //! Class to handle line type entries @@ -331,7 +336,7 @@ void DRW_Dimstyle::parseCode(int code, dxfReader *reader){ * Class to handle line type symbol table entries * @author Rallaz */ -void DRW_LType::parseCode(int code, dxfReader *reader){ +bool DRW_LType::parseCode(int code, dxfReader *reader){ switch (code) { case 3: desc = reader->getUtf8String(); @@ -339,7 +344,9 @@ void DRW_LType::parseCode(int code, dxfReader *reader){ case 73: size = reader->getInt32(); path.clear(); - path.reserve(static_cast(size)); + if (!DRW::reserve( path, size)) { + return false; + } break; case 40: length = reader->getDouble(); @@ -352,9 +359,10 @@ void DRW_LType::parseCode(int code, dxfReader *reader){ haveShape = reader->getInt32(); break;*/ default: - DRW_TableEntry::parseCode(code, reader); - break; + return DRW_TableEntry::parseCode(code, reader); } + + return true; } //! Update line type @@ -377,7 +385,7 @@ void DRW_LType::update(){ * Class to handle layer symbol table entries * @author Rallaz */ -void DRW_Layer::parseCode(int code, dxfReader *reader){ +bool DRW_Layer::parseCode(int code, dxfReader *reader){ switch (code) { case 6: lineType = reader->getUtf8String(); @@ -401,9 +409,10 @@ void DRW_Layer::parseCode(int code, dxfReader *reader){ color24 = reader->getInt32(); break; default: - DRW_TableEntry::parseCode(code, reader); - break; + return DRW_TableEntry::parseCode(code, reader); } + + return true; } //! Class to handle text style entries @@ -411,7 +420,7 @@ void DRW_Layer::parseCode(int code, dxfReader *reader){ * Class to handle text style symbol table entries * @author Rallaz */ -void DRW_Textstyle::parseCode(int code, dxfReader *reader){ +bool DRW_Textstyle::parseCode(int code, dxfReader *reader){ switch (code) { case 3: font = reader->getUtf8String(); @@ -438,9 +447,10 @@ void DRW_Textstyle::parseCode(int code, dxfReader *reader){ fontFamily = reader->getInt32(); break; default: - DRW_TableEntry::parseCode(code, reader); - break; + return DRW_TableEntry::parseCode(code, reader); } + + return true; } //! Class to handle vport entries @@ -448,7 +458,7 @@ void DRW_Textstyle::parseCode(int code, dxfReader *reader){ * Class to handle vport symbol table entries * @author Rallaz */ -void DRW_Vport::parseCode(int code, dxfReader *reader){ +bool DRW_Vport::parseCode(int code, dxfReader *reader){ switch (code) { case 10: lowerLeft.x = reader->getDouble(); @@ -550,12 +560,13 @@ void DRW_Vport::parseCode(int code, dxfReader *reader){ snapIsopair = reader->getInt32(); break; default: - DRW_TableEntry::parseCode(code, reader); - break; + return DRW_TableEntry::parseCode(code, reader); } + + return true; } -void DRW_ImageDef::parseCode(int code, dxfReader *reader){ +bool DRW_ImageDef::parseCode(int code, dxfReader *reader){ switch (code) { case 1: fileName = reader->getUtf8String(); @@ -585,11 +596,13 @@ void DRW_ImageDef::parseCode(int code, dxfReader *reader){ resolution = reader->getInt32(); break; default: - break; + return DRW_TableEntry::parseCode(code, reader); } + + return true; } -void DRW_PlotSettings::parseCode(int code, dxfReader *reader){ +bool DRW_PlotSettings::parseCode(int code, dxfReader *reader){ switch (code) { case 5: handle = static_cast(reader->getHandleString()); @@ -610,6 +623,8 @@ void DRW_PlotSettings::parseCode(int code, dxfReader *reader){ marginTop = reader->getDouble(); break; default: - break; + return DRW_TableEntry::parseCode(code, reader); } + + return true; } diff --git a/src/libs/vdxf/libdxfrw/drw_objects.h b/src/libs/vdxf/libdxfrw/drw_objects.h index a769ed24d..492d9f596 100644 --- a/src/libs/vdxf/libdxfrw/drw_objects.h +++ b/src/libs/vdxf/libdxfrw/drw_objects.h @@ -1,6 +1,7 @@ /****************************************************************************** ** libDXFrw - Library to read/write DXF files (ascii & binary) ** ** ** +** Copyright (C) 2016-2022 A. Stebich (librecad@mail.lordofbikes.de) ** ** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** ** ** ** This library is free software, licensed under the terms of the GNU ** @@ -90,7 +91,7 @@ public: } protected: - void parseCode(int code, dxfReader *reader); + virtual bool parseCode(int code, dxfReader *reader); void reset() { flags = 0; @@ -227,7 +228,7 @@ public: } protected: - void parseCode(int code, dxfReader *reader); + bool parseCode(int code, dxfReader *reader) override; public: //V12 @@ -330,7 +331,7 @@ public: } protected: - void parseCode(int code, dxfReader *reader); + bool parseCode(int code, dxfReader *reader) override; void update(); public: @@ -374,7 +375,7 @@ public: } protected: - void parseCode(int code, dxfReader *reader); + bool parseCode(int code, dxfReader *reader) override; public: UTF8STRING lineType; /*!< line type, code 6 */ @@ -442,7 +443,7 @@ public: } protected: - void parseCode(int code, dxfReader *reader); + bool parseCode(int code, dxfReader *reader) override; public: double height; /*!< Fixed text height (0 not set), code 40 */ @@ -511,7 +512,7 @@ public: } protected: - void parseCode(int code, dxfReader *reader); + bool parseCode(int code, dxfReader *reader) override; public: DRW_Coord lowerLeft; /*!< Lower left corner, code 10 & 20 */ @@ -576,7 +577,7 @@ public: } protected: - void parseCode(int code, dxfReader *reader); + bool parseCode(int code, dxfReader *reader) override; public: // std::string handle; /*!< entity identifier, code 5 */ @@ -614,7 +615,7 @@ public: } protected: - void parseCode(int code, dxfReader *reader); + bool parseCode(int code, dxfReader *reader) override; public: UTF8STRING plotViewName {}; /*!< Plot view name, code 6 */ @@ -641,7 +642,7 @@ public: } protected: - void parseCode(int code, dxfReader *reader){DRW_TableEntry::parseCode(code, reader);} + bool parseCode(int code, dxfReader *reader){return DRW_TableEntry::parseCode(code, reader);} }; namespace DRW { diff --git a/src/libs/vdxf/libdxfrw/drw_reserve.h b/src/libs/vdxf/libdxfrw/drw_reserve.h new file mode 100644 index 000000000..e87d7ff8b --- /dev/null +++ b/src/libs/vdxf/libdxfrw/drw_reserve.h @@ -0,0 +1,52 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2016-2022 A. Stebich (librecad@mail.lordofbikes.de) ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#ifndef DRW_RESERVE_H +#define DRW_RESERVE_H + +#include +#include "intern/drw_dbg.h" + +namespace DRW +{ + /** + * Template to protect vector<>.reserve() calls. + * Malformed or suspicious input files can cause std::exceptions, + * which are caught here to avoid crashes or other vulnerabilities. + */ + template + auto reserve(std::vector &list, const int size) -> bool + { + try { + list.reserve( size); + } + catch (const std::exception& e) { + DRW_DBG( "std::exception : "); + DRW_DBG( e.what()); + DRW_DBG( " - "); + DRW_DBG( size); + DRW_DBG( "\n"); + return false; + } + catch (...) { + DRW_DBG( "vector<>.reserve() exception : "); + DRW_DBG( size); + DRW_DBG( "\n"); + return false; + } + + return true; + } +} // namespace DRW + +#endif // DRW_RESERVE_H diff --git a/src/libs/vdxf/libdxfrw/libdxfrw.cpp b/src/libs/vdxf/libdxfrw/libdxfrw.cpp index c81c19db4..d4b41c0b5 100644 --- a/src/libs/vdxf/libdxfrw/libdxfrw.cpp +++ b/src/libs/vdxf/libdxfrw/libdxfrw.cpp @@ -2025,7 +2025,9 @@ bool dxfRW::processHeader() { return setError(DRW::BAD_READ_HEADER); } - header.parseCode(code, reader); + if (!header.parseCode(code, reader)) { + return setError(DRW::BAD_CODE_PARSED); + } } return setError(DRW::BAD_READ_HEADER); @@ -2103,8 +2105,11 @@ bool dxfRW::processLType() { } else if (sectionstr == "ENDTAB") { return true; //found ENDTAB terminate } - } else if (reading) - ltype.parseCode(code, reader); + } else if (reading) { + if (!ltype.parseCode(code, reader)) { + return setError( DRW::BAD_CODE_PARSED); + } + } } return setError(DRW::BAD_READ_TABLES); @@ -2129,8 +2134,11 @@ bool dxfRW::processLayer() { } else if (sectionstr == "ENDTAB") { return true; //found ENDTAB terminate } - } else if (reading) - layer.parseCode(code, reader); + } else if (reading) { + if (!layer.parseCode(code, reader)) { + return setError( DRW::BAD_CODE_PARSED); + } + } } return setError(DRW::BAD_READ_TABLES); @@ -2155,8 +2163,11 @@ bool dxfRW::processDimStyle() { } else if (sectionstr == "ENDTAB") { return true; //found ENDTAB terminate } - } else if (reading) - dimSty.parseCode(code, reader); + } else if (reading) { + if (!dimSty.parseCode(code, reader)) { + return setError(DRW::BAD_CODE_PARSED); + } + } } return setError(DRW::BAD_READ_TABLES); @@ -2181,8 +2192,11 @@ bool dxfRW::processTextStyle(){ } else if (sectionstr == "ENDTAB") { return true; //found ENDTAB terminate } - } else if (reading) - TxtSty.parseCode(code, reader); + } else if (reading) { + if (!TxtSty.parseCode(code, reader)) { + return setError( DRW::BAD_CODE_PARSED); + } + } } return setError(DRW::BAD_READ_TABLES); @@ -2207,8 +2221,11 @@ bool dxfRW::processVports(){ } else if (sectionstr == "ENDTAB") { return true; //found ENDTAB terminate } - } else if (reading) - vp.parseCode(code, reader); + } else if (reading) { + if (!vp.parseCode(code, reader)) { + return setError( DRW::BAD_CODE_PARSED); + } + } } return setError(DRW::BAD_READ_TABLES); @@ -2233,8 +2250,11 @@ bool dxfRW::processAppId(){ } else if (sectionstr == "ENDTAB") { return true; //found ENDTAB terminate } - } else if (reading) - vp.parseCode(code, reader); + } else if (reading) { + if (!vp.parseCode(code, reader)) { + return setError(DRW::BAD_CODE_PARSED); + } + } } return setError(DRW::BAD_READ_TABLES); @@ -2268,8 +2288,7 @@ bool dxfRW::processBlock() { DRW_Block block; while (reader->readRec(&code)) { DRW_DBG(code); DRW_DBG("\n"); - switch (code) { - case 0: { + if (0 == code) { nextentity = reader->getString(); DRW_DBG(nextentity); DRW_DBG("\n"); iface->addBlock(block); @@ -2282,9 +2301,9 @@ bool dxfRW::processBlock() { return true; //found ENDBLK, terminate } } - default: - block.parseCode(code, reader); - break; + + if (!block.parseCode(code, reader)) { + return setError( DRW::BAD_CODE_PARSED); } } @@ -2375,8 +2394,7 @@ bool dxfRW::processEllipse() { DRW_Ellipse ellipse; while (reader->readRec(&code)) { DRW_DBG(code); DRW_DBG("\n"); - switch (code) { - case 0: { + if (0 == code) { nextentity = reader->getString(); DRW_DBG(nextentity); DRW_DBG("\n"); if (applyExt) @@ -2384,9 +2402,9 @@ bool dxfRW::processEllipse() { iface->addEllipse(ellipse); return true; //found new entity or ENDSEC, terminate } - default: - ellipse.parseCode(code, reader); - break; + + if (!ellipse.parseCode(code, reader)) { + return setError( DRW::BAD_CODE_PARSED); } } @@ -2399,8 +2417,7 @@ bool dxfRW::processTrace() { DRW_Trace trace; while (reader->readRec(&code)) { DRW_DBG(code); DRW_DBG("\n"); - switch (code) { - case 0: { + if (0 == code) { nextentity = reader->getString(); DRW_DBG(nextentity); DRW_DBG("\n"); if (applyExt) @@ -2408,9 +2425,9 @@ bool dxfRW::processTrace() { iface->addTrace(trace); return true; //found new entity or ENDSEC, terminate } - default: - trace.parseCode(code, reader); - break; + + if (!trace.parseCode(code, reader)) { + return setError( DRW::BAD_CODE_PARSED); } } @@ -2423,8 +2440,7 @@ bool dxfRW::processSolid() { DRW_Solid solid; while (reader->readRec(&code)) { DRW_DBG(code); DRW_DBG("\n"); - switch (code) { - case 0: { + if (0 == code) { nextentity = reader->getString(); DRW_DBG(nextentity); DRW_DBG("\n"); if (applyExt) @@ -2432,9 +2448,9 @@ bool dxfRW::processSolid() { iface->addSolid(solid); return true; //found new entity or ENDSEC, terminate } - default: - solid.parseCode(code, reader); - break; + + if (!solid.parseCode(code, reader)) { + return setError( DRW::BAD_CODE_PARSED); } } @@ -2447,16 +2463,15 @@ bool dxfRW::process3dface() { DRW_3Dface face; while (reader->readRec(&code)) { DRW_DBG(code); DRW_DBG("\n"); - switch (code) { - case 0: { + if (0 == code) { nextentity = reader->getString(); DRW_DBG(nextentity); DRW_DBG("\n"); iface->add3dFace(face); return true; //found new entity or ENDSEC, terminate } - default: - face.parseCode(code, reader); - break; + + if (!face.parseCode(code, reader)) { + return setError( DRW::BAD_CODE_PARSED); } } @@ -2469,17 +2484,17 @@ bool dxfRW::processViewport() { DRW_Viewport vp; while (reader->readRec(&code)) { DRW_DBG(code); DRW_DBG("\n"); - switch (code) { - case 0: { + if (0 == code) { nextentity = reader->getString(); DRW_DBG(nextentity); DRW_DBG("\n"); iface->addViewport(vp); return true; //found new entity or ENDSEC, terminate } - default: - vp.parseCode(code, reader); - break; + + if (!vp.parseCode(code, reader)) { + return setError( DRW::BAD_CODE_PARSED); } + break; } return setError(DRW::BAD_READ_ENTITIES); @@ -2491,16 +2506,15 @@ bool dxfRW::processPoint() { DRW_Point point; while (reader->readRec(&code)) { DRW_DBG(code); DRW_DBG("\n"); - switch (code) { - case 0: { + if (0 == code) { nextentity = reader->getString(); DRW_DBG(nextentity); DRW_DBG("\n"); iface->addPoint(point); return true; //found new entity or ENDSEC, terminate } - default: - point.parseCode(code, reader); - break; + + if (!point.parseCode(code, reader)) { + return setError( DRW::BAD_CODE_PARSED); } } @@ -2513,16 +2527,15 @@ bool dxfRW::processLine() { DRW_Line line; while (reader->readRec(&code)) { DRW_DBG(code); DRW_DBG("\n"); - switch (code) { - case 0: { + if (0 == code) { nextentity = reader->getString(); DRW_DBG(nextentity); DRW_DBG("\n"); iface->addLine(line); return true; //found new entity or ENDSEC, terminate } - default: - line.parseCode(code, reader); - break; + + if (!line.parseCode(code, reader)) { + return setError( DRW::BAD_CODE_PARSED); } } @@ -2535,16 +2548,15 @@ bool dxfRW::processRay() { DRW_Ray line; while (reader->readRec(&code)) { DRW_DBG(code); DRW_DBG("\n"); - switch (code) { - case 0: { + if (0 == code) { nextentity = reader->getString(); DRW_DBG(nextentity); DRW_DBG("\n"); iface->addRay(line); return true; //found new entity or ENDSEC, terminate } - default: - line.parseCode(code, reader); - break; + + if (!line.parseCode(code, reader)) { + return setError( DRW::BAD_CODE_PARSED); } } @@ -2557,16 +2569,15 @@ bool dxfRW::processXline() { DRW_Xline line; while (reader->readRec(&code)) { DRW_DBG(code); DRW_DBG("\n"); - switch (code) { - case 0: { + if (0 == code) { nextentity = reader->getString(); DRW_DBG(nextentity); DRW_DBG("\n"); iface->addXline(line); return true; //found new entity or ENDSEC, terminate } - default: - line.parseCode(code, reader); - break; + + if (!line.parseCode(code, reader)) { + return setError( DRW::BAD_CODE_PARSED); } } @@ -2579,8 +2590,7 @@ bool dxfRW::processCircle() { DRW_Circle circle; while (reader->readRec(&code)) { DRW_DBG(code); DRW_DBG("\n"); - switch (code) { - case 0: { + if (0 == code) { nextentity = reader->getString(); DRW_DBG(nextentity); DRW_DBG("\n"); if (applyExt) @@ -2588,9 +2598,9 @@ bool dxfRW::processCircle() { iface->addCircle(circle); return true; //found new entity or ENDSEC, terminate } - default: - circle.parseCode(code, reader); - break; + + if (!circle.parseCode(code, reader)) { + return setError( DRW::BAD_CODE_PARSED); } } @@ -2603,8 +2613,7 @@ bool dxfRW::processArc() { DRW_Arc arc; while (reader->readRec(&code)) { DRW_DBG(code); DRW_DBG("\n"); - switch (code) { - case 0: { + if (0 == code) { nextentity = reader->getString(); DRW_DBG(nextentity); DRW_DBG("\n"); if (applyExt) @@ -2612,9 +2621,9 @@ bool dxfRW::processArc() { iface->addArc(arc); return true; //found new entity or ENDSEC, terminate } - default: - arc.parseCode(code, reader); - break; + + if (!arc.parseCode(code, reader)) { + return setError( DRW::BAD_CODE_PARSED); } } @@ -2627,16 +2636,15 @@ bool dxfRW::processInsert() { DRW_Insert insert; while (reader->readRec(&code)) { DRW_DBG(code); DRW_DBG("\n"); - switch (code) { - case 0: { + if (0 == code) { nextentity = reader->getString(); DRW_DBG(nextentity); DRW_DBG("\n"); iface->addInsert(insert); return true; //found new entity or ENDSEC, terminate } - default: - insert.parseCode(code, reader); - break; + + if (!insert.parseCode(code, reader)) { + return setError( DRW::BAD_CODE_PARSED); } } @@ -2649,8 +2657,7 @@ bool dxfRW::processLWPolyline() { DRW_LWPolyline pl; while (reader->readRec(&code)) { DRW_DBG(code); DRW_DBG("\n"); - switch (code) { - case 0: { + if (0 == code) { nextentity = reader->getString(); DRW_DBG(nextentity); DRW_DBG("\n"); if (applyExt) @@ -2658,9 +2665,9 @@ bool dxfRW::processLWPolyline() { iface->addLWPolyline(pl); return true; //found new entity or ENDSEC, terminate } - default: - pl.parseCode(code, reader); - break; + + if (!pl.parseCode(code, reader)) { + return setError( DRW::BAD_CODE_PARSED); } } @@ -2673,8 +2680,7 @@ bool dxfRW::processPolyline() { DRW_Polyline pl; while (reader->readRec(&code)) { DRW_DBG(code); DRW_DBG("\n"); - switch (code) { - case 0: { + if (0 == code) { nextentity = reader->getString(); DRW_DBG(nextentity); DRW_DBG("\n"); if (nextentity != "VERTEX") { @@ -2684,10 +2690,9 @@ bool dxfRW::processPolyline() { processVertex(&pl); } } - Q_FALLTHROUGH(); - default: - pl.parseCode(code, reader); - break; + + if (!pl.parseCode(code, reader)) { //parseCode just initialize the members of pl + return setError(DRW::BAD_CODE_PARSED); } } @@ -2700,8 +2705,7 @@ bool dxfRW::processVertex(DRW_Polyline *pl) { QScopedPointer v(new DRW_Vertex()); while (reader->readRec(&code)) { DRW_DBG(code); DRW_DBG("\n"); - switch (code) { - case 0: { + if (0 == code) { pl->appendVertex(v.take()); nextentity = reader->getString(); DRW_DBG(nextentity); DRW_DBG("\n"); @@ -2711,10 +2715,9 @@ bool dxfRW::processVertex(DRW_Polyline *pl) { v.reset(new DRW_Vertex()); //another vertex } } - Q_FALLTHROUGH(); - default: - v->parseCode(code, reader); - break; + + if (!v->parseCode(code, reader)) { //the members of v are reinitialized here + return setError( DRW::BAD_CODE_PARSED); } } @@ -2727,16 +2730,15 @@ bool dxfRW::processText() { DRW_Text txt; while (reader->readRec(&code)) { DRW_DBG(code); DRW_DBG("\n"); - switch (code) { - case 0: { + if (0 == code) { nextentity = reader->getString(); DRW_DBG(nextentity); DRW_DBG("\n"); iface->addText(txt); return true; //found new entity or ENDSEC, terminate } - default: - txt.parseCode(code, reader); - break; + + if (!txt.parseCode(code, reader)) { + return setError( DRW::BAD_CODE_PARSED); } } @@ -2749,17 +2751,16 @@ bool dxfRW::processMText() { DRW_MText txt; while (reader->readRec(&code)) { DRW_DBG(code); DRW_DBG("\n"); - switch (code) { - case 0: { + if (0 == code) { nextentity = reader->getString(); DRW_DBG(nextentity); DRW_DBG("\n"); txt.updateAngle(); iface->addMText(txt); return true; //found new entity or ENDSEC, terminate } - default: - txt.parseCode(code, reader); - break; + + if (!txt.parseCode(code, reader)) { + return setError( DRW::BAD_CODE_PARSED); } } @@ -2772,16 +2773,15 @@ bool dxfRW::processHatch() { DRW_Hatch hatch; while (reader->readRec(&code)) { DRW_DBG(code); DRW_DBG("\n"); - switch (code) { - case 0: { + if (0 == code) { nextentity = reader->getString(); DRW_DBG(nextentity); DRW_DBG("\n"); iface->addHatch(&hatch); return true; //found new entity or ENDSEC, terminate } - default: - hatch.parseCode(code, reader); - break; + + if (!hatch.parseCode(code, reader)) { + return setError( DRW::BAD_CODE_PARSED); } } @@ -2795,16 +2795,15 @@ bool dxfRW::processSpline() { DRW_Spline sp; while (reader->readRec(&code)) { DRW_DBG(code); DRW_DBG("\n"); - switch (code) { - case 0: { + if (0 == code) { nextentity = reader->getString(); DRW_DBG(nextentity); DRW_DBG("\n"); iface->addSpline(&sp); return true; //found new entity or ENDSEC, terminate } - default: - sp.parseCode(code, reader); - break; + + if (!sp.parseCode(code, reader)) { + return setError( DRW::BAD_CODE_PARSED); } } @@ -2818,16 +2817,15 @@ bool dxfRW::processImage() { DRW_Image img; while (reader->readRec(&code)) { DRW_DBG(code); DRW_DBG("\n"); - switch (code) { - case 0: { + if (0 == code) { nextentity = reader->getString(); DRW_DBG(nextentity); DRW_DBG("\n"); iface->addImage(&img); return true; //found new entity or ENDSEC, terminate } - default: - img.parseCode(code, reader); - break; + + if (!img.parseCode(code, reader)) { + return setError( DRW::BAD_CODE_PARSED); } } @@ -2841,8 +2839,7 @@ bool dxfRW::processDimension() { DRW_Dimension dim; while (reader->readRec(&code)) { DRW_DBG(code); DRW_DBG("\n"); - switch (code) { - case 0: { + if (0 == code) { nextentity = reader->getString(); DRW_DBG(nextentity); DRW_DBG("\n"); int type = dim.type & 0x0F; @@ -2885,9 +2882,9 @@ bool dxfRW::processDimension() { return true; //found new entity or ENDSEC, terminate } - default: - dim.parseCode(code, reader); - break; + + if (!dim.parseCode(code, reader)) { + return setError( DRW::BAD_CODE_PARSED); } } @@ -2900,16 +2897,15 @@ bool dxfRW::processLeader() { DRW_Leader leader; while (reader->readRec(&code)) { DRW_DBG(code); DRW_DBG("\n"); - switch (code) { - case 0: { + if (0 == code) { nextentity = reader->getString(); DRW_DBG(nextentity); DRW_DBG("\n"); iface->addLeader(&leader); return true; //found new entity or ENDSEC, terminate } - default: - leader.parseCode(code, reader); - break; + + if (!leader.parseCode(code, reader)) { + return setError( DRW::BAD_CODE_PARSED); } } @@ -2961,16 +2957,15 @@ bool dxfRW::processImageDef() { DRW_ImageDef img; while (reader->readRec(&code)) { DRW_DBG(code); DRW_DBG("\n"); - switch (code) { - case 0: { + if (0 == code) { nextentity = reader->getString(); DRW_DBG(nextentity); DRW_DBG("\n"); iface->linkImage(&img); return true; //found new entity or ENDSEC, terminate } - default: - img.parseCode(code, reader); - break; + + if (!img.parseCode(code, reader)) { + return setError( DRW::BAD_CODE_PARSED); } } @@ -2983,16 +2978,15 @@ bool dxfRW::processPlotSettings() { DRW_PlotSettings ps; while (reader->readRec(&code)) { DRW_DBG(code); DRW_DBG("\n"); - switch (code) { - case 0: { + if (0 == code) { nextentity = reader->getString(); DRW_DBG(nextentity); DRW_DBG("\n"); iface->addPlotSettings(&ps); return true; //found new entity or ENDSEC, terminate } - default: - ps.parseCode(code, reader); - break; + + if (!ps.parseCode(code, reader)) { + return setError( DRW::BAD_CODE_PARSED); } } diff --git a/src/libs/vdxf/vdxf.pri b/src/libs/vdxf/vdxf.pri index f38e1199b..be7674d33 100644 --- a/src/libs/vdxf/vdxf.pri +++ b/src/libs/vdxf/vdxf.pri @@ -20,6 +20,7 @@ SOURCES += \ *msvc*:SOURCES += $$PWD/stable.cpp HEADERS += \ + $$PWD/libdxfrw/drw_reserve.h \ $$PWD/stable.h \ $$PWD/vdxfengine.h \ $$PWD/vdxfpaintdevice.h \