Skip to content

Commit a2d954d

Browse files
committed
Code modernization mega commit
- Run github actions on Ubuntu 22.04 - Build with gcc-12 and clang-15 - clang-tidy exclude list updated from scratch - Using "-gdwarf-4" because of: llvm/llvm-project#56550 - Added (void) to ignore return values - Added void if no function parameter is used - Default version string updated - valgrind suppression file added - Timeouts raised in case of valgrind test: more important to run stable
1 parent 42fdaaa commit a2d954d

File tree

9 files changed

+47
-28
lines changed

9 files changed

+47
-28
lines changed

.github/workflows/cmake.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,27 @@ jobs:
88
# well on Windows or Mac. You can convert this to a matrix build if you need
99
# cross-platform coverage.
1010
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
11-
runs-on: ubuntu-20.04
11+
runs-on: ubuntu-22.04
1212

1313
strategy:
14+
fail-fast: false
1415
matrix:
15-
compiler: [gcc-10, clang-12]
16+
compiler: [gcc-12, clang-15]
1617

1718
steps:
18-
- uses: actions/checkout@v2
19+
- uses: actions/checkout@main
1920

2021
- name: Update APT
2122
run: sudo apt-get update
2223

2324
- name: Setup Dependencies
24-
run: sudo apt-get install cmake libc-ares-dev libcurl4-openssl-dev libev-dev build-essential clang-tidy-12 ${{ matrix.compiler }} dnsutils python3-pip valgrind
25+
run: sudo apt-get install cmake libc-ares-dev libcurl4-openssl-dev libev-dev build-essential clang-tidy-15 ${{ matrix.compiler }} dnsutils python3-pip valgrind
2526

2627
- name: Setup Robot Framework
2728
run: sudo pip3 install robotframework
2829

2930
- name: Set clang-tidy
30-
run: sudo update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-12 100
31+
run: sudo update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-15 100
3132

3233
- name: Configure CMake
3334
env:
@@ -43,7 +44,7 @@ jobs:
4344
- name: Test
4445
run: make -C ${{github.workspace}}/ test ARGS="--verbose"
4546

46-
- uses: actions/upload-artifact@v2
47+
- uses: actions/upload-artifact@v3
4748
if: ${{ success() || failure() }}
4849
with:
4950
name: robot-logs-${{ matrix.compiler }}

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
project(HttpsDnsProxy C)
21
cmake_minimum_required(VERSION 3.7)
2+
project(HttpsDnsProxy C)
33

44
# FUNCTIONS
55

@@ -26,7 +26,7 @@ if (NOT CMAKE_INSTALL_BINDIR)
2626
endif()
2727

2828
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra --pedantic -Wno-strict-aliasing -Wno-variadic-macros")
29-
set(CMAKE_C_FLAGS_DEBUG "-g -DDEBUG")
29+
set(CMAKE_C_FLAGS_DEBUG "-gdwarf-4 -DDEBUG")
3030
set(CMAKE_C_FLAGS_RELEASE "-O2")
3131

