提交 36639907 编写于 作者: R Rich Salz

Add some const casts

Reviewed-by: NMatt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/1397)
上级 446dffa7
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
struct stack_st { struct stack_st {
int num; int num;
char **data; const char **data;
int sorted; int sorted;
int num_alloc; int num_alloc;
OPENSSL_sk_compfunc comp; OPENSSL_sk_compfunc comp;
...@@ -81,7 +81,7 @@ OPENSSL_STACK *OPENSSL_sk_deep_copy(const OPENSSL_STACK *sk, ...@@ -81,7 +81,7 @@ OPENSSL_STACK *OPENSSL_sk_deep_copy(const OPENSSL_STACK *sk,
if ((ret->data[i] = copy_func(sk->data[i])) == NULL) { if ((ret->data[i] = copy_func(sk->data[i])) == NULL) {
while (--i >= 0) while (--i >= 0)
if (ret->data[i] != NULL) if (ret->data[i] != NULL)
free_func(ret->data[i]); free_func((void *)ret->data[i]);
OPENSSL_sk_free(ret); OPENSSL_sk_free(ret);
return NULL; return NULL;
} }
...@@ -111,9 +111,9 @@ OPENSSL_STACK *OPENSSL_sk_new(OPENSSL_sk_compfunc c) ...@@ -111,9 +111,9 @@ OPENSSL_STACK *OPENSSL_sk_new(OPENSSL_sk_compfunc c)
return (NULL); 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) if (st == NULL)
return 0; return 0;
...@@ -128,8 +128,8 @@ int OPENSSL_sk_insert(OPENSSL_STACK *st, void *data, int loc) ...@@ -128,8 +128,8 @@ int OPENSSL_sk_insert(OPENSSL_STACK *st, void *data, int loc)
if ((loc >= (int)st->num) || (loc < 0)) if ((loc >= (int)st->num) || (loc < 0))
st->data[st->num] = data; st->data[st->num] = data;
else { else {
memmove(&(st->data[loc + 1]), memmove(&st->data[loc + 1], &st->data[loc],
&(st->data[loc]), sizeof(char *) * (st->num - loc)); sizeof(st->data[0]) * (st->num - loc));
st->data[loc] = data; st->data[loc] = data;
} }
st->num++; st->num++;
...@@ -149,30 +149,23 @@ void *OPENSSL_sk_delete_ptr(OPENSSL_STACK *st, const void *p) ...@@ -149,30 +149,23 @@ void *OPENSSL_sk_delete_ptr(OPENSSL_STACK *st, const void *p)
void *OPENSSL_sk_delete(OPENSSL_STACK *st, int loc) void *OPENSSL_sk_delete(OPENSSL_STACK *st, int loc)
{ {
char *ret; const char *ret;
int i, j;
if (st == NULL || loc < 0 || loc >= st->num) if (st == NULL || loc < 0 || loc >= st->num)
return NULL; return NULL;
ret = st->data[loc]; ret = st->data[loc];
if (loc != st->num - 1) { if (loc != st->num - 1)
j = st->num - 1; memmove(&st->data[loc], &st->data[loc + 1],
for (i = loc; i < j; i++) sizeof(st->data[0]) * (st->num - loc - 1));
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));
*/
}
st->num--; st->num--;
return (ret); return (void *)ret;
} }
static int internal_find(OPENSSL_STACK *st, const void *data, static int internal_find(OPENSSL_STACK *st, const void *data,
int ret_val_options) int ret_val_options)
{ {
const void *const *r; const void *r;
int i; int i;
if (st == NULL) if (st == NULL)
...@@ -191,7 +184,7 @@ static int internal_find(OPENSSL_STACK *st, const void *data, ...@@ -191,7 +184,7 @@ static int internal_find(OPENSSL_STACK *st, const void *data,
ret_val_options); ret_val_options);
if (r == NULL) if (r == NULL)
return (-1); 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) 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) ...@@ -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); 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)); 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)); return (OPENSSL_sk_insert(st, data, 0));
} }
...@@ -250,7 +243,7 @@ void OPENSSL_sk_pop_free(OPENSSL_STACK *st, OPENSSL_sk_freefunc func) ...@@ -250,7 +243,7 @@ void OPENSSL_sk_pop_free(OPENSSL_STACK *st, OPENSSL_sk_freefunc func)
return; return;
for (i = 0; i < st->num; i++) for (i = 0; i < st->num; i++)
if (st->data[i] != NULL) if (st->data[i] != NULL)
func(st->data[i]); func((char *)st->data[i]);
OPENSSL_sk_free(st); OPENSSL_sk_free(st);
} }
...@@ -273,14 +266,15 @@ void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i) ...@@ -273,14 +266,15 @@ void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i)
{ {
if (st == NULL || i < 0 || i >= st->num) if (st == NULL || i < 0 || i >= st->num)
return NULL; 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) if (st == NULL || i < 0 || i >= st->num)
return NULL; return NULL;
return (st->data[i] = value); st->data[i] = data;
return (void *)st->data[i];
} }
void OPENSSL_sk_sort(OPENSSL_STACK *st) void OPENSSL_sk_sort(OPENSSL_STACK *st)
......
...@@ -41,13 +41,13 @@ stack container ...@@ -41,13 +41,13 @@ stack container
void sk_TYPE_zero(const STACK_OF(TYPE) *sk); void sk_TYPE_zero(const STACK_OF(TYPE) *sk);
TYPE *sk_TYPE_delete(STACK_OF(TYPE) *sk, int i); TYPE *sk_TYPE_delete(STACK_OF(TYPE) *sk, int i);
TYPE *sk_TYPE_delete_ptr(STACK_OF(TYPE) *sk, TYPE *ptr); TYPE *sk_TYPE_delete_ptr(STACK_OF(TYPE) *sk, TYPE *ptr);
int sk_TYPE_push(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, TYPE *ptr); int sk_TYPE_unshift(STACK_OF(TYPE) *sk, const TYPE *ptr);
TYPE *sk_TYPE_pop(STACK_OF(TYPE) *sk); TYPE *sk_TYPE_pop(STACK_OF(TYPE) *sk);
TYPE *sk_TYPE_shift(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); 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); 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(STACK_OF(TYPE) *sk, TYPE *ptr);
int sk_TYPE_find_ex(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); void sk_TYPE_sort(const STACK_OF(TYPE) *sk);
......
...@@ -59,11 +59,11 @@ extern "C" { ...@@ -59,11 +59,11 @@ extern "C" {
} \ } \
static ossl_inline int sk_##t1##_push(STACK_OF(t1) *sk, t2 *ptr) \ 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) \ 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) \ static ossl_inline t2 *sk_##t1##_pop(STACK_OF(t1) *sk) \
{ \ { \
...@@ -79,11 +79,11 @@ extern "C" { ...@@ -79,11 +79,11 @@ extern "C" {
} \ } \
static ossl_inline int sk_##t1##_insert(STACK_OF(t1) *sk, t2 *ptr, int idx) \ 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) \ 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) \ static ossl_inline int sk_##t1##_find(STACK_OF(t1) *sk, t2 *ptr) \
{ \ { \
...@@ -109,7 +109,7 @@ extern "C" { ...@@ -109,7 +109,7 @@ extern "C" {
sk_##t1##_copyfunc copyfunc, \ sk_##t1##_copyfunc copyfunc, \
sk_##t1##_freefunc freefunc) \ 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_copyfunc)copyfunc, \
(OPENSSL_sk_freefunc)freefunc); \ (OPENSSL_sk_freefunc)freefunc); \
} \ } \
......
...@@ -23,20 +23,20 @@ typedef void *(*OPENSSL_sk_copyfunc)(const void *); ...@@ -23,20 +23,20 @@ typedef void *(*OPENSSL_sk_copyfunc)(const void *);
int OPENSSL_sk_num(const OPENSSL_STACK *); int OPENSSL_sk_num(const OPENSSL_STACK *);
void *OPENSSL_sk_value(const OPENSSL_STACK *, int); 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(OPENSSL_sk_compfunc cmp);
OPENSSL_STACK *OPENSSL_sk_new_null(void); OPENSSL_STACK *OPENSSL_sk_new_null(void);
void OPENSSL_sk_free(OPENSSL_STACK *); void OPENSSL_sk_free(OPENSSL_STACK *);
void OPENSSL_sk_pop_free(OPENSSL_STACK *st, void (*func) (void *)); 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); 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(OPENSSL_STACK *st, int loc);
void *OPENSSL_sk_delete_ptr(OPENSSL_STACK *st, const void *p); 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(OPENSSL_STACK *st, const void *data);
int OPENSSL_sk_find_ex(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_push(OPENSSL_STACK *st, const void *data);
int OPENSSL_sk_unshift(OPENSSL_STACK *st, void *data); int OPENSSL_sk_unshift(OPENSSL_STACK *st, const void *data);
void *OPENSSL_sk_shift(OPENSSL_STACK *st); void *OPENSSL_sk_shift(OPENSSL_STACK *st);
void *OPENSSL_sk_pop(OPENSSL_STACK *st); void *OPENSSL_sk_pop(OPENSSL_STACK *st);
void OPENSSL_sk_zero(OPENSSL_STACK *st); void OPENSSL_sk_zero(OPENSSL_STACK *st);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册