Skip to content

Commit

Permalink
Use C99 like the Linux kernel, again
Browse files Browse the repository at this point in the history
Apply to loop variables so that they don't leak out of the loop - unless
they leak on purpose.
  • Loading branch information
DimitriPapadopoulos committed Dec 29, 2023
1 parent c565bb6 commit 9f5a0e6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
8 changes: 2 additions & 6 deletions src/ipv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -887,9 +887,7 @@ int ipv4_add_split_vpn_route(struct tunnel *tunnel, char *dest, char *mask,

static int ipv4_set_split_routes(struct tunnel *tunnel)
{
int i;

for (i = 0; i < tunnel->ipv4.split_routes; i++) {
for (int i = 0; i < tunnel->ipv4.split_routes; i++) {
struct rtentry *route;
int ret;

Expand Down Expand Up @@ -1056,9 +1054,7 @@ int ipv4_restore_routes(struct tunnel *tunnel)

static inline char *replace_char(char *str, char find, char replace)
{
int i;

for (i = 0; i < strlen(str); i++)
for (int i = 0; i < strlen(str); i++)
if (str[i] == find)
str[i] = replace;
return str;
Expand Down
20 changes: 5 additions & 15 deletions src/ssl.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,9 @@ static inline int handle_ssl_error(SSL *ssl, int ret)
*/
static inline int safe_ssl_read(SSL *ssl, uint8_t *buf, int bufsize)
{
int ret;
int ret = SSL_read(ssl, buf, bufsize);

ret = SSL_read(ssl, buf, bufsize);
if (ret > 0)
return ret;

return handle_ssl_error(ssl, ret);
return (ret > 0) ? ret : handle_ssl_error(ssl, ret);
}

/*
Expand All @@ -147,9 +143,7 @@ static inline int safe_ssl_read(SSL *ssl, uint8_t *buf, int bufsize)
*/
static inline int safe_ssl_read_all(SSL *ssl, uint8_t *buf, int bufsize)
{
int n = 0;

while (n < bufsize) {
for (int n = 0; n < bufsize; ) {
int ret;

ret = safe_ssl_read(ssl, &buf[n], bufsize - n);
Expand All @@ -175,13 +169,9 @@ static inline int safe_ssl_read_all(SSL *ssl, uint8_t *buf, int bufsize)
*/
static inline int safe_ssl_write(SSL *ssl, const uint8_t *buf, int n)
{
int ret;

ret = SSL_write(ssl, buf, n);
if (ret > 0)
return ret;
int ret = SSL_write(ssl, buf, n);

return handle_ssl_error(ssl, ret);
return (ret > 0) ? ret : handle_ssl_error(ssl, ret);
}

#endif

0 comments on commit 9f5a0e6

Please sign in to comment.