tty's compress_str(), core's dat/keyhelp

Rewrite 3.6.1's compress_str() to avoid peeking past the end of the
input string.  This should eliminate the reported valgrind complaint.
The problem was noticed for post-3.6.0 code introduced [by me...] last
June, but it looks like it was present in the old code too.

Also, fix the wording in the paragraph about NUL in the keyhelp text.

tty_putstr() always passes non-message window text through compress_str(),
clobbering usage of two spaces to separate sentences.  putstr()'s caller
ought to have more control over that (possibly via its hardly ever used
'attribute' arg?).
This commit is contained in:
PatR
2016-12-20 12:43:35 -08:00
parent f4632732ac
commit d606b2a8ff
2 changed files with 21 additions and 18 deletions

View File

@@ -14,12 +14,12 @@
is reporting the wrong character but will be operating correctly if
it describes ^J when you type ^M.
A NUL character, typed as ^<space> on some keyboards, ^@ on others,
and maybe not typeable at all on yet others. It is not used as a
command, and will be converted into ESC before reaching 'whatdoes'.
Unlike ^M, this transformation is performed by NetHack itself.
But like ^M, if you type NUL and get feedback about ESC, the
situation is expected.
A NUL character, which is typed as ^<space> on some keyboards,
^@ on others, and maybe not typeable at all on yet others, is not
used as a command, and will be converted into ESC before reaching
'whatdoes'. Unlike ^M, this transformation is performed within
NetHack. But like ^M, if you type NUL and get feedback about ESC,
the situation is expected.
ESC itself is a synonym for ^[, and is another source of oddity.
Various function keys, including cursor arrow keys, may transmit

View File

@@ -2448,19 +2448,22 @@ const char *str;
topline wrapping converts space at wrap point into newline,
we reverse that here */
if ((int) strlen(str) >= CO || index(str, '\n')) {
register const char *bp0 = str;
char c, nxtc, *bp1 = cbuf, *endbp1 = &cbuf[sizeof cbuf - 1];
const char *in_str = str;
char c, *outstr = cbuf, *outend = &cbuf[sizeof cbuf - 1];
boolean was_space = TRUE; /* True discards all leading spaces;
False would retain one if present */
cbuf[0] = cbuf[sizeof cbuf - 1] = '\0'; /* superfluous */
nxtc = (*bp0 == '\n') ? ' ' : *bp0;
do {
c = nxtc;
nxtc = bp0[1];
if (nxtc == '\n')
nxtc = ' ';
if (c != ' ' || nxtc != ' ')
*bp1++ = c;
} while (*bp0++ && bp1 < endbp1);
while ((c = *in_str++) != '\0' && outstr < outend) {
if (c == '\n')
c = ' ';
if (was_space && c == ' ')
continue;
*outstr++ = c;
was_space = (c == ' ');
}
if ((was_space && outstr > cbuf) || outstr == outend)
--outstr; /* remove trailing space or make room for terminator */
*outstr = '\0';
str = cbuf;
}
return str;