mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-02-22 10:10:54 +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)
|
strbuf strbuf_puts(strbuf sb, const char *text)
|
||||||
{
|
{
|
||||||
if (sb->start && (!sb->end || sb->current < sb->end)) {
|
if (sb->start) {
|
||||||
register size_t n = sb->end ? sb->end - sb->current : -1;
|
if (!sb->end) {
|
||||||
while (n-- && (*sb->current = *text)) {
|
while ((*sb->current = *text)) {
|
||||||
++sb->current;
|
++sb->current;
|
||||||
++text;
|
++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++)
|
while (*text++)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user