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>
diff --git a/crypto/stack/stack.c b/crypto/stack/stack.c
index 7aa3218..6a23722 100644
--- a/crypto/stack/stack.c
+++ b/crypto/stack/stack.c
@@ -209,7 +209,7 @@
   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 @@
   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 @@
 
   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 @@
   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) {
diff --git a/crypto/stack/stack_test.cc b/crypto/stack/stack_test.cc
index 6eb9948..58b4192 100644
--- a/crypto/stack/stack_test.cc
+++ b/crypto/stack/stack_test.cc
@@ -324,7 +324,7 @@
     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));
diff --git a/include/openssl/stack.h b/include/openssl/stack.h
index 15b6adf..7431576 100644
--- a/include/openssl/stack.h
+++ b/include/openssl/stack.h
@@ -160,7 +160,7 @@
 // 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 @@
 // 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 @@
   }                                                                            \
                                                                                \
   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) { \