mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 23:32:09 +00:00
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:
parent
b00c866c4e
commit
2db5d04e3f
1 changed files with 4 additions and 0 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue