MCPcopy Create free account
hub / github.com/armink/struct2json / ensure

Function ensure

struct2json/src/cJSON.c:121–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119typedef struct {char *buffer; int length; int offset; } printbuffer;
120
121static char* ensure(printbuffer *p,int needed)
122{
123 char *newbuffer;int newsize;
124 if (!p || !p->buffer) return 0;
125 needed+=p->offset;
126 if (needed<=p->length) return p->buffer+p->offset;
127
128 newsize=pow2gt(needed);
129 newbuffer=(char*)cJSON_malloc(newsize);
130 if (!newbuffer) {cJSON_free(p->buffer);p->length=0,p->buffer=0;return 0;}
131 if (newbuffer) memcpy(newbuffer,p->buffer,p->length);
132 cJSON_free(p->buffer);
133 p->length=newsize;
134 p->buffer=newbuffer;
135 return newbuffer+p->offset;
136}
137
138static int update(printbuffer *p)
139{

Callers 5

print_numberFunction · 0.85
print_string_ptrFunction · 0.85
print_valueFunction · 0.85
print_arrayFunction · 0.85
print_objectFunction · 0.85

Calls 1

pow2gtFunction · 0.85

Tested by

no test coverage detected