Reduce the ephemeral nature of str_mid

When the substring is the tail of the supplied string, return a
"pointer" to within the supplied string rather than a new "return"
string. This means that tail-end substrings of string constants are
themselves constants.
This commit is contained in:
Bill Currie 2020-02-19 14:40:01 +09:00
parent b00c866c4e
commit 2db5d04e3f

View file

@ -112,6 +112,10 @@ bi_str_mid (progs_t *pr)
end = size;
if (pos < 0 || pos >= size || end <= pos)
return;
if (end == size) {
R_STRING (pr) = str + pos - pr->pr_strings;
return;
}
temp = alloca (end - pos + 1);
strncpy (temp, str + pos, end - pos);
temp[end - pos] = 0;