Make sure that the pointer is checked for null before dereferencing.
From: Erik Hovland <erik@hovland.org>
---
libs/libmythfreemheg/Groups.cpp | 8 ++++---
libs/libmythfreemheg/Link.cpp | 2 +-
libs/libmythfreemheg/Programs.cpp | 4 +++
libs/libmythfreemheg/Stream.cpp | 42 +++++++++++++++++++----------------
libs/libmythfreemheg/TokenGroup.cpp | 10 +++++---
libs/libmythfreemheg/Variables.cpp | 18 +++++++++------
6 files changed, 49 insertions(+), 35 deletions(-)
diff --git a/libs/libmythfreemheg/Groups.cpp b/libs/libmythfreemheg/Groups.cpp
index a65c465..2240366 100644
a
|
b
|
void MHScene::Initialise(MHParseNode *p, MHEngine *engine) |
398 | 398 | MHGroup::Initialise(p, engine); |
399 | 399 | // Event register. |
400 | 400 | MHParseNode *pInputEventReg = p->GetNamedArg(C_INPUT_EVENT_REGISTER); |
401 | | m_nEventReg = pInputEventReg->GetArgN(0)->GetIntValue(); |
| 401 | if (pInputEventReg) m_nEventReg = pInputEventReg->GetArgN(0)->GetIntValue(); |
402 | 402 | // Co-ordinate system |
403 | 403 | MHParseNode *pSceneCoords = p->GetNamedArg(C_SCENE_COORDINATE_SYSTEM); |
404 | | m_nSceneCoordX = pSceneCoords->GetArgN(0)->GetIntValue(); |
405 | | m_nSceneCoordY = pSceneCoords->GetArgN(1)->GetIntValue(); |
| 404 | if (pSceneCoords) { |
| 405 | m_nSceneCoordX = pSceneCoords->GetArgN(0)->GetIntValue(); |
| 406 | m_nSceneCoordY = pSceneCoords->GetArgN(1)->GetIntValue(); |
| 407 | } |
406 | 408 | // Aspect ratio |
407 | 409 | MHParseNode *pAspectRatio = p->GetNamedArg(C_ASPECT_RATIO); |
408 | 410 | if (pAspectRatio) { |
diff --git a/libs/libmythfreemheg/Link.cpp b/libs/libmythfreemheg/Link.cpp
index daab860..30d0878 100644
a
|
b
|
void MHLink::Initialise(MHParseNode *p, MHEngine *engine) |
73 | 73 | } |
74 | 74 | |
75 | 75 | MHParseNode *pLinkEffect = p->GetNamedArg(C_LINK_EFFECT); |
76 | | m_LinkEffect.Initialise(pLinkEffect, engine); |
| 76 | if (pLinkEffect) m_LinkEffect.Initialise(pLinkEffect, engine); |
77 | 77 | } |
78 | 78 | |
79 | 79 | static const char *rchEventType[] = |
diff --git a/libs/libmythfreemheg/Programs.cpp b/libs/libmythfreemheg/Programs.cpp
index 8895d21..0dd4fa4 100644
a
|
b
|
MHProgram::MHProgram() |
50 | 50 | void MHProgram::Initialise(MHParseNode *p, MHEngine *engine) |
51 | 51 | { |
52 | 52 | MHIngredient::Initialise(p, engine); |
53 | | p->GetNamedArg(C_NAME)->GetArgN(0)->GetStringValue(m_Name); // Program name |
| 53 | MHParseNode *pCmdNode = p->GetNamedArg(C_NAME); |
| 54 | if (pCmdNode) pCmdNode->GetArgN(0)->GetStringValue(m_Name); // Program name |
| 55 | |
54 | 56 | MHParseNode *pAvail = p->GetNamedArg(C_INITIALLY_AVAILABLE); |
55 | 57 | if (pAvail) m_fInitiallyAvailable = pAvail->GetArgN(0)->GetBoolValue(); |
56 | 58 | // The MHEG Standard says that InitiallyAvailable is mandatory and should be false. |
diff --git a/libs/libmythfreemheg/Stream.cpp b/libs/libmythfreemheg/Stream.cpp
index f88899c..9dda175 100644
a
|
b
|
void MHStream::Initialise(MHParseNode *p, MHEngine *engine) |
40 | 40 | { |
41 | 41 | MHPresentable::Initialise(p, engine); |
42 | 42 | MHParseNode *pMultiplex = p->GetNamedArg(C_MULTIPLEX); |
43 | | for (int i = 0; i < pMultiplex->GetArgCount(); i++) { |
44 | | MHParseNode *pItem = pMultiplex->GetArgN(i); |
45 | | if (pItem->GetTagNo() == C_AUDIO) { |
46 | | MHAudio *pAudio = new MHAudio; |
47 | | m_Multiplex.Append(pAudio); |
48 | | pAudio->Initialise(pItem, engine); |
| 43 | if (pMultiplex) { |
| 44 | for (int i = 0; i < pMultiplex->GetArgCount(); i++) { |
| 45 | MHParseNode *pItem = pMultiplex->GetArgN(i); |
| 46 | if (pItem->GetTagNo() == C_AUDIO) { |
| 47 | MHAudio *pAudio = new MHAudio; |
| 48 | m_Multiplex.Append(pAudio); |
| 49 | pAudio->Initialise(pItem, engine); |
| 50 | } |
| 51 | else if (pItem->GetTagNo() == C_VIDEO) { |
| 52 | MHVideo *pVideo = new MHVideo; |
| 53 | m_Multiplex.Append(pVideo); |
| 54 | pVideo->Initialise(pItem, engine); |
| 55 | } |
| 56 | else if (pItem->GetTagNo() == C_RTGRAPHICS) { |
| 57 | MHRTGraphics *pRtGraph = new MHRTGraphics; |
| 58 | m_Multiplex.Append(pRtGraph); |
| 59 | pRtGraph->Initialise(pItem, engine); |
| 60 | } |
| 61 | // Ignore unknown items |
49 | 62 | } |
50 | | else if (pItem->GetTagNo() == C_VIDEO) { |
51 | | MHVideo *pVideo = new MHVideo; |
52 | | m_Multiplex.Append(pVideo); |
53 | | pVideo->Initialise(pItem, engine); |
54 | | } |
55 | | else if (pItem->GetTagNo() == C_RTGRAPHICS) { |
56 | | MHRTGraphics *pRtGraph = new MHRTGraphics; |
57 | | m_Multiplex.Append(pRtGraph); |
58 | | pRtGraph->Initialise(pItem, engine); |
59 | | } |
60 | | // Ignore unknown items |
61 | 63 | } |
62 | 64 | MHParseNode *pStorage = p->GetNamedArg(C_STORAGE); |
63 | 65 | if (pStorage) m_nStorage = (enum Storage) pStorage->GetArgN(0)->GetEnumValue(); |
… |
… |
MHAudio::MHAudio() |
150 | 152 | void MHAudio::Initialise(MHParseNode *p, MHEngine *engine) |
151 | 153 | { |
152 | 154 | MHPresentable::Initialise(p, engine); |
153 | | m_nComponentTag = p->GetNamedArg(C_COMPONENT_TAG)->GetArgN(0)->GetIntValue(); |
| 155 | MHParseNode *pComponentTagNode = p->GetNamedArg(C_COMPONENT_TAG); |
| 156 | if (pComponentTagNode) m_nComponentTag = pComponentTagNode->GetArgN(0)->GetIntValue(); |
154 | 157 | MHParseNode *pOrigVol = p->GetNamedArg(C_ORIGINAL_VOLUME); |
155 | 158 | if (pOrigVol) m_nOriginalVol = pOrigVol->GetIntValue(); |
156 | 159 | } |
… |
… |
MHVideo::MHVideo() |
232 | 235 | void MHVideo::Initialise(MHParseNode *p, MHEngine *engine) |
233 | 236 | { |
234 | 237 | MHVisible::Initialise(p, engine); |
235 | | m_nComponentTag = p->GetNamedArg(C_COMPONENT_TAG)->GetArgN(0)->GetIntValue(); |
| 238 | MHParseNode *pComponentTagNode = p->GetNamedArg(C_COMPONENT_TAG); |
| 239 | if (pComponentTagNode) m_nComponentTag = pComponentTagNode->GetArgN(0)->GetIntValue(); |
236 | 240 | MHParseNode *pTerm = p->GetNamedArg(C_TERMINATION); |
237 | 241 | if (pTerm) m_Termination = (enum Termination)pTerm->GetEnumValue(); |
238 | 242 | } |
diff --git a/libs/libmythfreemheg/TokenGroup.cpp b/libs/libmythfreemheg/TokenGroup.cpp
index c3f0005..3576c36 100644
a
|
b
|
void MHListGroup::Initialise(MHParseNode *p, MHEngine *engine) |
231 | 231 | { |
232 | 232 | MHTokenGroup::Initialise(p, engine); |
233 | 233 | MHParseNode *pPositions = p->GetNamedArg(C_POSITIONS); |
234 | | for (int i = 0; i < pPositions->GetArgCount(); i++) { |
235 | | MHParseNode *pPos = pPositions->GetArgN(i); |
236 | | QPoint pos(pPos->GetSeqN(0)->GetIntValue(), pPos->GetSeqN(1)->GetIntValue()); |
237 | | m_Positions.Append(pos); |
| 234 | if (pPositions) { |
| 235 | for (int i = 0; i < pPositions->GetArgCount(); i++) { |
| 236 | MHParseNode *pPos = pPositions->GetArgN(i); |
| 237 | QPoint pos(pPos->GetSeqN(0)->GetIntValue(), pPos->GetSeqN(1)->GetIntValue()); |
| 238 | m_Positions.Append(pos); |
| 239 | } |
238 | 240 | } |
239 | 241 | MHParseNode *pWrap = p->GetNamedArg(C_WRAP_AROUND); |
240 | 242 | if (pWrap) m_fWrapAround = pWrap->GetArgN(0)->GetBoolValue(); |
diff --git a/libs/libmythfreemheg/Variables.cpp b/libs/libmythfreemheg/Variables.cpp
index 14ea9d6..da813c5 100644
a
|
b
|
void MHBooleanVar::Initialise(MHParseNode *p, MHEngine *engine) |
57 | 57 | MHVariable::Initialise(p, engine); |
58 | 58 | // Original value should be a bool. |
59 | 59 | MHParseNode *pInitial = p->GetNamedArg(C_ORIGINAL_VALUE); |
60 | | m_fOriginalValue = pInitial->GetArgN(0)->GetBoolValue(); |
| 60 | if (pInitial) m_fOriginalValue = pInitial->GetArgN(0)->GetBoolValue(); |
61 | 61 | } |
62 | 62 | |
63 | 63 | void MHBooleanVar::PrintMe(FILE *fd, int nTabs) const |
… |
… |
void MHIntegerVar::Initialise(MHParseNode *p, MHEngine *engine) |
111 | 111 | MHVariable::Initialise(p, engine); |
112 | 112 | // Original value should be an int. |
113 | 113 | MHParseNode *pInitial = p->GetNamedArg(C_ORIGINAL_VALUE); |
114 | | m_nOriginalValue = pInitial->GetArgN(0)->GetIntValue(); |
| 114 | if (pInitial) m_nOriginalValue = pInitial->GetArgN(0)->GetIntValue(); |
115 | 115 | } |
116 | 116 | |
117 | 117 | void MHIntegerVar::PrintMe(FILE *fd, int nTabs) const |
… |
… |
void MHOctetStrVar::Initialise(MHParseNode *p, MHEngine *engine) |
185 | 185 | MHVariable::Initialise(p, engine); |
186 | 186 | // Original value should be a string. |
187 | 187 | MHParseNode *pInitial = p->GetNamedArg(C_ORIGINAL_VALUE); |
188 | | pInitial->GetArgN(0)->GetStringValue(m_OriginalValue); |
| 188 | if (pInitial) pInitial->GetArgN(0)->GetStringValue(m_OriginalValue); |
189 | 189 | } |
190 | 190 | |
191 | 191 | void MHOctetStrVar::PrintMe(FILE *fd, int nTabs) const |
… |
… |
void MHObjectRefVar::Initialise(MHParseNode *p, MHEngine *engine) |
258 | 258 | // Original value should be an object reference. |
259 | 259 | MHParseNode *pInitial = p->GetNamedArg(C_ORIGINAL_VALUE); |
260 | 260 | // and this should be a ObjRef node. |
261 | | MHParseNode *pArg = pInitial->GetNamedArg(C_OBJECT_REFERENCE); |
262 | | m_OriginalValue.Initialise(pArg->GetArgN(0), engine); |
| 261 | if (pInitial) { |
| 262 | MHParseNode *pArg = pInitial->GetNamedArg(C_OBJECT_REFERENCE); |
| 263 | if (pArg) m_OriginalValue.Initialise(pArg->GetArgN(0), engine); |
| 264 | } |
263 | 265 | } |
264 | 266 | |
265 | 267 | void MHObjectRefVar::PrintMe(FILE *fd, int nTabs) const |
… |
… |
void MHContentRefVar::Initialise(MHParseNode *p, MHEngine *engine) |
312 | 314 | // Original value should be a content reference. |
313 | 315 | MHParseNode *pInitial = p->GetNamedArg(C_ORIGINAL_VALUE); |
314 | 316 | // and this should be a ContentRef node. |
315 | | MHParseNode *pArg = pInitial->GetNamedArg(C_CONTENT_REFERENCE); |
316 | | m_OriginalValue.Initialise(pArg->GetArgN(0), engine); |
| 317 | if (pInitial) { |
| 318 | MHParseNode *pArg = pInitial->GetNamedArg(C_CONTENT_REFERENCE); |
| 319 | if (pArg) m_OriginalValue.Initialise(pArg->GetArgN(0), engine); |
| 320 | } |
317 | 321 | } |
318 | 322 | |
319 | 323 | void MHContentRefVar::PrintMe(FILE *fd, int nTabs) const |