diff options
author | David Tardon <dtardon@redhat.com> | 2018-01-09 16:48:38 +0100 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2018-01-09 16:48:38 +0100 |
commit | ab9002c37b6be82e572c354281de9c7d5e636a61 (patch) | |
tree | 22ac70cf539a61a2038254a597c712526ae38aac | |
parent | 9c252a30064a7968b8e548db46cfa8018d4876c1 (diff) |
avoid undef. behavior casting arbitrary int to enum
Just pass the values around as unsigned ints and use the enums as
constant sets. The previous code doesn't add any extra type safety
anyway.
Change-Id: I914e136136a97cbf411fad7e1bedbbb79a7c49d2
-rw-r--r-- | src/lib/MSPUBParser.cpp | 8 | ||||
-rw-r--r-- | src/lib/MSPUBTypes.h | 12 |
2 files changed, 10 insertions, 10 deletions
diff --git a/src/lib/MSPUBParser.cpp b/src/lib/MSPUBParser.cpp index 8a307eb..1b1be01 100644 --- a/src/lib/MSPUBParser.cpp +++ b/src/lib/MSPUBParser.cpp @@ -2387,7 +2387,7 @@ bool MSPUBParser::parseContentChunkReference(librevenge::RVNGInputStream *input, { //input should be at block.dataOffset + 4 , that is, at the beginning of the list of sub-blocks MSPUB_DEBUG_MSG(("Parsing chunk reference 0x%x\n", m_lastSeenSeqNum)); - MSPUBContentChunkType type = UNKNOWN_CHUNK; + unsigned type = UNKNOWN_CHUNK; unsigned long offset = 0; unsigned parentSeqNum = 0; bool seenType = false; @@ -2399,7 +2399,7 @@ bool MSPUBParser::parseContentChunkReference(librevenge::RVNGInputStream *input, //FIXME: Warn if multiple of these blocks seen. if (subBlock.id == CHUNK_TYPE) { - type = (MSPUBContentChunkType)subBlock.data; + type = subBlock.data; seenType = true; } else if (subBlock.id == CHUNK_OFFSET) @@ -2498,8 +2498,8 @@ MSPUBBlockInfo MSPUBParser::parseBlock(librevenge::RVNGInputStream *input, bool { MSPUBBlockInfo info; info.startPosition = input->tell(); - info.id = (MSPUBBlockID)readU8(input); - info.type = (MSPUBBlockType)readU8(input); + info.id = readU8(input); + info.type = readU8(input); info.dataOffset = input->tell(); int len = getBlockDataLength(info.type); bool varLen = len < 0; diff --git a/src/lib/MSPUBTypes.h b/src/lib/MSPUBTypes.h index 04219d0..d44d020 100644 --- a/src/lib/MSPUBTypes.h +++ b/src/lib/MSPUBTypes.h @@ -77,9 +77,9 @@ struct EscherContainerInfo struct MSPUBBlockInfo { - MSPUBBlockInfo() : id((MSPUBBlockID)0), type((MSPUBBlockType)0), startPosition(0), dataOffset(0), dataLength(0), data(0), stringData() { } - MSPUBBlockID id; - MSPUBBlockType type; + MSPUBBlockInfo() : id(0), type(0), startPosition(0), dataOffset(0), dataLength(0), data(0), stringData() { } + unsigned id; + unsigned type; unsigned long startPosition; unsigned long dataOffset; unsigned long dataLength; @@ -89,10 +89,10 @@ struct MSPUBBlockInfo struct ContentChunkReference { - ContentChunkReference() : type(UNKNOWN_CHUNK), offset(0), end(0), seqNum(0), parentSeqNum(0) { } - ContentChunkReference(MSPUBContentChunkType t, unsigned long o, unsigned long e, unsigned sn, unsigned psn) : + ContentChunkReference() : type(0), offset(0), end(0), seqNum(0), parentSeqNum(0) { } + ContentChunkReference(unsigned t, unsigned long o, unsigned long e, unsigned sn, unsigned psn) : type(t), offset(o), end(e), seqNum(sn), parentSeqNum(psn) {} - MSPUBContentChunkType type; + unsigned type; unsigned long offset; unsigned long end; //offset of the last element plus one. unsigned seqNum; |