mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-02-20 09:26:37 +00:00
Fix bug in strbuf_puts(), not always appending nul
This commit is contained in:
parent
81bed5ab33
commit
8f707f4cdb
18
strbuf.c
18
strbuf.c
@ -54,11 +54,19 @@ strbuf strbuf_ncat(strbuf sb, const char *text, size_t len)
|
||||
|
||||
strbuf strbuf_puts(strbuf sb, const char *text)
|
||||
{
|
||||
if (sb->start && (!sb->end || sb->current < sb->end)) {
|
||||
register size_t n = sb->end ? sb->end - sb->current : -1;
|
||||
while (n-- && (*sb->current = *text)) {
|
||||
++sb->current;
|
||||
++text;
|
||||
if (sb->start) {
|
||||
if (!sb->end) {
|
||||
while ((*sb->current = *text)) {
|
||||
++sb->current;
|
||||
++text;
|
||||
}
|
||||
} else if (sb->current < sb->end) {
|
||||
register size_t n = sb->end - sb->current;
|
||||
while (n-- && (*sb->current = *text)) {
|
||||
++sb->current;
|
||||
++text;
|
||||
}
|
||||
*sb->current = '\0';
|
||||
}
|
||||
}
|
||||
while (*text++)
|
||||
|
Loading…
x
Reference in New Issue
Block a user