CID 182344: Integer handling issues

This commit is contained in:
Enno Rehling 2018-01-25 15:38:55 +01:00
parent 5fb2283d7b
commit 495c45391d

View file

@ -539,7 +539,6 @@ static int sp_summon_familiar(castorder * co)
const race *rc; const race *rc;
int sk; int sk;
int dh, dh1; int dh, dh1;
int bytes;
message *msg; message *msg;
char zText[2048], *bufp = zText; char zText[2048], *bufp = zText;
size_t size = sizeof(zText) - 1; size_t size = sizeof(zText) - 1;
@ -591,25 +590,25 @@ static int sp_summon_familiar(castorder * co)
for (sk = 0; sk < MAXSKILLS; sk++) { for (sk = 0; sk < MAXSKILLS; sk++) {
if (skill_enabled(sk) && rc->bonus[sk] > -5) { if (skill_enabled(sk) && rc->bonus[sk] > -5) {
size_t bytes;
dh--; dh--;
if (dh1 == 0) { if (dh1 == 0) {
dh1 = 1; dh1 = 1;
} }
else { else {
if (dh == 0) { if (dh == 0) {
bytes = (int) str_strlcpy(bufp, (const char *)LOC(mage->faction->locale, bytes = str_strlcpy(bufp, (const char *)LOC(mage->faction->locale,
"list_and"), size); "list_and"), size);
} }
else { else {
bytes = (int)str_strlcpy(bufp, (const char *)", ", size); bytes = str_strlcpy(bufp, (const char *)", ", size);
} }
assert(bytes >= 0); assert(bytes >= 0 && bytes <= INT_MAX);
BUFFER_STRCAT(bufp, size, bytes); BUFFER_STRCAT(bufp, size, bytes);
} }
bytes = bytes = str_strlcpy(bufp, skillname((skill_t)sk, mage->faction->locale),
str_strlcpy(bufp, (const char *)skillname((skill_t)sk, mage->faction->locale),
size); size);
assert(bytes <= INT_MAX); assert(bytes >= 0 && bytes <= INT_MAX);
BUFFER_STRCAT(bufp, size, (int)bytes); BUFFER_STRCAT(bufp, size, (int)bytes);
} }
} }