[Change] Removed all "improper" usage of strcat/strncat.
This commit is contained in:
parent
06891d765d
commit
871c5c89e5
32
src/board.c
32
src/board.c
@ -228,40 +228,34 @@ static int board_fail(unsigned int wdw) {
|
|||||||
* @brief Updates the boarding window.
|
* @brief Updates the boarding window.
|
||||||
*/
|
*/
|
||||||
static void board_update(unsigned int wdw) {
|
static void board_update(unsigned int wdw) {
|
||||||
int i, len;
|
int i, j;
|
||||||
char str[128], buf[32];
|
char str[PATH_MAX];
|
||||||
char cred[10];
|
char cred[10];
|
||||||
Pilot* p;
|
Pilot* p;
|
||||||
|
|
||||||
p = pilot_get(player->target);
|
p = pilot_get(player->target);
|
||||||
|
j = 0;
|
||||||
|
|
||||||
/* Credits. */
|
/* Credits. */
|
||||||
credits2str(cred, p->credits, 2);
|
credits2str(cred, p->credits, 2);
|
||||||
|
|
||||||
snprintf(str, 128, "%s\n", cred);
|
j += snprintf(&str[j], PATH_MAX-j, "%s\n", cred);
|
||||||
len = strlen(str);
|
|
||||||
|
|
||||||
/* Commodities. */
|
/* Commodities. */
|
||||||
if(p->ncommodities == 0) {
|
if(p->ncommodities == 0)
|
||||||
strncat(str, "none\n", 128-len);
|
j += snprintf(&str[j], PATH_MAX-j, "none\n");
|
||||||
len = strlen(str);
|
else {
|
||||||
} else {
|
for(i = 0; i < p->ncommodities; i++)
|
||||||
for(i = 0; i < p->ncommodities; i++) {
|
j += snprintf(&str[j], PATH_MAX-j,
|
||||||
snprintf(buf, 32,
|
|
||||||
"%d %s\n",
|
"%d %s\n",
|
||||||
p->commodities[i].quantity, p->commodities[i].commodity->name);
|
p->commodities[i].quantity, p->commodities[i].commodity->name);
|
||||||
strncat(str, buf, 128-len);
|
|
||||||
len = strlen(str);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Fuel. */
|
||||||
if(p->fuel <= 0.)
|
if(p->fuel <= 0.)
|
||||||
strncat(str, "none", 128-len);
|
j += snprintf(&str[j], PATH_MAX-j, "none\n");
|
||||||
else {
|
else
|
||||||
snprintf(buf, 32, "%.0f Units", p->fuel);
|
j += snprintf(&str[j], PATH_MAX-j, "%.0f Units\n", p->fuel);
|
||||||
strncat(str, buf, 128-len);
|
|
||||||
}
|
|
||||||
len = strlen(str);
|
|
||||||
|
|
||||||
window_modifyText(wdw, "txtData", str);
|
window_modifyText(wdw, "txtData", str);
|
||||||
}
|
}
|
||||||
|
48
src/map.c
48
src/map.c
@ -152,7 +152,8 @@ static void map_update(unsigned int wid) {
|
|||||||
StarSystem* sys;
|
StarSystem* sys;
|
||||||
int f, y, h, standing, nstanding;
|
int f, y, h, standing, nstanding;
|
||||||
unsigned int services;
|
unsigned int services;
|
||||||
char buf[128];
|
char buf[PATH_MAX];
|
||||||
|
int p;
|
||||||
|
|
||||||
/* Needs map to update. */
|
/* Needs map to update. */
|
||||||
if(!map_isOpen())
|
if(!map_isOpen())
|
||||||
@ -230,12 +231,12 @@ static void map_update(unsigned int wid) {
|
|||||||
strncpy(buf, "None", 128);
|
strncpy(buf, "None", 128);
|
||||||
window_modifyText(wid, "txtPlanets", buf);
|
window_modifyText(wid, "txtPlanets", buf);
|
||||||
} else {
|
} else {
|
||||||
|
p = 0;
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
if(sys->nplanets > 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++) {
|
for(i = 1; i < sys->nplanets; i++) {
|
||||||
strcat(buf, ",\n");
|
p += snprintf(&buf[p], PATH_MAX-p, ",\n%s", sys->planets[i]->name);
|
||||||
strcat(buf, sys->planets[i]->name);
|
|
||||||
}
|
}
|
||||||
window_modifyText(wid, "txtPlanets", buf);
|
window_modifyText(wid, "txtPlanets", buf);
|
||||||
}
|
}
|
||||||
@ -252,34 +253,53 @@ static void map_update(unsigned int wid) {
|
|||||||
for(i = 0; i < sys->nplanets; i++)
|
for(i = 0; i < sys->nplanets; i++)
|
||||||
services |= sys->planets[i]->services;
|
services |= sys->planets[i]->services;
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
|
p = 0;
|
||||||
/*snprintf(buf, sizeof(buf), "%f\n", sys->prices[0]); */
|
/*snprintf(buf, sizeof(buf), "%f\n", sys->prices[0]); */
|
||||||
if(services & PLANET_SERVICE_COMMODITY)
|
if(services & PLANET_SERVICE_COMMODITY)
|
||||||
strcat(buf, "Commodity\n");
|
p += snprintf(&buf[p], PATH_MAX-p, "Commodity\n");
|
||||||
if(services & PLANET_SERVICE_OUTFITS)
|
if(services & PLANET_SERVICE_OUTFITS)
|
||||||
strcat(buf, "Outfits\n");
|
p += snprintf(&buf[p], PATH_MAX-p, "Outfits\n");
|
||||||
if(services & PLANET_SERVICE_SHIPYARD)
|
if(services & PLANET_SERVICE_SHIPYARD)
|
||||||
strcat(buf, "Shipyard\n");
|
p += snprintf(&buf[p], PATH_MAX-p, "Shipyard\n");
|
||||||
if(buf[0] == '\0')
|
if(buf[0] == '\0')
|
||||||
strcat(buf, "None");
|
p += snprintf(&buf[p], PATH_MAX-p, "None");
|
||||||
window_modifyText(wid, "txtServices", buf);
|
window_modifyText(wid, "txtServices", buf);
|
||||||
|
|
||||||
/* System status. */
|
/* System status. */
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
|
p = 0;
|
||||||
|
|
||||||
|
/* Nebulae. */
|
||||||
if(sys->nebu_density > 0.) { /* Has nebulae. */
|
if(sys->nebu_density > 0.) { /* Has nebulae. */
|
||||||
/* Volatility. */
|
/* Volatility. */
|
||||||
if(sys->nebu_volatility > 700.)
|
if(sys->nebu_volatility > 700.)
|
||||||
strcat(buf, " Volatile");
|
p += snprintf(&buf[p], PATH_MAX-p, " Volatile");
|
||||||
else if(sys->nebu_volatility > 300.)
|
else if(sys->nebu_volatility > 300.)
|
||||||
strcat(buf, " Dangerous");
|
p += snprintf(&buf[p], PATH_MAX-p, " Dangerous");
|
||||||
else if(sys->nebu_volatility > 0.)
|
else if(sys->nebu_volatility > 0.)
|
||||||
strcat(buf, " Unstable");
|
p += snprintf(&buf[p], PATH_MAX-p, " Unstable");
|
||||||
|
|
||||||
/* Density */
|
/* Density */
|
||||||
if(sys->nebu_density > 700.)
|
if(sys->nebu_density > 700.)
|
||||||
strcat(buf, " Dense");
|
p += snprintf(&buf[p], PATH_MAX-p, " Dense");
|
||||||
else if(sys->nebu_density < 300.)
|
else if(sys->nebu_density < 300.)
|
||||||
strcat(buf, " Light");
|
p += snprintf(&buf[p], PATH_MAX-p, " Light");
|
||||||
strcat(buf, " Nebulae");
|
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);
|
window_modifyText(wid, "txtSystemStatus", buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
21
src/pilot.c
21
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. */
|
/* Return all the outfits in a nice text form. */
|
||||||
char* pilot_getOutfits(Pilot* pilot) {
|
char* pilot_getOutfits(Pilot* pilot) {
|
||||||
int i;
|
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';
|
buf[0] = '\0';
|
||||||
|
p = 0;
|
||||||
/* First outfit. */
|
/* First outfit. */
|
||||||
if(pilot->noutfits > 0)
|
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);
|
pilot->outfits[0].quantity, pilot->outfits[0].outfit->name);
|
||||||
else
|
else
|
||||||
snprintf(str, 1024, "None");
|
p += snprintf(&buf[p], len-p, "None");
|
||||||
|
|
||||||
/* Rest of the outfits. */
|
/* Rest of the outfits. */
|
||||||
for(i = 1; i < pilot->noutfits; i++) {
|
for(i = 1; i < pilot->noutfits; i++)
|
||||||
snprintf(buf, 64, ", %dx %s",
|
p += snprintf(&buf[p], len-p, ", %dx %s",
|
||||||
pilot->outfits[i].quantity, pilot->outfits[i].outfit->name);
|
pilot->outfits[i].quantity, pilot->outfits[i].outfit->name);
|
||||||
strcat(str, buf);
|
|
||||||
}
|
return buf;
|
||||||
return str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Recalculate the pilot's stats based on her outfits. */
|
/* Recalculate the pilot's stats based on her outfits. */
|
||||||
|
Loading…
Reference in New Issue
Block a user