The str array need an extra element for the NUL terminator.  The previous
code didn't suffer from memory-unsafety, but winpty_snprintf truncated the
last character of the marker, and trying to write NUL to the WinXP console
didn't work.  (I suspect WinXP turned the NUL into a space, so
findSyncMarker couldn't find it later.)
This commit is contained in:
Ryan Prichard 2016-03-30 02:13:02 -05:00
parent 44848914fc
commit de9f54da29

View File

@ -839,7 +839,7 @@ void Agent::syncMarkerText(CHAR_INFO (&output)[SYNC_MARKER_LEN])
{ {
// XXX: The marker text generated here could easily collide with ordinary // XXX: The marker text generated here could easily collide with ordinary
// console output. Does it make sense to try to avoid the collision? // console output. Does it make sense to try to avoid the collision?
char str[SYNC_MARKER_LEN]; char str[SYNC_MARKER_LEN + 1];
winpty_snprintf(str, "S*Y*N*C*%08x", m_syncCounter); winpty_snprintf(str, "S*Y*N*C*%08x", m_syncCounter);
for (int i = 0; i < SYNC_MARKER_LEN; ++i) { for (int i = 0; i < SYNC_MARKER_LEN; ++i) {
output[i].Char.UnicodeChar = str[i]; output[i].Char.UnicodeChar = str[i];