Skip to content

Commit eab7050

Browse files
committed
gcc-10 and clang(-tidy)-12 warning fixes with github workflows
Also run jobs on every push and pull request, so in case of forks also the side branches can be tested
1 parent 750c4db commit eab7050

File tree

9 files changed

+24
-20
lines changed

9 files changed

+24
-20
lines changed

.github/workflows/cmake.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
11
name: CMake
22

3-
on:
4-
push:
5-
branches: [ master ]
6-
pull_request:
7-
branches: [ master ]
3+
on: [push, pull_request]
84

95
jobs:
106
build:
117
# The CMake configure and build commands are platform agnostic and should work equally
128
# well on Windows or Mac. You can convert this to a matrix build if you need
139
# cross-platform coverage.
1410
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
15-
runs-on: ubuntu-latest
11+
runs-on: ubuntu-20.04
1612

1713
strategy:
1814
matrix:
19-
compiler: [gcc, clang]
15+
compiler: [gcc-10, clang-12]
2016

2117
steps:
2218
- uses: actions/checkout@v2
23-
19+
2420
- name: Update APT
2521
run: sudo apt-get update
2622

2723
- name: Setup Dependencies
28-
run: sudo apt-get install cmake libc-ares-dev libcurl4-openssl-dev libev-dev build-essential clang clang-tidy
24+
run: sudo apt-get install cmake libc-ares-dev libcurl4-openssl-dev libev-dev build-essential clang-tidy-12 ${{ matrix.compiler }}
25+
26+
- name: Set clang-tidy
27+
run: sudo update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-12 100
2928

3029
- name: Configure CMake
3130
env:

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ if(NOT CLANG_TIDY_EXE)
5858
message(STATUS "clang-tidy not found.")
5959
else()
6060
message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
61-
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")
61+
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")
6262
endif()
6363

6464
# The main binary

src/dns_poller.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ static ev_tstamp get_timeout(dns_poller_t *d)
9797
static struct timeval max_tv = {.tv_sec = 5, .tv_usec = 0};
9898
struct timeval tv;
9999
struct timeval *tvp = ares_timeout(d->ares, &max_tv, &tv);
100+
// NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
100101
ev_tstamp after = tvp->tv_sec + tvp->tv_usec * 1e-6;
101102
return after ? after : 0.1;
102103
}

src/dns_server.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ static void watcher_cb(struct ev_loop __attribute__((unused)) *loop,
6565
struct sockaddr_storage raddr;
6666
/* recvfrom can write to addrlen */
6767
socklen_t tmp_addrlen = d->addrlen;
68-
int len = recvfrom(w->fd, buf, REQUEST_MAX, 0, (struct sockaddr*)&raddr,
69-
&tmp_addrlen);
68+
ssize_t len = recvfrom(w->fd, buf, REQUEST_MAX, 0, (struct sockaddr*)&raddr,
69+
&tmp_addrlen);
7070
if (len < 0) {
7171
ELOG("recvfrom failed: %s", strerror(errno));
7272
return;
@@ -96,7 +96,7 @@ void dns_server_init(dns_server_t *d, struct ev_loop *loop,
9696
}
9797

9898
void dns_server_respond(dns_server_t *d, struct sockaddr *raddr, char *buf,
99-
int blen) {
99+
size_t blen) {
100100
ssize_t len = sendto(d->sock, buf, blen, 0, raddr, d->addrlen);
101101
if(len == -1) {
102102
DLOG("sendto failed: %s", strerror(errno));

src/dns_server.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void dns_server_init(dns_server_t *d, struct ev_loop *loop,
2626

2727
// Sends a DNS response 'buf' of length 'blen' to 'raddr'.
2828
void dns_server_respond(dns_server_t *d, struct sockaddr *raddr, char *buf,
29-
int blen);
29+
size_t blen);
3030

3131
void dns_server_stop(dns_server_t *d);
3232

src/https_client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <stdio.h> // NOLINT(llvmlibc-restrict-system-libc-headers)
77
#include <string.h> // NOLINT(llvmlibc-restrict-system-libc-headers)
88
#include <sys/socket.h> // NOLINT(llvmlibc-restrict-system-libc-headers)
9-
#include <unistd.h>
9+
#include <unistd.h> // NOLINT(llvmlibc-restrict-system-libc-headers)
1010

1111
#include "https_client.h"
1212
#include "logging.h"

src/logging.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ static FILE *logf = NULL; // NOLINT(cppcoreguidelines-avoid-non-const-glo
1212
static int loglevel = LOG_ERROR; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
1313
static ev_timer logging_timer; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
1414

15-
static const char *SeverityStr[] = {
15+
static const char * const SeverityStr[] = {
1616
"[D]",
1717
"[I]",
1818
"[W]",
@@ -63,6 +63,7 @@ int logging_debug_enabled() {
6363
return loglevel <= LOG_DEBUG;
6464
}
6565

66+
// NOLINTNEXTLINE(misc-no-recursion) because of severity check
6667
void _log(const char *file, int line, int severity, const char *fmt, ...) {
6768
if (severity < loglevel) {
6869
return;

src/main.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,23 @@
1717
#include "stat.h"
1818

1919
// Holds app state required for dns_server_cb.
20+
// NOLINTNEXTLINE(altera-struct-pack-align)
2021
typedef struct {
2122
https_client_t *https_client;
2223
struct curl_slist *resolv;
2324
const char *resolver_url;
24-
uint8_t using_dns_poller;
2525
stat_t *stat;
26+
uint8_t using_dns_poller;
2627
} app_state_t;
2728

29+
// NOLINTNEXTLINE(altera-struct-pack-align)
2830
typedef struct {
29-
uint16_t tx_id;
30-
struct sockaddr_storage raddr;
3131
dns_server_t *dns_server;
3232
char* dns_req;
33-
ev_tstamp start_tstamp;
3433
stat_t *stat;
34+
ev_tstamp start_tstamp;
35+
uint16_t tx_id;
36+
struct sockaddr_storage raddr;
3537
} request_t;
3638

3739
// Very very basic hostname parsing.

src/stat.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ void stat_request_end(stat_t *s, size_t resp_len, ev_tstamp latency)
5555
if (resp_len) {
5656
s->responses_size += resp_len;
5757
s->responses++;
58+
// NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
5859
s->query_times_sum += (latency * 1000);
5960
}
6061
}

0 commit comments

Comments
 (0)