AGI: Rewrote cmdVersion() to use Common::String

This simplifies the code and avoids heap corruption because of the long
version string
This commit is contained in:
Filippos Karapetis 2011-09-26 15:15:39 +03:00
parent cf071732b1
commit 397b4968d9

View file

@ -1259,7 +1259,6 @@ void cmdSetMenuItem(AgiGame *state, uint8 *p) {
} }
void cmdVersion(AgiGame *state, uint8 *p) { void cmdVersion(AgiGame *state, uint8 *p) {
char verMsg[64];
char ver2Msg[] = char ver2Msg[] =
"\n" "\n"
" \n\n" " \n\n"
@ -1269,33 +1268,17 @@ void cmdVersion(AgiGame *state, uint8 *p) {
" \n\n" " \n\n"
" Emulating AGI v%x.002.%03x\n"; " Emulating AGI v%x.002.%03x\n";
// no Sierra as it wraps textbox // no Sierra as it wraps textbox
char *r, *q;
int ver, maj, min;
char msg[256];
int gap;
int len;
sprintf(verMsg, TITLE " v%s", gScummVMVersion); Common::String verMsg = TITLE " v%s";
ver = getVersion(); int ver = getVersion();
maj = (ver >> 12) & 0xf; int maj = (ver >> 12) & 0xf;
min = ver & 0xfff; int min = ver & 0xfff;
q = maj == 2 ? ver2Msg : ver3Msg; verMsg += (maj == 2 ? ver2Msg : ver3Msg);
r = strchr(q + 1, '\n'); verMsg = Common::String::format(verMsg.c_str(), gScummVMVersion, maj, min);
// insert our version into the other version state->_vm->messageBox(verMsg.c_str());
len = strlen(verMsg);
gap = r - q;
if (gap < 0)
gap = 0;
else
gap = (gap - len) / 2;
strncpy(q + 1 + gap, verMsg, strlen(verMsg));
sprintf(msg, q, maj, min);
state->_vm->messageBox(msg);
} }
void cmdConfigureScreen(AgiGame *state, uint8 *p) { void cmdConfigureScreen(AgiGame *state, uint8 *p) {