mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-19 07:20:50 +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;
|
end = size;
|
||||||
if (pos < 0 || pos >= size || end <= pos)
|
if (pos < 0 || pos >= size || end <= pos)
|
||||||
return;
|
return;
|
||||||
|
if (end == size) {
|
||||||
|
R_STRING (pr) = str + pos - pr->pr_strings;
|
||||||
|
return;
|
||||||
|
}
|
||||||
temp = alloca (end - pos + 1);
|
temp = alloca (end - pos + 1);
|
||||||
strncpy (temp, str + pos, end - pos);
|
strncpy (temp, str + pos, end - pos);
|
||||||
temp[end - pos] = 0;
|
temp[end - pos] = 0;
|
||||||
|
|
Loading…
Reference in a new issue