[openssl-commits] [openssl] master update
Rich Salz
rsalz at openssl.org
Wed Aug 10 13:57:54 UTC 2016
The branch master has been updated
via 3663990760f9e414c50f3a73fa7276b4b528ef41 (commit)
from 446dffa7f6abf5400adac9c7814440b5af3b7edd (commit)
- Log -----------------------------------------------------------------
commit 3663990760f9e414c50f3a73fa7276b4b528ef41
Author: Rich Salz <rsalz at openssl.org>
Date: Thu Aug 4 16:50:19 2016 -0400
Add some const casts
Reviewed-by: Matt Caswell <matt at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/1397)
-----------------------------------------------------------------------
Summary of changes:
crypto/stack/stack.c | 46 ++++++++++++++++++------------------------
doc/crypto/DEFINE_STACK_OF.pod | 6 +++---
include/openssl/safestack.h | 10 ++++-----
include/openssl/stack.h | 8 ++++----
4 files changed, 32 insertions(+), 38 deletions(-)
diff --git a/crypto/stack/stack.c b/crypto/stack/stack.c
index 02be8af..acd350a 100644
--- a/crypto/stack/stack.c
+++ b/crypto/stack/stack.c
@@ -14,7 +14,7 @@
struct stack_st {
int num;
- char **data;
+ const char **data;
int sorted;
int num_alloc;
OPENSSL_sk_compfunc comp;
@@ -81,7 +81,7 @@ OPENSSL_STACK *OPENSSL_sk_deep_copy(const OPENSSL_STACK *sk,
if ((ret->data[i] = copy_func(sk->data[i])) == NULL) {
while (--i >= 0)
if (ret->data[i] != NULL)
- free_func(ret->data[i]);
+ free_func((void *)ret->data[i]);
OPENSSL_sk_free(ret);
return NULL;
}
@@ -111,9 +111,9 @@ OPENSSL_STACK *OPENSSL_sk_new(OPENSSL_sk_compfunc c)
return (NULL);
}
-int OPENSSL_sk_insert(OPENSSL_STACK *st, void *data, int loc)
+int OPENSSL_sk_insert(OPENSSL_STACK *st, const void *data, int loc)
{
- char **s;
+ const char **s;
if (st == NULL)
return 0;
@@ -128,8 +128,8 @@ int OPENSSL_sk_insert(OPENSSL_STACK *st, void *data, int loc)
if ((loc >= (int)st->num) || (loc < 0))
st->data[st->num] = data;
else {
- memmove(&(st->data[loc + 1]),
- &(st->data[loc]), sizeof(char *) * (st->num - loc));
+ memmove(&st->data[loc + 1], &st->data[loc],
+ sizeof(st->data[0]) * (st->num - loc));
st->data[loc] = data;
}
st->num++;
@@ -149,30 +149,23 @@ void *OPENSSL_sk_delete_ptr(OPENSSL_STACK *st, const void *p)
void *OPENSSL_sk_delete(OPENSSL_STACK *st, int loc)
{
- char *ret;
- int i, j;
+ const char *ret;
if (st == NULL || loc < 0 || loc >= st->num)
return NULL;
ret = st->data[loc];
- if (loc != st->num - 1) {
- j = st->num - 1;
- for (i = loc; i < j; i++)
- st->data[i] = st->data[i + 1];
- /*
- * In theory memcpy is not safe for this memcpy( &(st->data[loc]),
- * &(st->data[loc+1]), sizeof(char *)*(st->num-loc-1));
- */
- }
+ if (loc != st->num - 1)
+ memmove(&st->data[loc], &st->data[loc + 1],
+ sizeof(st->data[0]) * (st->num - loc - 1));
st->num--;
- return (ret);
+ return (void *)ret;
}
static int internal_find(OPENSSL_STACK *st, const void *data,
int ret_val_options)
{
- const void *const *r;
+ const void *r;
int i;
if (st == NULL)
@@ -191,7 +184,7 @@ static int internal_find(OPENSSL_STACK *st, const void *data,
ret_val_options);
if (r == NULL)
return (-1);
- return (int)((char **)r - st->data);
+ return (int)((const char **)r - st->data);
}
int OPENSSL_sk_find(OPENSSL_STACK *st, const void *data)
@@ -204,12 +197,12 @@ int OPENSSL_sk_find_ex(OPENSSL_STACK *st, const void *data)
return internal_find(st, data, OBJ_BSEARCH_VALUE_ON_NOMATCH);
}
-int OPENSSL_sk_push(OPENSSL_STACK *st, void *data)
+int OPENSSL_sk_push(OPENSSL_STACK *st, const void *data)
{
return (OPENSSL_sk_insert(st, data, st->num));
}
-int OPENSSL_sk_unshift(OPENSSL_STACK *st, void *data)
+int OPENSSL_sk_unshift(OPENSSL_STACK *st, const void *data)
{
return (OPENSSL_sk_insert(st, data, 0));
}
@@ -250,7 +243,7 @@ void OPENSSL_sk_pop_free(OPENSSL_STACK *st, OPENSSL_sk_freefunc func)
return;
for (i = 0; i < st->num; i++)
if (st->data[i] != NULL)
- func(st->data[i]);
+ func((char *)st->data[i]);
OPENSSL_sk_free(st);
}
@@ -273,14 +266,15 @@ void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i)
{
if (st == NULL || i < 0 || i >= st->num)
return NULL;
- return st->data[i];
+ return (void *)st->data[i];
}
-void *OPENSSL_sk_set(OPENSSL_STACK *st, int i, void *value)
+void *OPENSSL_sk_set(OPENSSL_STACK *st, int i, const void *data)
{
if (st == NULL || i < 0 || i >= st->num)
return NULL;
- return (st->data[i] = value);
+ st->data[i] = data;
+ return (void *)st->data[i];
}
void OPENSSL_sk_sort(OPENSSL_STACK *st)
diff --git a/doc/crypto/DEFINE_STACK_OF.pod b/doc/crypto/DEFINE_STACK_OF.pod
index 5acc3e3..ae443b0 100644
--- a/doc/crypto/DEFINE_STACK_OF.pod
+++ b/doc/crypto/DEFINE_STACK_OF.pod
@@ -41,13 +41,13 @@ stack container
void sk_TYPE_zero(const STACK_OF(TYPE) *sk);
TYPE *sk_TYPE_delete(STACK_OF(TYPE) *sk, int i);
TYPE *sk_TYPE_delete_ptr(STACK_OF(TYPE) *sk, TYPE *ptr);
- int sk_TYPE_push(STACK_OF(TYPE) *sk, TYPE *ptr);
- int sk_TYPE_unshift(STACK_OF(TYPE) *sk, TYPE *ptr);
+ int sk_TYPE_push(STACK_OF(TYPE) *sk, const TYPE *ptr);
+ int sk_TYPE_unshift(STACK_OF(TYPE) *sk, const TYPE *ptr);
TYPE *sk_TYPE_pop(STACK_OF(TYPE) *sk);
TYPE *sk_TYPE_shift(STACK_OF(TYPE) *sk);
void sk_TYPE_pop_free(STACK_OF(TYPE) *sk, sk_TYPE_freefunc freefunc);
int sk_TYPE_insert(STACK_OF(TYPE) *sk, TYPE *ptr, int idx);
- TYPE *sk_TYPE_set(STACK_OF(TYPE) *sk, int idx, TYPE *ptr);
+ TYPE *sk_TYPE_set(STACK_OF(TYPE) *sk, int idx, const TYPE *ptr);
int sk_TYPE_find(STACK_OF(TYPE) *sk, TYPE *ptr);
int sk_TYPE_find_ex(STACK_OF(TYPE) *sk, TYPE *ptr);
void sk_TYPE_sort(const STACK_OF(TYPE) *sk);
diff --git a/include/openssl/safestack.h b/include/openssl/safestack.h
index 7877fd9..9fe733c 100644
--- a/include/openssl/safestack.h
+++ b/include/openssl/safestack.h
@@ -59,11 +59,11 @@ extern "C" {
} \
static ossl_inline int sk_##t1##_push(STACK_OF(t1) *sk, t2 *ptr) \
{ \
- return OPENSSL_sk_push((OPENSSL_STACK *)sk, (void *)ptr); \
+ return OPENSSL_sk_push((OPENSSL_STACK *)sk, (const void *)ptr); \
} \
static ossl_inline int sk_##t1##_unshift(STACK_OF(t1) *sk, t2 *ptr) \
{ \
- return OPENSSL_sk_unshift((OPENSSL_STACK *)sk, (void *)ptr); \
+ return OPENSSL_sk_unshift((OPENSSL_STACK *)sk, (const void *)ptr); \
} \
static ossl_inline t2 *sk_##t1##_pop(STACK_OF(t1) *sk) \
{ \
@@ -79,11 +79,11 @@ extern "C" {
} \
static ossl_inline int sk_##t1##_insert(STACK_OF(t1) *sk, t2 *ptr, int idx) \
{ \
- return OPENSSL_sk_insert((OPENSSL_STACK *)sk, (void *)ptr, idx); \
+ return OPENSSL_sk_insert((OPENSSL_STACK *)sk, (const void *)ptr, idx); \
} \
static ossl_inline t2 *sk_##t1##_set(STACK_OF(t1) *sk, int idx, t2 *ptr) \
{ \
- return (t2 *)OPENSSL_sk_set((OPENSSL_STACK *)sk, idx, (void *)ptr); \
+ return (t2 *)OPENSSL_sk_set((OPENSSL_STACK *)sk, idx, (const void *)ptr); \
} \
static ossl_inline int sk_##t1##_find(STACK_OF(t1) *sk, t2 *ptr) \
{ \
@@ -109,7 +109,7 @@ extern "C" {
sk_##t1##_copyfunc copyfunc, \
sk_##t1##_freefunc freefunc) \
{ \
- return (STACK_OF(t1) *)OPENSSL_sk_deep_copy((OPENSSL_STACK *)sk, \
+ return (STACK_OF(t1) *)OPENSSL_sk_deep_copy((const OPENSSL_STACK *)sk, \
(OPENSSL_sk_copyfunc)copyfunc, \
(OPENSSL_sk_freefunc)freefunc); \
} \
diff --git a/include/openssl/stack.h b/include/openssl/stack.h
index ae47be9..23ad3b8 100644
--- a/include/openssl/stack.h
+++ b/include/openssl/stack.h
@@ -23,20 +23,20 @@ typedef void *(*OPENSSL_sk_copyfunc)(const void *);
int OPENSSL_sk_num(const OPENSSL_STACK *);
void *OPENSSL_sk_value(const OPENSSL_STACK *, int);
-void *OPENSSL_sk_set(OPENSSL_STACK *, int, void *);
+void *OPENSSL_sk_set(OPENSSL_STACK *st, int i, const void *data);
OPENSSL_STACK *OPENSSL_sk_new(OPENSSL_sk_compfunc cmp);
OPENSSL_STACK *OPENSSL_sk_new_null(void);
void OPENSSL_sk_free(OPENSSL_STACK *);
void OPENSSL_sk_pop_free(OPENSSL_STACK *st, void (*func) (void *));
OPENSSL_STACK *OPENSSL_sk_deep_copy(const OPENSSL_STACK *, OPENSSL_sk_copyfunc c, OPENSSL_sk_freefunc f);
-int OPENSSL_sk_insert(OPENSSL_STACK *sk, void *data, int where);
+int OPENSSL_sk_insert(OPENSSL_STACK *sk, const void *data, int where);
void *OPENSSL_sk_delete(OPENSSL_STACK *st, int loc);
void *OPENSSL_sk_delete_ptr(OPENSSL_STACK *st, const void *p);
int OPENSSL_sk_find(OPENSSL_STACK *st, const void *data);
int OPENSSL_sk_find_ex(OPENSSL_STACK *st, const void *data);
-int OPENSSL_sk_push(OPENSSL_STACK *st, void *data);
-int OPENSSL_sk_unshift(OPENSSL_STACK *st, void *data);
+int OPENSSL_sk_push(OPENSSL_STACK *st, const void *data);
+int OPENSSL_sk_unshift(OPENSSL_STACK *st, const void *data);
void *OPENSSL_sk_shift(OPENSSL_STACK *st);
void *OPENSSL_sk_pop(OPENSSL_STACK *st);
void OPENSSL_sk_zero(OPENSSL_STACK *st);
More information about the openssl-commits
mailing list