cbfstool: Simplify the common buffer_splice() function's interface
Previously, this function allowed one to pass a size of 0 in order to indicate that the entire buffer should be copied. However, the semantics of calling it this way were non-obvious: The desired behavior was clear when the offset was also 0, but what was the expected outcome when the offset was nonzero, since carrying over the original size in this case would be an error? In fact, it turns out that it always ignored the provided offset when the size was zero. This commit eliminates all special handling of 0; thus, the resulting buffer is exactly as large as requested, even if it's degenerate. Since the only consumer that actually called the function with a size of 0 was buffer_clone(), no other files required changes. Change-Id: I1baa5dbaa7ba5bd746e8b1e08816335183bd5d2d Signed-off-by: Sol Boucher <solb@chromium.org> Reviewed-on: http://review.coreboot.org/10132 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
This commit is contained in:
parent
5bad3954bf
commit
1a3349ffd1
|
@ -86,23 +86,19 @@ static inline void buffer_init(struct buffer *b, char *name, void *data,
|
||||||
b->size = size;
|
b->size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Splice a buffer into another buffer. If size is zero the entire buffer
|
/* Splice a buffer into another buffer. Note that it's up to the caller to
|
||||||
* is spliced while if size is non-zero the buffer is spliced starting at
|
* bounds check the offset and size. */
|
||||||
* offset for size bytes. Note that it's up to caller to bounds check.
|
|
||||||
*/
|
|
||||||
static inline void buffer_splice(struct buffer *dest, const struct buffer *src,
|
static inline void buffer_splice(struct buffer *dest, const struct buffer *src,
|
||||||
size_t offset, size_t size)
|
size_t offset, size_t size)
|
||||||
{
|
{
|
||||||
buffer_init(dest, src->name, src->data, src->size);
|
buffer_init(dest, src->name, src->data, src->size);
|
||||||
if (size != 0) {
|
dest->data += offset;
|
||||||
dest->data += offset;
|
buffer_set_size(dest, size);
|
||||||
buffer_set_size(dest, size);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void buffer_clone(struct buffer *dest, const struct buffer *src)
|
static inline void buffer_clone(struct buffer *dest, const struct buffer *src)
|
||||||
{
|
{
|
||||||
buffer_splice(dest, src, 0, 0);
|
buffer_splice(dest, src, 0, src->size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void buffer_seek(struct buffer *b, size_t size)
|
static inline void buffer_seek(struct buffer *b, size_t size)
|
||||||
|
|
Loading…
Reference in New Issue