aboutsummaryrefslogtreecommitdiff
path: root/src/nc-util.h
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2024-11-03 14:03:07 -0500
committerLibravatar vnugent <public@vaughnnugent.com>2024-11-03 14:03:07 -0500
commitdcc65c2cacf2261eb705ff8ac7d1a0263ced79f4 (patch)
treec898c02f7e5b081c64932ce1ab5ebde9b27bdace /src/nc-util.h
parent44044eb0fb28b774773e3284fd147c91d59d64e3 (diff)
parente0d30c1d8f407bfef05a9cc36398bb0894a96c39 (diff)
merge develop
Diffstat (limited to 'src/nc-util.h')
-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;
}