From 4c79651326eeabc2a53534a3b8b1b5aff885dd5a Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Wed, 20 Feb 2013 08:06:16 -0500 Subject: Prevent segmentation faults in some places. --- diff --git a/src/area.c b/src/area.c index 7e7f3ed..4f0bc11 100644 --- a/src/area.c +++ b/src/area.c @@ -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)); diff --git a/src/xml.c b/src/xml.c index e677fe1..d34b0ac 100644 --- a/src/xml.c +++ b/src/xml.c @@ -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; } -- cgit v0.9.1