iova_slice error detect
parent
a46945b6cd
commit
23ff87dea0
22
src/sf_iov.c
22
src/sf_iov.c
|
|
@ -52,6 +52,7 @@ int sf_iova_consume(SFDynamicIOVArray *iova, const int consume_len)
|
|||
iova->iov = iob;
|
||||
if (iova->cnt == 0) {
|
||||
struct iovec *last;
|
||||
|
||||
last = iob - 1;
|
||||
last->iov_base = (char *)last->iov_base + last->iov_len;
|
||||
last->iov_len = 0;
|
||||
|
|
@ -68,7 +69,7 @@ int sf_iova_consume(SFDynamicIOVArray *iova, const int consume_len)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static inline void iova_slice(SFDynamicIOVArray *iova, const int slice_len)
|
||||
static inline int iova_slice(SFDynamicIOVArray *iova, const int slice_len)
|
||||
{
|
||||
struct iovec *iob;
|
||||
struct iovec *end;
|
||||
|
|
@ -88,7 +89,16 @@ static inline void iova_slice(SFDynamicIOVArray *iova, const int slice_len)
|
|||
}
|
||||
}
|
||||
|
||||
iova->cnt = (iob - iova->iov) + 1;
|
||||
if (iob < end) {
|
||||
iova->cnt = (iob - iova->iov) + 1;
|
||||
return 0;
|
||||
} else {
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"iov remain bytes: %d < slice length: %d",
|
||||
__LINE__, bytes, slice_len);
|
||||
iova->cnt = 0;
|
||||
return EOVERFLOW;
|
||||
}
|
||||
}
|
||||
|
||||
int sf_iova_first_slice(SFDynamicIOVArray *iova, const int slice_len)
|
||||
|
|
@ -99,15 +109,14 @@ int sf_iova_first_slice(SFDynamicIOVArray *iova, const int slice_len)
|
|||
return result;
|
||||
}
|
||||
|
||||
iova_slice(iova, slice_len);
|
||||
return 0;
|
||||
return iova_slice(iova, slice_len);
|
||||
}
|
||||
|
||||
int sf_iova_next_slice(SFDynamicIOVArray *iova,
|
||||
const int consume_len, const int slice_len)
|
||||
{
|
||||
struct iovec *last;
|
||||
struct iovec *origin;
|
||||
const struct iovec *origin;
|
||||
int remain_len;
|
||||
int result;
|
||||
|
||||
|
|
@ -126,6 +135,5 @@ int sf_iova_next_slice(SFDynamicIOVArray *iova,
|
|||
}
|
||||
}
|
||||
|
||||
iova_slice(iova, slice_len);
|
||||
return 0;
|
||||
return iova_slice(iova, slice_len);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ typedef struct sf_dynamic_iov_array {
|
|||
struct iovec *ptr;
|
||||
|
||||
struct {
|
||||
struct iovec *iov;
|
||||
const struct iovec *iov;
|
||||
int cnt;
|
||||
} input;
|
||||
|
||||
|
|
@ -39,7 +39,7 @@ typedef struct sf_dynamic_iov_array {
|
|||
(iova).cnt = (iova).input.cnt = _cnt
|
||||
|
||||
#define sf_iova_destroy(iova) \
|
||||
if ((iova).iov != (iova).input.iov && \
|
||||
if ((iova).iov != (struct iovec *)(iova).input.iov && \
|
||||
(iova).ptr != (iova).holder) \
|
||||
free((iova).ptr)
|
||||
|
||||
|
|
@ -49,7 +49,7 @@ extern "C" {
|
|||
|
||||
static inline int sf_iova_check_alloc(SFDynamicIOVArray *iova)
|
||||
{
|
||||
if (iova->iov == iova->input.iov) {
|
||||
if (iova->iov == (struct iovec *)iova->input.iov) {
|
||||
if (iova->input.cnt <= SF_IOV_FIXED_SIZE) {
|
||||
iova->ptr = iova->holder;
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue