diff options
author | vnugent <public@vaughnnugent.com> | 2024-11-03 14:03:07 -0500 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2024-11-03 14:03:07 -0500 |
commit | dcc65c2cacf2261eb705ff8ac7d1a0263ced79f4 (patch) | |
tree | c898c02f7e5b081c64932ce1ab5ebde9b27bdace /src/nc-util.h | |
parent | 44044eb0fb28b774773e3284fd147c91d59d64e3 (diff) | |
parent | e0d30c1d8f407bfef05a9cc36398bb0894a96c39 (diff) |
merge develop
Diffstat (limited to 'src/nc-util.h')
-rw-r--r-- | src/nc-util.h | 42 |
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; } |