diff options
author | P. J. McDermott <pjm@nac.net> | 2013-02-20 08:06:16 (EST) |
---|---|---|
committer | P. J. McDermott <pjm@nac.net> | 2013-02-20 08:06:16 (EST) |
commit | 4c79651326eeabc2a53534a3b8b1b5aff885dd5a (patch) | |
tree | 7adbc176b69b290629ca1bb6e3408f41132e3498 | |
parent | b87ba33f92354fca6d9cbb8ad76f62bc01233787 (diff) | |
download | overworld-rpg-4c79651326eeabc2a53534a3b8b1b5aff885dd5a.zip overworld-rpg-4c79651326eeabc2a53534a3b8b1b5aff885dd5a.tar.gz overworld-rpg-4c79651326eeabc2a53534a3b8b1b5aff885dd5a.tar.bz2 |
Prevent segmentation faults in some places.
-rw-r--r-- | src/area.c | 15 | ||||
-rw-r--r-- | src/xml.c | 12 |
2 files changed, 24 insertions, 3 deletions
@@ -12,6 +12,10 @@ area_new(struct map *map) { struct area *a; + if (map == NULL) { + return NULL; + } + a = malloc(sizeof(*a)); if (a == NULL) { return NULL; @@ -126,6 +130,10 @@ render_area_to_viewport(struct area *area, struct viewport *vp) SDL_Rect srcrect; SDL_Rect dstrect; + if (area == NULL || vp == NULL) { + return; + } + srcrect.x = vp->x; srcrect.y = vp->y; srcrect.w = vp->w; @@ -146,6 +154,13 @@ render_area_to_surface(struct area *area, SDL_Rect *arearect, /* For demo */ SDL_Rect tmprect; + if (area == NULL || arearect == NULL) { + return; + } + if (surface == NULL || surfacerect == NULL) { + return; + } + memcpy(&srcrect, arearect, sizeof(srcrect)); memcpy(&dstrect, surfacerect, sizeof(dstrect)); @@ -126,9 +126,15 @@ xml_node_pop(XML_Parser p) free(n); n = (struct xml_node *) XML_GetUserData(p); - XML_SetStartElementHandler(p, n->start); - XML_SetEndElementHandler(p, n->end); - XML_SetCharacterDataHandler(p, n->charhndl); + if (n == NULL) { + XML_SetStartElementHandler(p, NULL); + XML_SetEndElementHandler(p, NULL); + XML_SetCharacterDataHandler(p, NULL); + } else { + XML_SetStartElementHandler(p, n->start); + XML_SetEndElementHandler(p, n->end); + XML_SetCharacterDataHandler(p, n->charhndl); + } return data; } |