mirror of
https://github.com/shadowsocks/shadowsocks-libev.git
synced 2026-10-30 22:13:49 +00:00
Polish code
code issues found by Clang with CFLAGS="-Os -Wall -Wextra -Werror=unused-const-variable -Wno-error=unused-parameter" enabled The details as follows: - variable initialization issue, modified them as Clang suggested - data type mismatch when comparing, fix them either by casting or changing the data type of index of iterator - get_sockaddr() in netutils may return -1 thus changed returning type from size_t to ssize_t, which makes Clang happier - recvfrom() in udprelay is identical, fix this by creating local variable for comparison and assign back to buf->len when returning value is acceptable Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
This commit is contained in:
+7
-6
@@ -203,7 +203,8 @@ static int safe_memcmp(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
const unsigned char *_s1 = (const unsigned char *)s1;
|
||||
const unsigned char *_s2 = (const unsigned char *)s2;
|
||||
int ret = 0, i;
|
||||
int ret = 0;
|
||||
size_t i;
|
||||
for (i = 0; i < n; i++)
|
||||
ret |= _s1[i] ^ _s2[i];
|
||||
return !!ret;
|
||||
@@ -219,7 +220,7 @@ int balloc(buffer_t *ptr, size_t capacity)
|
||||
|
||||
int brealloc(buffer_t *ptr, size_t len, size_t capacity)
|
||||
{
|
||||
int real_capacity = max(len, capacity);
|
||||
size_t real_capacity = max(len, capacity);
|
||||
if (ptr->capacity < real_capacity) {
|
||||
ptr->array = realloc(ptr->array, real_capacity);
|
||||
ptr->capacity = real_capacity;
|
||||
@@ -1119,7 +1120,7 @@ int ss_encrypt_all(buffer_t *plain, int method, int auth, size_t capacity)
|
||||
size_t iv_len = enc_iv_len;
|
||||
int err = 1;
|
||||
|
||||
static buffer_t tmp = { 0 };
|
||||
static buffer_t tmp = { 0, 0, 0, NULL };
|
||||
brealloc(&tmp, iv_len + plain->len, capacity);
|
||||
buffer_t *cipher = &tmp;
|
||||
cipher->len = plain->len;
|
||||
@@ -1178,7 +1179,7 @@ int ss_encrypt_all(buffer_t *plain, int method, int auth, size_t capacity)
|
||||
int ss_encrypt(buffer_t *plain, enc_ctx_t *ctx, size_t capacity)
|
||||
{
|
||||
if (ctx != NULL) {
|
||||
static buffer_t tmp = { 0 };
|
||||
static buffer_t tmp = { 0, 0, 0, NULL };
|
||||
|
||||
int err = 1;
|
||||
size_t iv_len = 0;
|
||||
@@ -1261,7 +1262,7 @@ int ss_decrypt_all(buffer_t *cipher, int method, int auth, size_t capacity)
|
||||
cipher_ctx_t evp;
|
||||
cipher_context_init(&evp, method, 0);
|
||||
|
||||
static buffer_t tmp = { 0 };
|
||||
static buffer_t tmp = { 0, 0, 0, NULL };
|
||||
brealloc(&tmp, cipher->len, capacity);
|
||||
buffer_t *plain = &tmp;
|
||||
plain->len = cipher->len - iv_len;
|
||||
@@ -1324,7 +1325,7 @@ int ss_decrypt_all(buffer_t *cipher, int method, int auth, size_t capacity)
|
||||
int ss_decrypt(buffer_t *cipher, enc_ctx_t *ctx, size_t capacity)
|
||||
{
|
||||
if (ctx != NULL) {
|
||||
static buffer_t tmp = { 0 };
|
||||
static buffer_t tmp = { 0, 0, 0, NULL };
|
||||
|
||||
size_t iv_len = 0;
|
||||
int err = 1;
|
||||
|
||||
Reference in New Issue
Block a user