MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / csv_increase_buffer

Function csv_increase_buffer

libCacheSim/traceReader/generalReader/libcsv.c:234–263  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

232}
233
234static int csv_increase_buffer(struct csv_parser *p) {
235 /* Increase the size of the entry buffer. Attempt to increase size by
236 * p->blk_size, if this is larger than SIZE_MAX try to increase current
237 * buffer size to SIZE_MAX. If allocation fails, try to allocate halve
238 * the size and try again until successful or increment size is zero.
239 */
240
241 size_t to_add = p->blk_size;
242 void *vp;
243
244 if (p->entry_size >= SIZE_MAX - to_add) to_add = SIZE_MAX - p->entry_size;
245
246 if (!to_add) {
247 p->status = CSV_ETOOBIG;
248 return -1;
249 }
250
251 while ((vp = p->realloc_func(p->entry_buf, p->entry_size + to_add)) == NULL) {
252 to_add /= 2;
253 if (!to_add) {
254 p->status = CSV_ENOMEM;
255 return -1;
256 }
257 }
258
259 /* Update entry buffer pointer and entry_size if successful */
260 p->entry_buf = vp;
261 p->entry_size += to_add;
262 return 0;
263}
264
265size_t csv_parse(struct csv_parser *p, const void *s, size_t len,
266 void (*cb1)(void *, size_t, void *),

Callers 1

csv_parseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected