============
Cbuf_LinkString
-Copies a command string into a buffer node
+Copies a command string into a buffer node.
+The input should not be null-terminated, the output will be.
============
*/
static void Cbuf_LinkString(cmd_state_t *cmd, llist_t *head, cmd_input_t *existing, const char *text, qbool leavepending, unsigned int cmdsize)
}
cbuf->size += cmdsize;
- dp_strlcpy(&node->text[offset], text, cmdsize + 1); // always sets the last char to \0
+ dp_ustr2stp(&node->text[offset], node->length + 1, text, cmdsize);
//Con_Printf("^5Cbuf_LinkString(): %s `^7%s^5`\n", node->pending ? "append" : "new", &node->text[offset]);
node->pending = leavepending;
}
llist_t list;
cmd_state_t *source;
vec_t delay;
- size_t size;
- size_t length;
+ size_t size; ///< excludes \0 terminator
+ size_t length; ///< excludes \0 terminator
char *text;
qbool pending;
} cmd_input_t;
{
static char copybuf[MAX_INPUTLINE]; // client only
con_lineinfo_t *l = &CONBUFFER_LINES(buf, i);
- size_t sz = l->len+1 > sizeof(copybuf) ? sizeof(copybuf) : l->len+1;
- dp_strlcpy(copybuf, l->start, sz);
+
+ dp_ustr2stp(copybuf, sizeof(copybuf), l->start, l->len);
return copybuf;
}
space = strchr(line + 1, ' ');
if(space && pos == (space - line) + 1)
{
- dp_strlcpy(command, line + 1, min(sizeof(command), (unsigned int)(space - line)));
+ // adding 1 to line drops the leading ]
+ dp_ustr2stp(command, sizeof(command), line + 1, space - (line + 1));
patterns = Cvar_VariableString(cmd->cvars, va(vabuf, sizeof(vabuf), "con_completion_%s", command), CF_CLIENT | CF_SERVER); // TODO maybe use a better place for this?
if(patterns && !*patterns)
// prevseparator points past the '/' right before the wildcard and nextseparator at the one following it (or at the end of the string)
// copy everything up except nextseperator
- dp_strlcpy(subpattern, pattern, min(sizeof(subpattern), (size_t) (nextseparator - pattern + 1)));
+ dp_ustr2stp(subpattern, sizeof(subpattern), pattern, nextseparator - pattern);
// find the last '/' before the wildcard
prevseparator = strrchr( subpattern, '/' );
if (!prevseparator)
prevseparator++;
// copy everything from start to the previous including the '/' (before the wildcard)
// everything up to start is already included in the path of matchedSet's entries
- dp_strlcpy(subpath, start, min(sizeof(subpath), (size_t) ((prevseparator - subpattern) - (start - pattern) + 1)));
+ dp_ustr2stp(subpath, sizeof(subpath), start, (prevseparator - subpattern) - (start - pattern));
// for each entry in matchedSet try to open the subdirectories specified in subpath
for( dirlistindex = 0 ; dirlistindex < matchedSet.numstrings ; dirlistindex++ ) {