[M] Change in openvpn[master]: Remove various useless assignments
"flichtenheld (Code Review)" <[email protected]>
| Newsgroups | gmane.network.openvpn.devel |
|---|---|
| Message-ID | <[email protected]> |
Attention is currently required from: plaisthos.
Hello plaisthos,
I'd like you to do a code review.
Please visit
http://gerrit.openvpn.net/c/openvpn/+/1617?usp=email
to review the following change.
Change subject: Remove various useless assignments
......................................................................
Remove various useless assignments
The values assigned by these are never actually used
for something.
Identified by cppcheck.
Change-Id: Id0caa497c4ff1ad8743cb23f332f003b2d3393ed
Signed-off-by: Frank Lichtenheld <[email protected]>
---
M src/openvpn/crypto.c
M src/openvpn/error.h
M src/openvpn/forward.c
M src/openvpn/manage.c
M src/openvpn/options.c
M src/openvpn/pkcs11_openssl.c
M src/openvpn/push_util.c
M src/openvpn/ssl_openssl.c
M src/openvpnmsica/openvpnmsica.c
M src/tapctl/tap.c
M tests/unit_tests/openvpn/test_ssl.c
M tests/unit_tests/openvpnserv/test_openvpnserv.c
12 files changed, 22 insertions(+), 40 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/17/1617/1
diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c
index 7954e8a..df9b905 100644
--- a/src/openvpn/crypto.c
+++ b/src/openvpn/crypto.c
@@ -1204,8 +1204,6 @@
struct buffer work = alloc_buf_gc(BUF_SIZE(frame), &gc);
struct buffer encrypt_workspace = alloc_buf_gc(BUF_SIZE(frame), &gc);
struct buffer decrypt_workspace = alloc_buf_gc(BUF_SIZE(frame), &gc);
- struct buffer buf = clear_buf();
- void *buf_p;
/* init work */
ASSERT(buf_init(&work, frame->buf.headroom));
@@ -1242,8 +1240,8 @@
ASSERT(rand_bytes(BPTR(&src), BLEN(&src)));
/* copy source to input buf */
- buf = work;
- buf_p = buf_write_alloc(&buf, BLENZ(&src));
+ struct buffer buf = work;
+ void *buf_p = buf_write_alloc(&buf, BLENZ(&src));
ASSERT(buf_p);
memcpy(buf_p, BPTR(&src), BLENZ(&src));
diff --git a/src/openvpn/error.h b/src/openvpn/error.h
index 62948aa..62389af 100644
--- a/src/openvpn/error.h
+++ b/src/openvpn/error.h
@@ -406,8 +406,8 @@
openvpn_errno_maybe_crt(bool *crt_error)
{
int err = 0;
- *crt_error = false;
#ifdef _WIN32
+ *crt_error = false;
err = GetLastError();
if (err == ERROR_SUCCESS)
{
diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c
index 27cfd36..53eab4d 100644
--- a/src/openvpn/forward.c
+++ b/src/openvpn/forward.c
@@ -1746,7 +1746,6 @@
process_outgoing_link(struct context *c, struct link_socket *sock)
{
struct gc_arena gc = gc_new();
- int error_code = 0;
if (c->c2.to_link.len > 0 && c->c2.to_link.len <= c->c2.frame.buf.payload_size)
{
@@ -1821,7 +1820,7 @@
}
/* Check return status */
- error_code = openvpn_errno();
+ int error_code = openvpn_errno();
check_status(size, "write", sock, NULL);
if (size > 0)
diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c
index d776908..31dcd4f 100644
--- a/src/openvpn/manage.c
+++ b/src/openvpn/manage.c
@@ -912,10 +912,9 @@
static void
man_remote_entry_count(struct management *man)
{
- unsigned count = 0;
if (man->persist.callback.remote_entry_count)
{
- count = (*man->persist.callback.remote_entry_count)(man->persist.callback.arg);
+ unsigned int count = (*man->persist.callback.remote_entry_count)(man->persist.callback.arg);
msg(M_CLIENT, "%u", count);
msg(M_CLIENT, "END");
}
@@ -3660,7 +3659,6 @@
struct gc_arena gc = gc_new();
int ret = 0;
volatile int signal_received = 0;
- struct buffer alert_msg = clear_buf();
const bool standalone_disabled_save = man->persist.standalone_disabled;
struct man_connection *mc = &man->connection;
@@ -3672,6 +3670,7 @@
*state = EKS_SOLICIT;
+ struct buffer alert_msg;
if (b64_data)
{
alert_msg = alloc_buf_gc(strlen(b64_data) + strlen(prompt) + 3, &gc);
diff --git a/src/openvpn/options.c b/src/openvpn/options.c
index 200e3cd..28275cc 100644
--- a/src/openvpn/options.c
+++ b/src/openvpn/options.c
@@ -7091,7 +7091,6 @@
if (streq(p[1], "FORWARD_COMPATIBLE") && p[2] && streq(p[2], "1"))
{
options->forward_compatible = true;
- msglevel_fc = msglevel_forward_compatible(options, msglevel);
}
setenv_str(es, p[1], p[2] ? p[2] : "");
}
diff --git a/src/openvpn/pkcs11_openssl.c b/src/openvpn/pkcs11_openssl.c
index b6c1624..69c5a50 100644
--- a/src/openvpn/pkcs11_openssl.c
+++ b/src/openvpn/pkcs11_openssl.c
@@ -384,7 +384,6 @@
if (certificate != NULL)
{
pkcs11h_certificate_freeCertificate(certificate);
- certificate = NULL;
}
/*
@@ -400,7 +399,6 @@
if (openssl_session != NULL)
{
pkcs11h_openssl_freeSession(openssl_session);
- openssl_session = NULL;
}
return ret;
#endif /* ifdef HAVE_XKEY_PROVIDER */
diff --git a/src/openvpn/push_util.c b/src/openvpn/push_util.c
index e129403..2e5ac40 100644
--- a/src/openvpn/push_util.c
+++ b/src/openvpn/push_util.c
@@ -99,7 +99,6 @@
}
char *str = gc_strdup(s, gc);
- size_t i = 0;
while (*str)
{
@@ -112,11 +111,11 @@
/* if no commas were found go to fail, do not send any message */
return false;
}
+ /* copy from current position to (ci - 1) */
str[ci] = '\0';
- /* copy from i to (ci -1) */
struct buffer tmp = forge_msg(str, ",push-continuation 2", gc);
buffer_list_push(msgs, BSTR(&tmp));
- i = ci + 1;
+ str += ci + 1;
}
else
{
@@ -130,9 +129,8 @@
struct buffer tmp = forge_msg(str, NULL, gc);
buffer_list_push(msgs, BSTR(&tmp));
}
- i = strlen(str);
+ break;
}
- str = &str[i];
}
return true;
}
diff --git a/src/openvpn/ssl_openssl.c b/src/openvpn/ssl_openssl.c
index 234b0b6..44062c9 100644
--- a/src/openvpn/ssl_openssl.c
+++ b/src/openvpn/ssl_openssl.c
@@ -2602,15 +2602,13 @@
"builtin EC curves. It does not list additional curves nor X448 or X25519\n");
#ifndef OPENSSL_NO_EC
EC_builtin_curve *curves = NULL;
- size_t crv_len = 0;
- size_t n = 0;
- crv_len = EC_get_builtin_curves(NULL, 0);
+ size_t crv_len = EC_get_builtin_curves(NULL, 0);
ALLOC_ARRAY(curves, EC_builtin_curve, crv_len);
if (EC_get_builtin_curves(curves, crv_len))
{
printf("\nAvailable Elliptic curves/groups:\n");
- for (n = 0; n < crv_len; n++)
+ for (size_t n = 0; n < crv_len; n++)
{
const char *sname;
sname = OBJ_nid2sn(curves[n].nid);
diff --git a/src/openvpnmsica/openvpnmsica.c b/src/openvpnmsica/openvpnmsica.c
index fdb610c..d698c04 100644
--- a/src/openvpnmsica/openvpnmsica.c
+++ b/src/openvpnmsica/openvpnmsica.c
@@ -711,7 +711,6 @@
uiResult = MsiViewFetch(hViewST, &hRecord);
if (uiResult == ERROR_NO_MORE_ITEMS)
{
- uiResult = ERROR_SUCCESS;
break;
}
else if (uiResult != ERROR_SUCCESS)
diff --git a/src/tapctl/tap.c b/src/tapctl/tap.c
index 16e3c0b..6ed395d 100644
--- a/src/tapctl/tap.c
+++ b/src/tapctl/tap.c
@@ -473,7 +473,7 @@
return ERROR_OUTOFMEMORY;
}
- dwCountExpResult = ExpandEnvironmentStrings(szValue, szValueExp, dwCountExp);
+ ExpandEnvironmentStrings(szValue, szValueExp, dwCountExp);
free(szValue);
*pszValue = szValueExp;
return ERROR_SUCCESS;
@@ -601,8 +601,6 @@
_In_ DWORD dwProperty, _Out_opt_ LPDWORD pdwPropertyRegDataType,
_Out_ LPVOID *ppData)
{
- DWORD dwResult = ERROR_BAD_ARGUMENTS;
-
if (ppData == NULL)
{
return ERROR_BAD_ARGUMENTS;
@@ -628,7 +626,7 @@
}
else
{
- dwResult = GetLastError();
+ DWORD dwResult = GetLastError();
if (dwResult == ERROR_INSUFFICIENT_BUFFER)
{
/* Allocate on heap and retry. */
diff --git a/tests/unit_tests/openvpn/test_ssl.c b/tests/unit_tests/openvpn/test_ssl.c
index 0e9cecf..c40845a 100644
--- a/tests/unit_tests/openvpn/test_ssl.c
+++ b/tests/unit_tests/openvpn/test_ssl.c
@@ -303,8 +303,6 @@
struct buffer work = alloc_buf_gc(BUF_SIZE(&frame), &gc);
struct buffer encrypt_workspace = alloc_buf_gc(BUF_SIZE(&frame), &gc);
struct buffer decrypt_workspace = alloc_buf_gc(BUF_SIZE(&frame), &gc);
- struct buffer buf = clear_buf();
- void *buf_p;
/* init work */
ASSERT(buf_init(&work, frame.buf.headroom));
@@ -325,8 +323,8 @@
ASSERT(rand_bytes(BPTR(&src), BLEN(&src)));
/* copy source to input buf */
- buf = work;
- buf_p = buf_write_alloc(&buf, BLENZ(&src));
+ struct buffer buf = work;
+ void *buf_p = buf_write_alloc(&buf, BLENZ(&src));
ASSERT(buf_p);
memcpy(buf_p, BPTR(&src), BLENZ(&src));
@@ -356,7 +354,6 @@
struct buffer encrypt_workspace = alloc_buf_gc(BUF_SIZE(&frame), &gc);
struct buffer decrypt_workspace = alloc_buf_gc(BUF_SIZE(&frame), &gc);
struct buffer work = alloc_buf_gc(BUF_SIZE(&frame), &gc);
- struct buffer buf = clear_buf();
struct buffer src = alloc_buf_gc(frame.buf.payload_size, &gc);
void *buf_p;
@@ -371,7 +368,7 @@
ASSERT(rand_bytes(BPTR(&src), BLEN(&src)));
/* copy source to input buf */
- buf = work;
+ struct buffer buf = work;
buf_p = buf_write_alloc(&buf, BLENZ(&src));
ASSERT(buf_p);
memcpy(buf_p, BPTR(&src), BLENZ(&src));
@@ -652,7 +649,6 @@
struct buffer work = alloc_buf_gc(BUF_SIZE(&frame), &gc);
struct buffer encrypt_workspace = alloc_buf_gc(BUF_SIZE(&frame), &gc);
struct buffer decrypt_workspace = alloc_buf_gc(BUF_SIZE(&frame), &gc);
- struct buffer buf = clear_buf();
void *buf_p;
/* init work */
@@ -669,7 +665,7 @@
ASSERT(buf_write(&src, plaintext, strlen(plaintext)));
/* copy source to input buf */
- buf = work;
+ struct buffer buf = work;
buf_p = buf_write_alloc(&buf, BLENZ(&src));
ASSERT(buf_p);
memcpy(buf_p, BPTR(&src), BLENZ(&src));
diff --git a/tests/unit_tests/openvpnserv/test_openvpnserv.c b/tests/unit_tests/openvpnserv/test_openvpnserv.c
index 45096a1..6a6aee4 100644
--- a/tests/unit_tests/openvpnserv/test_openvpnserv.c
+++ b/tests/unit_tests/openvpnserv/test_openvpnserv.c
@@ -57,13 +57,13 @@
static void
test_convert_itf_dns_domains(void **state)
{
- DWORD size, orig_size, len, res_len;
+ DWORD size, len, res_len;
LSTATUS err;
const DWORD glyph_size = sizeof(wchar_t);
wchar_t domains_1[BUF_SIZE] = L"openvpn.com";
len = (DWORD)wcslen(domains_1) + 1;
- size = orig_size = len * glyph_size;
+ size = len * glyph_size;
wchar_t domains_1_res[BUF_SIZE] = L".openvpn.com";
res_len = len + 2; /* adds . and \0 */
err = ConvertItfDnsDomains(L"openvpn.net", domains_1, &size, BUF_SIZE);
@@ -73,7 +73,7 @@
wchar_t domains_2[BUF_SIZE] = L"openvpn.com,openvpn.net";
len = (DWORD)wcslen(domains_2) + 1;
- size = orig_size = len * glyph_size;
+ size = len * glyph_size;
wchar_t domains_2_res[BUF_SIZE] = L".openvpn.com";
res_len = (DWORD)wcslen(domains_2_res) + 2;
err = ConvertItfDnsDomains(L"openvpn.net", domains_2, &size, BUF_SIZE);
@@ -83,7 +83,7 @@
wchar_t domains_3[BUF_SIZE] = L"openvpn.com,openvpn.net";
len = (DWORD)wcslen(domains_3) + 1;
- size = orig_size = len * glyph_size;
+ size = len * glyph_size;
wchar_t domains_3_res[BUF_SIZE] = L".openvpn.net";
res_len = (DWORD)wcslen(domains_3_res) + 2;
err = ConvertItfDnsDomains(L"openvpn.com", domains_3, &size, BUF_SIZE);
@@ -93,7 +93,7 @@
wchar_t domains_4[BUF_SIZE] = L"openvpn.com,openvpn.net";
len = (DWORD)wcslen(domains_4) + 1;
- size = orig_size = len * glyph_size;
+ size = len * glyph_size;
wchar_t domains_4_res[BUF_SIZE] = L".openvpn.com\0.openvpn.net";
res_len = len + 3; /* adds two . and one \0 */
err = ConvertItfDnsDomains(NULL, domains_4, &size, BUF_SIZE);
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1617?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id0caa497c4ff1ad8743cb23f332f003b2d3393ed
Gerrit-Change-Number: 1617
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]>
Gerrit-Reviewer: plaisthos <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel