M_BuildConditionSetString, M_StartMessage: Fix occasionally spurious injected newlines

This commit is contained in:
toaster 2023-03-03 15:31:36 +00:00
parent db52c22a83
commit bd54a789a2
2 changed files with 8 additions and 8 deletions

View file

@ -971,7 +971,7 @@ char *M_BuildConditionSetString(UINT8 unlockid)
size_t len = 1024, worklen; size_t len = 1024, worklen;
static char message[1024] = ""; static char message[1024] = "";
const char *work = NULL; const char *work = NULL;
size_t max = 0, start = 0, strlines = 0, i; size_t max = 0, maxatstart = 0, start = 0, i;
boolean stopasap = false; boolean stopasap = false;
message[0] = '\0'; message[0] = '\0';
@ -1038,12 +1038,13 @@ char *M_BuildConditionSetString(UINT8 unlockid)
{ {
start = i; start = i;
max += 4; max += 4;
maxatstart = max;
} }
else if (message[i] == '\n') else if (message[i] == '\n')
{ {
strlines = i;
start = 0; start = 0;
max = 0; max = 0;
maxatstart = 0;
continue; continue;
} }
else if (message[i] & 0x80) else if (message[i] & 0x80)
@ -1055,8 +1056,7 @@ char *M_BuildConditionSetString(UINT8 unlockid)
if (max >= DESCRIPTIONWIDTH && start > 0) if (max >= DESCRIPTIONWIDTH && start > 0)
{ {
message[start] = '\n'; message[start] = '\n';
max -= (start-strlines)*8; max -= maxatstart;
strlines = start;
start = 0; start = 0;
} }
} }

View file

@ -27,7 +27,7 @@ static inline size_t M_StringHeight(const char *string)
void M_StartMessage(const char *string, void *routine, menumessagetype_t itemtype) void M_StartMessage(const char *string, void *routine, menumessagetype_t itemtype)
{ {
const UINT8 pid = 0; const UINT8 pid = 0;
size_t max = 0, start = 0, strlines = 0, i; size_t max = 0, maxatstart = 0, start = 0, strlines, i;
static char *message = NULL; static char *message = NULL;
Z_Free(message); Z_Free(message);
message = Z_StrDup(string); message = Z_StrDup(string);
@ -41,12 +41,13 @@ void M_StartMessage(const char *string, void *routine, menumessagetype_t itemtyp
{ {
start = i; start = i;
max += 4; max += 4;
maxatstart = max;
} }
else if (message[i] == '\n') else if (message[i] == '\n')
{ {
strlines = i;
start = 0; start = 0;
max = 0; max = 0;
maxatstart = 0;
continue; continue;
} }
else if (message[i] & 0x80) else if (message[i] & 0x80)
@ -58,8 +59,7 @@ void M_StartMessage(const char *string, void *routine, menumessagetype_t itemtyp
if (max >= BASEVIDWIDTH && start > 0) if (max >= BASEVIDWIDTH && start > 0)
{ {
message[start] = '\n'; message[start] = '\n';
max -= (start-strlines)*8; max -= maxatstart;
strlines = start;
start = 0; start = 0;
} }
} }