diff options
author | Craig Tiller <craig.tiller@gmail.com> | 2015-06-23 16:26:18 -0700 |
---|---|---|
committer | Craig Tiller <craig.tiller@gmail.com> | 2015-06-23 16:26:18 -0700 |
commit | 009886cf79bd4bf53049633ef7797eb63be30b68 (patch) | |
tree | acf2de7539d7b49cb35f174c25100a4d6b644d23 /src/core/support/slice.c | |
parent | af691804781f4e546c806b98ca8b05e2370e61f8 (diff) | |
parent | 6b4fc31f08b9a61a90262379072cffea0bc39795 (diff) |
Merge github.com:grpc/grpc into that-which-we-call-a-rose
Conflicts:
gRPC.podspec
tools/doxygen/Doxyfile.core.internal
Diffstat (limited to 'src/core/support/slice.c')
-rw-r--r-- | src/core/support/slice.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/core/support/slice.c b/src/core/support/slice.c index 4cff029286..a2d62fc1e5 100644 --- a/src/core/support/slice.c +++ b/src/core/support/slice.c @@ -194,7 +194,7 @@ gpr_slice gpr_slice_malloc(size_t length) { } else { /* small slice: just inline the data */ slice.refcount = NULL; - slice.data.inlined.length = length; + slice.data.inlined.length = (gpr_uint8)length; } return slice; } @@ -202,11 +202,11 @@ gpr_slice gpr_slice_malloc(size_t length) { gpr_slice gpr_slice_sub_no_ref(gpr_slice source, size_t begin, size_t end) { gpr_slice subset; + GPR_ASSERT(end >= begin); + if (source.refcount) { /* Enforce preconditions */ - GPR_ASSERT(source.data.refcounted.length >= begin); GPR_ASSERT(source.data.refcounted.length >= end); - GPR_ASSERT(end >= begin); /* Build the result */ subset.refcount = source.refcount; @@ -214,8 +214,10 @@ gpr_slice gpr_slice_sub_no_ref(gpr_slice source, size_t begin, size_t end) { subset.data.refcounted.bytes = source.data.refcounted.bytes + begin; subset.data.refcounted.length = end - begin; } else { + /* Enforce preconditions */ + GPR_ASSERT(source.data.inlined.length >= end); subset.refcount = NULL; - subset.data.inlined.length = end - begin; + subset.data.inlined.length = (gpr_uint8)(end - begin); memcpy(subset.data.inlined.bytes, source.data.inlined.bytes + begin, end - begin); } @@ -227,7 +229,7 @@ gpr_slice gpr_slice_sub(gpr_slice source, size_t begin, size_t end) { if (end - begin <= sizeof(subset.data.inlined.bytes)) { subset.refcount = NULL; - subset.data.inlined.length = end - begin; + subset.data.inlined.length = (gpr_uint8)(end - begin); memcpy(subset.data.inlined.bytes, GPR_SLICE_START_PTR(source) + begin, end - begin); } else { @@ -245,17 +247,17 @@ gpr_slice gpr_slice_split_tail(gpr_slice *source, size_t split) { /* inlined data, copy it out */ GPR_ASSERT(source->data.inlined.length >= split); tail.refcount = NULL; - tail.data.inlined.length = source->data.inlined.length - split; + tail.data.inlined.length = (gpr_uint8)(source->data.inlined.length - split); memcpy(tail.data.inlined.bytes, source->data.inlined.bytes + split, tail.data.inlined.length); - source->data.inlined.length = split; + source->data.inlined.length = (gpr_uint8)split; } else { size_t tail_length = source->data.refcounted.length - split; GPR_ASSERT(source->data.refcounted.length >= split); if (tail_length < sizeof(tail.data.inlined.bytes)) { /* Copy out the bytes - it'll be cheaper than refcounting */ tail.refcount = NULL; - tail.data.inlined.length = tail_length; + tail.data.inlined.length = (gpr_uint8)tail_length; memcpy(tail.data.inlined.bytes, source->data.refcounted.bytes + split, tail_length); } else { @@ -280,16 +282,16 @@ gpr_slice gpr_slice_split_head(gpr_slice *source, size_t split) { GPR_ASSERT(source->data.inlined.length >= split); head.refcount = NULL; - head.data.inlined.length = split; + head.data.inlined.length = (gpr_uint8)split; memcpy(head.data.inlined.bytes, source->data.inlined.bytes, split); - source->data.inlined.length -= split; + source->data.inlined.length = (gpr_uint8)(source->data.inlined.length - split); memmove(source->data.inlined.bytes, source->data.inlined.bytes + split, source->data.inlined.length); } else if (split < sizeof(head.data.inlined.bytes)) { GPR_ASSERT(source->data.refcounted.length >= split); head.refcount = NULL; - head.data.inlined.length = split; + head.data.inlined.length = (gpr_uint8)split; memcpy(head.data.inlined.bytes, source->data.refcounted.bytes, split); source->data.refcounted.bytes += split; source->data.refcounted.length -= split; @@ -311,7 +313,7 @@ gpr_slice gpr_slice_split_head(gpr_slice *source, size_t split) { } int gpr_slice_cmp(gpr_slice a, gpr_slice b) { - int d = GPR_SLICE_LENGTH(a) - GPR_SLICE_LENGTH(b); + int d = (int)(GPR_SLICE_LENGTH(a) - GPR_SLICE_LENGTH(b)); if (d != 0) return d; return memcmp(GPR_SLICE_START_PTR(a), GPR_SLICE_START_PTR(b), GPR_SLICE_LENGTH(a)); @@ -319,7 +321,7 @@ int gpr_slice_cmp(gpr_slice a, gpr_slice b) { int gpr_slice_str_cmp(gpr_slice a, const char *b) { size_t b_length = strlen(b); - int d = GPR_SLICE_LENGTH(a) - b_length; + int d = (int)(GPR_SLICE_LENGTH(a) - b_length); if (d != 0) return d; return memcmp(GPR_SLICE_START_PTR(a), b, b_length); } |