path: root/util
diff options
authorSol Boucher <solb@chromium.org>2015-05-05 18:25:18 -0700
committerPatrick Georgi <pgeorgi@google.com>2015-05-08 20:25:03 +0200
commit1a3349ffd1a8b9e0e656ea9ac889ce71860864c0 (patch)
tree91e97987b4170ba415f7d390761e0550ce747eac /util
parent5bad3954bf32f83ffd85dab90797b24103fc994a (diff)
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>
Diffstat (limited to 'util')
1 files changed, 5 insertions, 9 deletions
diff --git a/util/cbfstool/common.h b/util/cbfstool/common.h
index f364ea17e..78ec40aaa 100644
--- a/util/cbfstool/common.h
+++ b/util/cbfstool/common.h
@@ -86,23 +86,19 @@ static inline void buffer_init(struct buffer *b, char *name, void *data,
b->size = size;
-/* Splice a buffer into another buffer. If size is zero the entire buffer
- * is spliced while if size is non-zero the buffer is spliced starting at
- * offset for size bytes. Note that it's up to caller to bounds check.
- */
+/* Splice a buffer into another buffer. Note that it's up to the caller to
+ * bounds check the offset and size. */
static inline void buffer_splice(struct buffer *dest, const struct buffer *src,
size_t offset, size_t size)
buffer_init(dest, src->name, src->data, src->size);
- if (size != 0) {
- dest->data += offset;
- buffer_set_size(dest, size);
- }
+ dest->data += offset;
+ buffer_set_size(dest, size);
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)