[coreboot-gerrit] Patch set updated for coreboot: 3ad3413 cbfstool: Simplify the common buffer_splice() function's interface

Sol Boucher (solb@chromium.org) gerrit at coreboot.org
Fri May 8 04:43:19 CEST 2015


Sol Boucher (solb at chromium.org) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/10132

-gerrit

commit 3ad3413efc3a2e4fe4d79a244d3f0f2a20018870
Author: Sol Boucher <solb at chromium.org>
Date:   Tue May 5 18:25:18 2015 -0700

    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 at chromium.org>
---
 util/cbfstool/common.h | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/util/cbfstool/common.h b/util/cbfstool/common.h
index f364ea1..78ec40a 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)



More information about the coreboot-gerrit mailing list