diff --git a/src/board.c b/src/board.c index 7228792..159a7b6 100644 --- a/src/board.c +++ b/src/board.c @@ -228,40 +228,34 @@ static int board_fail(unsigned int wdw) { * @brief Updates the boarding window. */ static void board_update(unsigned int wdw) { - int i, len; - char str[128], buf[32]; + int i, j; + char str[PATH_MAX]; char cred[10]; Pilot* p; p = pilot_get(player->target); + j = 0; /* Credits. */ credits2str(cred, p->credits, 2); - snprintf(str, 128, "%s\n", cred); - len = strlen(str); + j += snprintf(&str[j], PATH_MAX-j, "%s\n", cred); /* Commodities. */ - if(p->ncommodities == 0) { - strncat(str, "none\n", 128-len); - len = strlen(str); - } else { - for(i = 0; i < p->ncommodities; i++) { - snprintf(buf, 32, + if(p->ncommodities == 0) + j += snprintf(&str[j], PATH_MAX-j, "none\n"); + else { + for(i = 0; i < p->ncommodities; i++) + j += snprintf(&str[j], PATH_MAX-j, "%d %s\n", p->commodities[i].quantity, p->commodities[i].commodity->name); - strncat(str, buf, 128-len); - len = strlen(str); - } } + /* Fuel. */ if(p->fuel <= 0.) - strncat(str, "none", 128-len); - else { - snprintf(buf, 32, "%.0f Units", p->fuel); - strncat(str, buf, 128-len); - } - len = strlen(str); + j += snprintf(&str[j], PATH_MAX-j, "none\n"); + else + j += snprintf(&str[j], PATH_MAX-j, "%.0f Units\n", p->fuel); window_modifyText(wdw, "txtData", str); } diff --git a/src/map.c b/src/map.c index a9d4e98..585a014 100644 --- a/src/map.c +++ b/src/map.c @@ -152,7 +152,8 @@ static void map_update(unsigned int wid) { StarSystem* sys; int f, y, h, standing, nstanding; unsigned int services; - char buf[128]; + char buf[PATH_MAX]; + int p; /* Needs map to update. */ if(!map_isOpen()) @@ -230,12 +231,12 @@ static void map_update(unsigned int wid) { strncpy(buf, "None", 128); window_modifyText(wid, "txtPlanets", buf); } else { + p = 0; buf[0] = '\0'; if(sys->nplanets > 0) - strcat(buf, sys->planets[0]->name); + p += snprintf(&buf[p], PATH_MAX-p, "%s", sys->planets[0]->name); for(i = 1; i < sys->nplanets; i++) { - strcat(buf, ",\n"); - strcat(buf, sys->planets[i]->name); + p += snprintf(&buf[p], PATH_MAX-p, ",\n%s", sys->planets[i]->name); } window_modifyText(wid, "txtPlanets", buf); } @@ -252,34 +253,53 @@ static void map_update(unsigned int wid) { for(i = 0; i < sys->nplanets; i++) services |= sys->planets[i]->services; buf[0] = '\0'; + p = 0; /*snprintf(buf, sizeof(buf), "%f\n", sys->prices[0]); */ if(services & PLANET_SERVICE_COMMODITY) - strcat(buf, "Commodity\n"); + p += snprintf(&buf[p], PATH_MAX-p, "Commodity\n"); if(services & PLANET_SERVICE_OUTFITS) - strcat(buf, "Outfits\n"); + p += snprintf(&buf[p], PATH_MAX-p, "Outfits\n"); if(services & PLANET_SERVICE_SHIPYARD) - strcat(buf, "Shipyard\n"); + p += snprintf(&buf[p], PATH_MAX-p, "Shipyard\n"); if(buf[0] == '\0') - strcat(buf, "None"); + p += snprintf(&buf[p], PATH_MAX-p, "None"); window_modifyText(wid, "txtServices", buf); /* System status. */ buf[0] = '\0'; + p = 0; + + /* Nebulae. */ if(sys->nebu_density > 0.) { /* Has nebulae. */ /* Volatility. */ if(sys->nebu_volatility > 700.) - strcat(buf, " Volatile"); + p += snprintf(&buf[p], PATH_MAX-p, " Volatile"); else if(sys->nebu_volatility > 300.) - strcat(buf, " Dangerous"); + p += snprintf(&buf[p], PATH_MAX-p, " Dangerous"); else if(sys->nebu_volatility > 0.) - strcat(buf, " Unstable"); + p += snprintf(&buf[p], PATH_MAX-p, " Unstable"); + /* Density */ if(sys->nebu_density > 700.) - strcat(buf, " Dense"); + p += snprintf(&buf[p], PATH_MAX-p, " Dense"); else if(sys->nebu_density < 300.) - strcat(buf, " Light"); - strcat(buf, " Nebulae"); + p += snprintf(&buf[p], PATH_MAX-p, " Light"); + p += snprintf(&buf[p], PATH_MAX-p, " Nebulae"); } + /* Interference. */ + if(sys->interference > 0.) { + if(buf[0] != '\0') + p += snprintf(&buf[p], PATH_MAX-p, ","); + + /* Density. */ + if(sys->interference > 700.) + p += snprintf(&buf[p], PATH_MAX-p, " Dense"); + else if(sys->interference < 300.) + p += snprintf(&buf[p], PATH_MAX-p, " Light"); + + p += snprintf(&buf[p], PATH_MAX-p, " Interference"); + } + window_modifyText(wid, "txtSystemStatus", buf); } diff --git a/src/pilot.c b/src/pilot.c index c4ff1fd..22d3e18 100644 --- a/src/pilot.c +++ b/src/pilot.c @@ -1039,24 +1039,27 @@ int pilot_rmOutfit(Pilot* pilot, Outfit* outfit, int quantity) { /* Return all the outfits in a nice text form. */ char* pilot_getOutfits(Pilot* pilot) { int i; - char buf[64], *str; + char* buf; + int p, len; - str = malloc(sizeof(char)*1024); + len = 1024; + + buf = malloc(sizeof(char)*len); buf[0] = '\0'; + p = 0; /* First outfit. */ if(pilot->noutfits > 0) - snprintf(str, 1024, "%dx %s", + p += snprintf(&buf[p], len-p, "%dx %s", pilot->outfits[0].quantity, pilot->outfits[0].outfit->name); else - snprintf(str, 1024, "None"); + p += snprintf(&buf[p], len-p, "None"); /* Rest of the outfits. */ - for(i = 1; i < pilot->noutfits; i++) { - snprintf(buf, 64, ", %dx %s", + for(i = 1; i < pilot->noutfits; i++) + p += snprintf(&buf[p], len-p, ", %dx %s", pilot->outfits[i].quantity, pilot->outfits[i].outfit->name); - strcat(str, buf); - } - return str; + + return buf; } /* Recalculate the pilot's stats based on her outfits. */