[Fix] Some long time snprintf mistakes.
This commit is contained in:
parent
652d9352ad
commit
0231017e57
12
src/outfit.c
12
src/outfit.c
@ -616,7 +616,7 @@ static void outfit_parseSBeam(Outfit* tmp, const xmlNodePtr parent) {
|
||||
}
|
||||
|
||||
} while(xml_nextNode(node));
|
||||
|
||||
|
||||
#define MELEMENT(o,s) if(0) WARN("Outfit '%s' missing/invalid '"s"' element", tmp->name)
|
||||
MELEMENT(tmp->u.bem.gfx==NULL, "gfx");
|
||||
MELEMENT(tmp->u.bem.spfx==-1, "spfx");
|
||||
@ -636,7 +636,7 @@ static void outfit_parseSBeam(Outfit* tmp, const xmlNodePtr parent) {
|
||||
/* Parse the specific area for a launcher and loads it into Outfit. */
|
||||
static void outfit_parseSLauncher(Outfit* tmp, const xmlNodePtr parent) {
|
||||
xmlNodePtr node;
|
||||
|
||||
|
||||
node = parent->xmlChildrenNode;
|
||||
do {
|
||||
/* Load the dataz. */
|
||||
@ -668,8 +668,7 @@ static void outfit_parseSAmmo(Outfit* tmp, const xmlNodePtr parent) {
|
||||
xmlr_float(node, "speed", tmp->u.amm.speed);
|
||||
xmlr_float(node, "energy", tmp->u.amm.energy);
|
||||
if(xml_isNode(node, "gfx")) {
|
||||
snprintf(str, strlen(xml_get(node))+sizeof(OUTFIT_GFX)+10,
|
||||
OUTFIT_GFX"space/%s.png", xml_get(node));
|
||||
snprintf(str, PATH_MAX, OUTFIT_GFX"space/%s.png", xml_get(node));
|
||||
tmp->u.amm.gfx_space = gl_newSprite(str, 6, 6);
|
||||
continue;
|
||||
}
|
||||
@ -680,7 +679,7 @@ static void outfit_parseSAmmo(Outfit* tmp, const xmlNodePtr parent) {
|
||||
else if(xml_isNode(node, "damage"))
|
||||
outfit_parseDamage(&tmp->u.amm.dtype, &tmp->u.amm.damage, node);
|
||||
} while((node = node->next));
|
||||
|
||||
|
||||
/* Post-processing. */
|
||||
tmp->u.amm.resist /= 100.; /* Set it in per one. */
|
||||
|
||||
@ -805,8 +804,7 @@ static Outfit* outfit_parse(const xmlNodePtr parent) {
|
||||
xmlr_int(cur, "price", tmp->price);
|
||||
xmlr_strd(cur, "description", tmp->description);
|
||||
if(xml_isNode(cur, "gfx_store")) {
|
||||
snprintf(str, strlen(xml_get(cur))+sizeof(OUTFIT_GFX)+10,
|
||||
OUTFIT_GFX"store/%s.png", xml_get(cur));
|
||||
snprintf(str, PATH_MAX, OUTFIT_GFX"store/%s.png", xml_get(cur));
|
||||
tmp->gfx_store = gl_newImage(str);
|
||||
}
|
||||
} while((cur = cur->next));
|
||||
|
41
src/player.c
41
src/player.c
@ -322,7 +322,7 @@ static void player_newMake(void) {
|
||||
player_new();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
space_init(sysname);
|
||||
free(sysname);
|
||||
|
||||
@ -499,7 +499,7 @@ void player_rmShip(char* shipname) {
|
||||
sizeof(char*) * (player_nstack-i-1));
|
||||
|
||||
player_nstack--; /* Shrink stack. */
|
||||
|
||||
|
||||
/* Realloc memory to smaller size. */
|
||||
player_stack = realloc(player_stack,
|
||||
sizeof(Pilot*) * (player_nstack));
|
||||
@ -539,7 +539,7 @@ void player_cleanup(void) {
|
||||
/* Nothing left. */
|
||||
player_nstack = 0;
|
||||
}
|
||||
|
||||
|
||||
/* Clean up missions. */
|
||||
if(missions_done != NULL) {
|
||||
free(missions_done);
|
||||
@ -824,12 +824,12 @@ void player_renderGUI(void) {
|
||||
}
|
||||
/* Fancy cinematic scene borders. */
|
||||
spfx_cinematic();
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(player == NULL) return;
|
||||
|
||||
|
||||
/* Lockon warning. */
|
||||
if(player->lockons > 0)
|
||||
gl_printMid(NULL, SCREEN_W, 0., SCREEN_H-gl_defFont.h-25.,
|
||||
@ -1269,31 +1269,30 @@ static void rect_parse(const xmlNodePtr parent, double* x, double* y,
|
||||
{ (a).x += VX(gui.frame); (a).y = VY(gui.frame) + gui.gfx_frame->h-(a).y; }
|
||||
static int gui_parse(const xmlNodePtr parent, const char* name) {
|
||||
xmlNodePtr cur, node;
|
||||
char* tmp, *tmp2;
|
||||
char* tmp, buf[PATH_MAX];
|
||||
|
||||
/* Gfx. */
|
||||
/* Set a property and not a node because it must be loaded first. */
|
||||
tmp2 = xml_nodeProp(parent, "gfx");
|
||||
if(tmp2 == NULL) {
|
||||
tmp = xml_nodeProp(parent, "gfx");
|
||||
if(tmp == NULL) {
|
||||
ERR("GUI '%s' has no gfx property", name);
|
||||
return -1;
|
||||
}
|
||||
/* Load gfx. */
|
||||
tmp = malloc((strlen(tmp2)+strlen(GUI_GFX)+12) * sizeof(char));
|
||||
|
||||
/* Frame. */
|
||||
snprintf(tmp, strlen(tmp2)+strlen(GUI_GFX)+5, GUI_GFX"%s.png", tmp2);
|
||||
snprintf(buf, PATH_MAX, GUI_GFX"%s.png", tmp);
|
||||
if(gui.gfx_frame) gl_freeTexture(gui.gfx_frame); /* Free if needed. */
|
||||
gui.gfx_frame = gl_newImage(tmp);
|
||||
gui.gfx_frame = gl_newImage(buf);
|
||||
/* Pilot. */
|
||||
snprintf(tmp, strlen(tmp2)+strlen(GUI_GFX)+11, GUI_GFX"%s_pilot.png", tmp2);
|
||||
snprintf(buf, PATH_MAX, GUI_GFX"%s_pilot.png", tmp);
|
||||
if(gui.gfx_targetPilot) gl_freeTexture(gui.gfx_targetPilot); /* Free if needed. */
|
||||
gui.gfx_targetPilot = gl_newSprite(tmp, 2, 2);
|
||||
gui.gfx_targetPilot = gl_newSprite(buf, 2, 2);
|
||||
/* Planet. */
|
||||
snprintf(tmp, strlen(tmp2)+strlen(GUI_GFX)+12, GUI_GFX"%s_planet.png", tmp2);
|
||||
snprintf(buf, PATH_MAX, GUI_GFX"%s_planet.png", tmp);
|
||||
if(gui.gfx_targetPlanet) gl_freeTexture(gui.gfx_targetPlanet); /* Free if needed. */
|
||||
gui.gfx_targetPlanet = gl_newSprite(tmp, 2, 2);
|
||||
gui.gfx_targetPlanet = gl_newSprite(buf, 2, 2);
|
||||
free(tmp);
|
||||
free(tmp2);
|
||||
|
||||
/* Frame (based on gfx). */
|
||||
vect_csetmin(&gui.frame,
|
||||
@ -1477,7 +1476,7 @@ void player_think(Pilot* pplayer) {
|
||||
}
|
||||
else if(player_isFlag(PLAYER_SECONDARY_L)) {
|
||||
player_rmFlag(PLAYER_SECONDARY_L);
|
||||
}
|
||||
}
|
||||
|
||||
/* Afterburn! */
|
||||
if(player_isFlag(PLAYER_AFTERBURNER)) {
|
||||
@ -1698,7 +1697,7 @@ void player_brokeHyperspace(void) {
|
||||
/* Set position, pilot_update will handle the lowering of velocity. */
|
||||
player_warp(-cos(player->solid->dir) * MIN_HYPERSPACE_DIST * 2.5,
|
||||
-sin(player->solid->dir) * MIN_HYPERSPACE_DIST * 2.5);
|
||||
|
||||
|
||||
/* Reduce fuel. */
|
||||
player->fuel -= HYPERSPACE_FUEL;
|
||||
|
||||
@ -2119,7 +2118,7 @@ static int player_parse(xmlNodePtr parent) {
|
||||
|
||||
if(xml_isNode(node, "ship"))
|
||||
player_parseShip(node, 1);
|
||||
|
||||
|
||||
if(xml_isNode(node, "ships")) {
|
||||
cur = node->xmlChildrenNode;
|
||||
do {
|
||||
@ -2238,7 +2237,7 @@ static int player_parseShip(xmlNodePtr parent, int is_player) {
|
||||
/* Set fuel. */
|
||||
if(fuel != 0)
|
||||
ship->fuel = MIN(ship->fuel_max, fuel);
|
||||
|
||||
|
||||
/* Add it to the stack if it's not what the player is in. */
|
||||
if(is_player == 0) {
|
||||
player_stack = realloc(player_stack, sizeof(Pilot*)*(player_nstack+1));
|
||||
@ -2247,7 +2246,7 @@ static int player_parseShip(xmlNodePtr parent, int is_player) {
|
||||
player_lstack[player_nstack] = strdup(loc);
|
||||
player_nstack++;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
17
src/space.c
17
src/space.c
@ -313,7 +313,7 @@ char* space_getRndPlanet(void) {
|
||||
return res;
|
||||
}
|
||||
|
||||
/* Return 1 if player can reach the system. */
|
||||
/* Return 1 if player can reach the system. */
|
||||
int space_sysReachable(StarSystem* sys) {
|
||||
int i;
|
||||
|
||||
@ -527,8 +527,7 @@ static Planet* planet_pull(const char* name) {
|
||||
do {
|
||||
if(xml_isNode(cur, "space")) {
|
||||
/* Load space gfx. */
|
||||
snprintf(str, strlen(xml_get(cur))+sizeof(PLANET_GFX_SPACE),
|
||||
PLANET_GFX_SPACE"%s", xml_get(cur));
|
||||
snprintf(str, PATH_MAX, PLANET_GFX_SPACE"%s", xml_get(cur));
|
||||
tmp->gfx_space = gl_newImage(str);
|
||||
}
|
||||
else if(xml_isNode(cur, "exterior")) {
|
||||
@ -860,7 +859,7 @@ void space_render(const double dt) {
|
||||
|
||||
/* Render the overlay. */
|
||||
void space_renderOverlay(const double dt) {
|
||||
if(cur_system == NULL) return;
|
||||
if(cur_system == NULL) return;
|
||||
|
||||
if(cur_system->nebu_density > 0.)
|
||||
nebu_renderOverlay(dt);
|
||||
@ -911,7 +910,7 @@ static void space_renderStars(const double dt) {
|
||||
b = 13.-10.*stars[i].brightness;
|
||||
stars[i].x -= player->solid->vel.x/b*dt;
|
||||
stars[i].y -= player->solid->vel.y/b*dt;
|
||||
|
||||
|
||||
/* Check for boundaries. */
|
||||
if(stars[i].x > SCREEN_W + STAR_BUF) stars[i].x = -STAR_BUF;
|
||||
else if(stars[i].x < -STAR_BUF) stars[i].x = SCREEN_W + STAR_BUF;
|
||||
@ -952,13 +951,13 @@ void planets_render(void) {
|
||||
/* Clean up the system. */
|
||||
void space_exit(void) {
|
||||
int i,j;
|
||||
|
||||
|
||||
/* Free the names. */
|
||||
/*if(planetname_stack) free(planetname_stack); */
|
||||
/*if(systemname_stack) free(systemname_stack); */
|
||||
if(planetname_stack) {
|
||||
free(planetname_stack);
|
||||
planetname_stack = NULL;
|
||||
free(planetname_stack);
|
||||
planetname_stack = NULL;
|
||||
}
|
||||
if(systemname_stack) {
|
||||
free(systemname_stack);
|
||||
@ -1039,7 +1038,7 @@ int space_sysLoad(xmlNodePtr parent) {
|
||||
StarSystem* sys;
|
||||
|
||||
space_clearKnown();
|
||||
|
||||
|
||||
node = parent->xmlChildrenNode;
|
||||
do {
|
||||
if(xml_isNode(node, "space")) {
|
||||
|
Loading…
Reference in New Issue
Block a user