3232
if ((CMAKE_C_COMPILER_ID MATCHES GNU AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 9) OR
@@ -92,7 +92,7 @@ if(NOT CLANG_TIDY_EXE)
9292
message(STATUS "clang-tidy not found.")
9393
else()
9494
message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
95-
set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" "-fix" "-checks=*,-clang-analyzer-alpha.*,-misc-unused-parameters,-cert-err34-c,-google-readability-todo,-hicpp-signed-bitwise,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers,-gnu-folding-constant,-gnu-zero-variadic-macro-arguments,-readability-function-cognitive-complexity,-concurrency-mt-unsafe")
95+
set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" "-fix" "-checks=*,-cert-err34-c,-readability-identifier-length,-altera-unroll-loops,-bugprone-easily-swappable-parameters,-concurrency-mt-unsafe,-*magic-numbers,-hicpp-signed-bitwise,-readability-function-cognitive-complexity,-altera-id-dependent-backward-branch,-google-readability-todo")
9696
endif()
9797

9898
# BUILD

src/logging.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static void logging_timer_cb(struct ev_loop __attribute__((unused)) *loop,
2626
ev_timer __attribute__((unused)) *w,
2727
int __attribute__((unused)) revents) {
2828
if (logf) {
29-
fflush(logf);
29+
(void)fflush(logf);
3030
}
3131
}
3232

@@ -47,20 +47,20 @@ void logging_flush_cleanup(struct ev_loop *loop) {
4747

4848
void logging_init(int fd, int level) {
4949
if (logf) {
50-
fclose(logf);
50+
(void)fclose(logf);
5151
}
5252
logf = fdopen(fd, "a");
5353
loglevel = level;
5454
}
5555

56-
void logging_cleanup() {
56+
void logging_cleanup(void) {
5757
if (logf) {
58-
fclose(logf);
58+
(void)fclose(logf);
5959
}
6060
logf = NULL;
6161
}
6262

63-
int logging_debug_enabled() {
63+
int logging_debug_enabled(void) {
6464
return loglevel <= LOG_DEBUG;
6565
}
6666

@@ -78,18 +78,18 @@ void _log(const char *file, int line, int severity, const char *fmt, ...) {
7878

7979
struct timeval tv;
8080
gettimeofday(&tv, NULL);
81-
fprintf(logf, "%s %8lu.%06lu %s:%d ", SeverityStr[severity],
81+
(void)fprintf(logf, "%s %8lu.%06lu %s:%d ", SeverityStr[severity],
8282
(uint64_t)tv.tv_sec,
8383
(uint64_t)tv.tv_usec, file, line);
8484

8585
va_list args;
8686
va_start(args, fmt);
87-
vfprintf(logf, fmt, args);
87+
(void)vfprintf(logf, fmt, args);
8888
va_end(args);
89-
fprintf(logf, "\n");
89+
(void)fprintf(logf, "\n");
9090

9191
if (severity >= LOG_FLUSH_LEVEL) {
92-
fflush(logf);
92+
(void)fflush(logf);
9393
}
9494
if (severity == LOG_FATAL) {
9595
#ifdef DEBUG

src/logging.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ void logging_flush_init(struct ev_loop *loop);
1616
void logging_flush_cleanup(struct ev_loop *loop);
1717

1818
// Cleans up and flushes open logs.
19-
void logging_cleanup();
19+
void logging_cleanup(void);
2020

2121
// Returns 1 if debug logging is enabled.
22-
int logging_debug_enabled();
22+
int logging_debug_enabled(void);
2323

2424
// Internal. Don't use.
2525
void _log(const char *file, int line, int severity, const char *fmt, ...);

src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ static void dns_poll_cb(const char* hostname, void *data,
169169
memset(buf, 0, sizeof(buf)); // NOLINT(clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling)
170170
if (strlen(hostname) > 254) { FLOG("Hostname too long."); }
171171
int ip_start = snprintf(buf, sizeof(buf) - 1, "%s:443:", hostname); // NOLINT(clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling)
172-
snprintf(buf + ip_start, sizeof(buf) - 1 - ip_start, "%s", addr_list); // NOLINT(clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling)
172+
(void)snprintf(buf + ip_start, sizeof(buf) - 1 - ip_start, "%s", addr_list); // NOLINT(clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling)
173173
if (app->resolv && app->resolv->data) {
174174
char * old_addr_list = strstr(app->resolv->data, ":443:");
175175
if (old_addr_list) {

src/options.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ DEFAULT_HTTP_VERSION = 2
2020
};
2121

2222

23-
const char * options_sw_version() {
23+
const char * options_sw_version(void) {
2424
#ifdef SW_VERSION
2525
return SW_VERSION;
2626
#else
27-
return "2023.01.01-atLeast"; // update date sometimes, like 1-2 times a year
27+
return "2023.10.10-atLeast"; // update date sometimes, like 1-2 times a year
2828
#endif
2929
}
3030

src/options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ typedef struct Options options_t;
5757
#ifdef __cplusplus
5858
extern "C" {
5959
#endif
60-
const char * options_sw_version();
60+
const char * options_sw_version(void);
6161
void options_init(struct Options *opt);
6262
int options_parse_args(struct Options *opt, int argc, char **argv);
6363
void options_show_usage(int argc, char **argv);

tests/robot/functional_tests.robot

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ Start Proxy
3333

3434
Start Proxy With Valgrind
3535
[Arguments] @{args}
36-
@{default_args} = Create List --track-fds=yes --time-stamp=yes --log-file=valgrind-%p.log
36+
@{default_args} = Create List --track-fds=yes --time-stamp=yes --log-file=valgrind-%p.log --suppressions=valgrind.supp
3737
... --gen-suppressions=all --tool=memcheck --leak-check=full --leak-resolution=high
3838
... --show-leak-kinds=all --track-origins=yes --keep-stacktraces=alloc-and-free
3939
... ${BINARY_PATH} -v -v -v -4 -p ${PORT}
4040
@{proces_args} = Combine Lists ${default_args} ${args}
4141
${proxy} = Start Process valgrind @{proces_args}
4242
... stderr=STDOUT alias=proxy
4343
Set Test Variable ${proxy}
44-
Set Test Variable ${dig_timeout} 4
44+
Set Test Variable ${dig_timeout} 10
4545
Set Test Variable ${dig_retry} 2
46-
Sleep 3 # wait for valgrind to fire up the proxy
46+
Sleep 6 # wait for valgrind to fire up the proxy
4747
Common Test Setup
4848

4949
Stop Proxy
@@ -68,7 +68,7 @@ Start Dig
6868

6969
Stop Dig
7070
[Arguments] ${handle}
71-
${result} = Wait For Process ${handle} timeout=10 secs
71+
${result} = Wait For Process ${handle} timeout=15 secs
7272
Log ${result.stdout}
7373
Should Be Equal As Integers ${result.rc} 0
7474
Should Contain ${result.stdout} ANSWER SECTION

tests/robot/valgrind.supp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
ignore dlopen
3+
Memcheck:Leak
4+
match-leak-kinds: reachable
5+
...
6+
fun:_dl_open
7+
}
8+
{
9+
curl version ldap dependency
10+
Memcheck:Leak
11+
match-leak-kinds: reachable
12+
...
13+
fun:ldap_int_sasl_init
14+
fun:ldap_int_initialize
15+
fun:ldap_get_option
16+
fun:curl_version
17+
fun:main
18+
}

0 commit comments

Comments
 (0)