1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

Calculate string size within dm_pool_grow_object.

This commit is contained in:
Alasdair Kergon 2008-04-19 15:50:18 +00:00
parent 7e305eda2f
commit f44e3ff46a
6 changed files with 22 additions and 21 deletions

View File

@ -1,5 +1,6 @@
Version 1.02.26 -
=================================
Calculate string size within dm_pool_grow_object.
Version 1.02.25 - 10th April 2008
=================================

View File

@ -500,7 +500,7 @@ void dm_pool_free(struct dm_pool *p, void *ptr);
*
* for (i = 0; i < 50; i++) {
* snprintf(buffer, sizeof(buffer), "%d, ", i);
* if (!dm_pool_grow_object(mem, buffer, strlen(buffer)))
* if (!dm_pool_grow_object(mem, buffer, 0))
* goto bad;
* }
*
@ -524,6 +524,7 @@ void dm_pool_free(struct dm_pool *p, void *ptr);
* dm_pool_grow_object. Finally get your object with
* a call to dm_pool_end_object.
*
* Setting delta to 0 means it will use strlen(extra).
*/
int dm_pool_begin_object(struct dm_pool *p, size_t hint);
int dm_pool_grow_object(struct dm_pool *p, const void *extra, size_t delta);

View File

@ -668,15 +668,13 @@ static int _report_headings(struct dm_report *rh)
log_error("dm_report: Failed to generate report headings for printing");
goto bad;
}
} else if (!dm_pool_grow_object(rh->mem, heading,
strlen(heading))) {
} else if (!dm_pool_grow_object(rh->mem, heading, 0)) {
log_error("dm_report: Failed to generate report headings for printing");
goto bad;
}
if (!list_end(&rh->field_props, &fp->list))
if (!dm_pool_grow_object(rh->mem, rh->separator,
strlen(rh->separator))) {
if (!dm_pool_grow_object(rh->mem, rh->separator, 0)) {
log_error("dm_report: Failed to generate report headings for printing");
goto bad;
}
@ -803,8 +801,7 @@ int dm_report_output(struct dm_report *rh)
repstr = field->report_string;
width = field->props->width;
if (!(rh->flags & DM_REPORT_OUTPUT_ALIGNED)) {
if (!dm_pool_grow_object(rh->mem, repstr,
strlen(repstr))) {
if (!dm_pool_grow_object(rh->mem, repstr, 0)) {
log_error("dm_report: Unable to extend output line");
goto bad;
}
@ -836,8 +833,7 @@ int dm_report_output(struct dm_report *rh)
}
if (!list_end(&row->fields, fh))
if (!dm_pool_grow_object(rh->mem, rh->separator,
strlen(rh->separator))) {
if (!dm_pool_grow_object(rh->mem, rh->separator, 0)) {
log_error("dm_report: Unable to extend output line");
goto bad;
}

View File

@ -216,10 +216,10 @@ int dm_pool_begin_object(struct dm_pool *p, size_t init_size)
return 1;
}
int dm_pool_grow_object(struct dm_pool *p, const void *buffer, size_t delta)
int dm_pool_grow_object(struct dm_pool *p, const void *extra, size_t delta)
{
struct block *new;
size_t size = delta;
size_t size = delta ? : strlen(extra);
assert(p->begun);
@ -238,7 +238,7 @@ int dm_pool_grow_object(struct dm_pool *p, const void *buffer, size_t delta)
}
p->object = new;
memcpy(new->data + size - delta, buffer, delta);
memcpy(new->data + size - delta, extra, delta);
return 1;
}

View File

@ -162,14 +162,17 @@ int dm_pool_begin_object(struct dm_pool *p, size_t hint)
return 1;
}
int dm_pool_grow_object(struct dm_pool *p, const void *extra, size_t n)
int dm_pool_grow_object(struct dm_pool *p, const void *extra, size_t delta)
{
struct chunk *c = p->chunk, *nc;
if (c->end - (c->begin + p->object_len) < n) {
if (!delta)
delta = strlen(extra);
if (c->end - (c->begin + p->object_len) < delta) {
/* move into a new chunk */
if (p->object_len + n > (p->chunk_size / 2))
nc = _new_chunk(p, (p->object_len + n) * 2);
if (p->object_len + delta > (p->chunk_size / 2))
nc = _new_chunk(p, (p->object_len + delta) * 2);
else
nc = _new_chunk(p, p->chunk_size);
@ -181,8 +184,8 @@ int dm_pool_grow_object(struct dm_pool *p, const void *extra, size_t n)
c = p->chunk;
}
memcpy(c->begin + p->object_len, extra, n);
p->object_len += n;
memcpy(c->begin + p->object_len, extra, delta);
p->object_len += delta;
return 1;
}

View File

@ -1697,7 +1697,7 @@ static int _dm_tree_names(struct dm_report *rh, struct dm_pool *mem,
log_error("dm_pool_grow_object failed");
goto out_abandon;
}
if (!dm_pool_grow_object(mem, name, strlen(name))) {
if (!dm_pool_grow_object(mem, name, 0)) {
log_error("dm_pool_grow_object failed");
goto out_abandon;
}
@ -1763,7 +1763,7 @@ static int _dm_tree_parents_devs_disp(struct dm_report *rh, struct dm_pool *mem,
log_error("dm_snprintf failed");
goto out_abandon;
}
if (!dm_pool_grow_object(mem, buf, strlen(buf))) {
if (!dm_pool_grow_object(mem, buf, 0)) {
log_error("dm_pool_grow_object failed");
goto out_abandon;
}
@ -1816,7 +1816,7 @@ static int _dm_deps_disp(struct dm_report *rh, struct dm_pool *mem,
log_error("dm_snprintf failed");
goto out_abandon;
}
if (!dm_pool_grow_object(mem, buf, strlen(buf))) {
if (!dm_pool_grow_object(mem, buf, 0)) {
log_error("dm_pool_grow_object failed");
goto out_abandon;
}