Const-correct sk_find and sk_delete_ptr.

Change-Id: I7ddc2c4827602ddac2a4aec5f9ccfa21d6c0bc40
Reviewed-on: https://boringssl-review.googlesource.com/32112
Commit-Queue: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
Reviewed-by: Adam Langley <alangley@gmail.com>
This commit is contained in:
David Benjamin 2018-09-23 15:11:41 -05:00 committed by CQ bot account: commit-bot@chromium.org
parent 892a31b5fb
commit 8d2f4b993f
3 changed files with 11 additions and 11 deletions

View File

@ -209,7 +209,7 @@ void *sk_delete(_STACK *sk, size_t where) {
return ret;
}
void *sk_delete_ptr(_STACK *sk, void *p) {
void *sk_delete_ptr(_STACK *sk, const void *p) {
if (sk == NULL) {
return NULL;
}
@ -223,7 +223,7 @@ void *sk_delete_ptr(_STACK *sk, void *p) {
return NULL;
}
int sk_find(const _STACK *sk, size_t *out_index, void *p) {
int sk_find(const _STACK *sk, size_t *out_index, const void *p) {
if (sk == NULL) {
return 0;
}
@ -247,7 +247,7 @@ int sk_find(const _STACK *sk, size_t *out_index, void *p) {
if (!sk_is_sorted(sk)) {
for (size_t i = 0; i < sk->num; i++) {
if (sk->comp((const void **)&p, (const void **)&sk->data[i]) == 0) {
if (sk->comp(&p, (const void **)&sk->data[i]) == 0) {
if (out_index) {
*out_index = i;
}
@ -270,7 +270,7 @@ int sk_find(const _STACK *sk, size_t *out_index, void *p) {
size_t idx = ((void **)r) - sk->data;
// This function always returns the first result.
while (idx > 0 &&
sk->comp((const void **)&p, (const void **)&sk->data[idx - 1]) == 0) {
sk->comp(&p, (const void **)&sk->data[idx - 1]) == 0) {
idx--;
}
if (out_index) {

View File

@ -324,7 +324,7 @@ TEST(StackTest, FindFirst) {
ASSERT_TRUE(bssl::PushToStack(sk.get(), std::move(value)));
}
TEST_INT *two = sk_TEST_INT_value(sk.get(), 1);
const TEST_INT *two = sk_TEST_INT_value(sk.get(), 1);
// Pointer-based equality.
size_t index;
ASSERT_TRUE(sk_TEST_INT_find(sk.get(), &index, two));

View File

@ -160,7 +160,7 @@ OPENSSL_EXPORT void *sk_delete(_STACK *sk, size_t where);
// sk_delete_ptr removes, at most, one instance of |p| from the stack based on
// pointer equality. If an instance of |p| is found then |p| is returned,
// otherwise it returns NULL.
OPENSSL_EXPORT void *sk_delete_ptr(_STACK *sk, void *p);
OPENSSL_EXPORT void *sk_delete_ptr(_STACK *sk, const void *p);
// sk_find returns the first value in the stack equal to |p|. If a comparison
// function has been set on the stack, equality is defined by it, otherwise
@ -173,7 +173,7 @@ OPENSSL_EXPORT void *sk_delete_ptr(_STACK *sk, void *p);
// Note this differs from OpenSSL. The type signature is slightly different, and
// OpenSSL's sk_find will implicitly sort |sk| if it has a comparison function
// defined.
OPENSSL_EXPORT int sk_find(const _STACK *sk, size_t *out_index, void *p);
OPENSSL_EXPORT int sk_find(const _STACK *sk, size_t *out_index, const void *p);
// sk_shift removes and returns the first element in the stack, or returns NULL
// if the stack is empty.
@ -302,13 +302,13 @@ BSSL_NAMESPACE_END
} \
\
static inline OPENSSL_UNUSED ptrtype sk_##name##_delete_ptr( \
STACK_OF(name) *sk, ptrtype p) { \
return (ptrtype)sk_delete_ptr((_STACK *)sk, (void *)p); \
STACK_OF(name) *sk, constptrtype p) { \
return (ptrtype)sk_delete_ptr((_STACK *)sk, (const void *)p); \
} \
\
static inline OPENSSL_UNUSED int sk_##name##_find( \
const STACK_OF(name) *sk, size_t *out_index, ptrtype p) { \
return sk_find((const _STACK *)sk, out_index, (void *)p); \
const STACK_OF(name) *sk, size_t *out_index, constptrtype p) { \
return sk_find((const _STACK *)sk, out_index, (const void *)p); \
} \
\
static inline OPENSSL_UNUSED ptrtype sk_##name##_shift(STACK_OF(name) *sk) { \