MCPcopy Create free account
hub / github.com/acl-dev/acl / vstring_extend

Function vstring_extend

lib_acl/src/stdlib/acl_vstring.c:37–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35/* vstring_extend - variable-length string buffer extension policy */
36
37static int vstring_extend(ACL_VBUF *bp, ssize_t incr)
38{
39 const char *myname = "vstring_extend";
40 ssize_t used = (ssize_t) (bp->ptr - bp->data), new_len;
41 ACL_VSTRING *vp = (ACL_VSTRING *) bp;
42
43 if (vp->maxlen > 0 && (ssize_t) ACL_VSTRING_LEN(vp) >= vp->maxlen) {
44 ACL_VSTRING_AT_OFFSET(vp, vp->maxlen - 1);
45 ACL_VSTRING_TERMINATE(vp);
46 acl_msg_warn("%s(%d), %s: overflow maxlen: %ld, %ld",
47 __FILE__, __LINE__, myname, (long) vp->maxlen,
48 (long) ACL_VSTRING_LEN(vp));
49 bp->flags |= ACL_VBUF_FLAG_EOF;
50 return ACL_VBUF_EOF;
51 }
52
53#ifdef ACL_WINDOWS
54 if (bp->fd == ACL_FILE_INVALID && (bp->flags & ACL_VBUF_FLAG_FIXED))
55#else
56 if (bp->fd < 0 && (bp->flags & ACL_VBUF_FLAG_FIXED))
57#endif
58 {
59 acl_msg_warn("%s(%d), %s: can't extend fixed buffer",
60 __FILE__, __LINE__, myname);
61 return ACL_VBUF_EOF;
62 }
63
64 /*
65 * Note: vp->vbuf.len is the current buffer size (both on entry and on
66 * exit of this routine). We round up the increment size to the buffer
67 * size to avoid silly little buffer increments. With really large
68 * strings we might want to abandon the length doubling strategy, and
69 * go to fixed increments.
70 */
71#ifdef INCR_NO_DOUBLE
72 /* below come from redis-server/sds.c/sdsMakeRoomFor, which can
73 * avoid memory double growing too large --- 2015.2.2, zsx
74 */
75 new_len = bp->len + incr;
76 if (new_len < MAX_PREALLOC) {
77 new_len *= 2;
78 } else {
79 new_len += MAX_PREALLOC;
80 }
81#else
82 new_len = bp->len + (bp->len > incr ? bp->len : incr);
83#endif
84
85 if (vp->maxlen > 0 && new_len > vp->maxlen) {
86 new_len = vp->maxlen;
87 }
88
89 if (vp->vbuf.flags & ACL_VBUF_FLAG_SLICE) {
90 bp->data = (unsigned char *) acl_slice_pool_realloc(__FILE__,
91 __LINE__, bp->alloc.slice, bp->data, new_len);
92 } else if (vp->vbuf.flags & ACL_VBUF_FLAG_DBUF) {
93 const unsigned char *data = bp->data;
94 bp->data = (unsigned char *)

Callers 2

acl_vstring_put_readyFunction · 0.70
acl_vstring_spaceFunction · 0.70

Calls 9

acl_msg_warnFunction · 0.85
acl_slice_pool_reallocFunction · 0.85
acl_dbuf_pool_allocFunction · 0.85
memcpyFunction · 0.85
acl_dbuf_pool_freeFunction · 0.85
acl_lseekFunction · 0.85
acl_msg_fatalFunction · 0.85
acl_last_serrorFunction · 0.85
acl_file_writeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…