aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2024-11-03 00:36:23 -0400
committerLibravatar vnugent <public@vaughnnugent.com>2024-11-03 00:36:23 -0400
commit0743e9f7ca92c298beccee4fd6312a04dfc8c246 (patch)
tree503e43e0c72f809a4f315e8b4b303bfcdb4c3b4b /src
parent061eda3622664a612f4e5d5e6a02c2496fdba4f9 (diff)
allow empty span slices
Diffstat (limited to 'src')
-rw-r--r--src/nc-util.h42
1 files changed, 29 insertions, 13 deletions
diff --git a/src/nc-util.h b/src/nc-util.h
index 36d26de..02228fb 100644
--- a/src/nc-util.h
+++ b/src/nc-util.h
@@ -207,14 +207,22 @@ static _nc_fn_inline span_t ncSpanSlice(span_t span, uint32_t offset, uint32_t s
span_t slice;
DEBUG_ASSERT2(ncSpanIsValid(span), "Expected span to be non-null");
- DEBUG_ASSERT2(offset + size <= span.size, "Expected offset + size to be less than span size")
+ DEBUG_ASSERT2(offset + size <= span.size, "Expected offset + size to be less than span size");
- /* Initialize slice, offset input data by the specified offset */
- ncSpanInit(
- &slice,
- ncSpanGetOffset(span, offset),
- size
- );
+ /* If the size of the sliced span is 0 return an empty span */
+ if (size == 0)
+ {
+ ncSpanInit(&slice, NULL, 0);
+ }
+ else
+ {
+ /* Initialize slice, offset input data by the specified offset */
+ ncSpanInit(
+ &slice,
+ ncSpanGetOffset(span, offset),
+ size
+ );
+ }
return slice;
}
@@ -226,12 +234,20 @@ static _nc_fn_inline cspan_t ncSpanSliceC(cspan_t span, uint32_t offset, uint32_
DEBUG_ASSERT2(ncSpanIsValidC(span), "Expected span to be non-null");
DEBUG_ASSERT2(offset + size <= span.size, "Expected offset + size to be less than span size")
- /* Initialize slice, offset input data by the specified offset */
- ncSpanInitC(
- &slice,
- ncSpanGetOffsetC(span, offset),
- size
- );
+ /* If the size of the sliced span is 0 return an empty span */
+ if (size == 0)
+ {
+ ncSpanInitC(&slice, NULL, 0);
+ }
+ else
+ {
+ /* Initialize slice, offset input data by the specified offset */
+ ncSpanInitC(
+ &slice,
+ ncSpanGetOffsetC(span, offset),
+ size
+ );
+ }
return slice;
}