Merge branch 'rs/strbuf-setlen-assert'
* rs/strbuf-setlen-assert: strbuf: clarify assertion in strbuf_setlen()
This commit is contained in:
commit
5ae6f5ca2f
7
strbuf.h
7
strbuf.h
@ -3,8 +3,6 @@
|
|||||||
|
|
||||||
/* See Documentation/technical/api-strbuf.txt */
|
/* See Documentation/technical/api-strbuf.txt */
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
extern char strbuf_slopbuf[];
|
extern char strbuf_slopbuf[];
|
||||||
struct strbuf {
|
struct strbuf {
|
||||||
size_t alloc;
|
size_t alloc;
|
||||||
@ -33,9 +31,8 @@ static inline size_t strbuf_avail(const struct strbuf *sb) {
|
|||||||
extern void strbuf_grow(struct strbuf *, size_t);
|
extern void strbuf_grow(struct strbuf *, size_t);
|
||||||
|
|
||||||
static inline void strbuf_setlen(struct strbuf *sb, size_t len) {
|
static inline void strbuf_setlen(struct strbuf *sb, size_t len) {
|
||||||
if (!sb->alloc)
|
if (len > (sb->alloc ? sb->alloc - 1 : 0))
|
||||||
strbuf_grow(sb, 0);
|
die("BUG: strbuf_setlen() beyond buffer");
|
||||||
assert(len < sb->alloc);
|
|
||||||
sb->len = len;
|
sb->len = len;
|
||||||
sb->buf[len] = '\0';
|
sb->buf[len] = '\0';
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user