chore: Add cpplint to the CI.

This commit is contained in:
iphydf 2022-01-17 17:12:05 +00:00
parent e3d20afc6a
commit 7f94e411a9
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
26 changed files with 105 additions and 90 deletions

View File

@ -12,6 +12,7 @@ workflows:
# Static analysis
- clang-analyze
- clang-tidy
- cpplint
- infer
- static-analysis
@ -116,3 +117,15 @@ jobs:
other/analysis/run-clang-tidy ||
other/analysis/run-clang-tidy ||
other/analysis/run-clang-tidy
cpplint:
working_directory: ~/work
docker:
- image: ubuntu
steps:
- run: *apt_install
- run: apt-get install -y --no-install-recommends python3-pip
- checkout
- run: pip install cpplint
- run: other/analysis/run-cpplint

View File

@ -30,6 +30,7 @@ branches:
- "ci/circleci: asan"
- "ci/circleci: clang-analyze"
- "ci/circleci: clang-tidy"
- "ci/circleci: cpplint"
- "ci/circleci: infer"
- "ci/circleci: msan"
- "ci/circleci: static-analysis"

11
other/analysis/run-cpplint Executable file
View File

@ -0,0 +1,11 @@
#!/bin/sh
FILTER="-whitespace"
FILTER="$FILTER,-build/include_subdir"
FILTER="$FILTER,-readability/casting"
FILTER="$FILTER,-runtime/arrays"
FILTER="$FILTER,-runtime/printf"
FILTER="$FILTER,-runtime/int"
FILTER="$FILTER,-build/header_guard"
cpplint --filter="$FILTER" toxav/*.[ch] toxcore/*.[ch] toxencryptsave/*.[ch]

View File

@ -41,16 +41,14 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por
uint16_t default_ports[DEFAULT_TCP_RELAY_PORTS_COUNT] = {DEFAULT_TCP_RELAY_PORTS};
int i;
for (i = 0; i < DEFAULT_TCP_RELAY_PORTS_COUNT; i ++) {
for (int i = 0; i < DEFAULT_TCP_RELAY_PORTS_COUNT; ++i) {
log_write(LOG_LEVEL_INFO, "Port #%d: %u\n", i, default_ports[i]);
}
// similar procedure to the one of reading config file below
*tcp_relay_ports = (uint16_t *)malloc(DEFAULT_TCP_RELAY_PORTS_COUNT * sizeof(uint16_t));
for (i = 0; i < DEFAULT_TCP_RELAY_PORTS_COUNT; i ++) {
for (int i = 0; i < DEFAULT_TCP_RELAY_PORTS_COUNT; ++i) {
(*tcp_relay_ports)[*tcp_relay_port_count] = default_ports[i];
@ -61,7 +59,7 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por
continue;
}
(*tcp_relay_port_count) ++;
++*tcp_relay_port_count;
}
// the loop above skips invalid ports, so we adjust the allocated memory size
@ -90,9 +88,7 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por
*tcp_relay_ports = (uint16_t *)malloc(config_port_count * sizeof(uint16_t));
int i;
for (i = 0; i < config_port_count; i ++) {
for (int i = 0; i < config_port_count; ++i) {
config_setting_t *elem = config_setting_get_elem(ports_array, i);
if (elem == nullptr) {
@ -115,7 +111,7 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por
continue;
}
(*tcp_relay_port_count) ++;
++*tcp_relay_port_count;
}
// the loop above skips invalid ports, so we adjust the allocated memory size
@ -264,9 +260,8 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
log_write(LOG_LEVEL_ERROR, "No TCP ports could be read.\n");
} else {
log_write(LOG_LEVEL_INFO, "Read %d TCP ports:\n", *tcp_relay_port_count);
int i;
for (i = 0; i < *tcp_relay_port_count; i ++) {
for (int i = 0; i < *tcp_relay_port_count; ++i) {
log_write(LOG_LEVEL_INFO, "Port #%d: %u\n", i, (*tcp_relay_ports)[i]);
}
}
@ -300,9 +295,8 @@ static uint8_t *bootstrap_hex_string_to_bin(const char *hex_string)
uint8_t *ret = (uint8_t *)malloc(len);
const char *pos = hex_string;
size_t i;
for (i = 0; i < len; ++i, pos += 2) {
for (size_t i = 0; i < len; ++i, pos += 2) {
unsigned int val;
sscanf(pos, "%02x", &val);
ret[i] = val;
@ -411,7 +405,7 @@ next:
// though it's freed when the element is removed, so we free it right away in order to keep memory
// consumption minimal
config_setting_remove_elem(node_list, 0);
i++;
++i;
}
config_destroy(&cfg);

View File

@ -38,7 +38,7 @@
static void print_key(const uint8_t *client_id)
{
for (uint32_t j = 0; j < 32; j++) {
for (uint32_t j = 0; j < 32; ++j) {
printf("%02X", client_id[j]);
}
}
@ -80,17 +80,17 @@ static size_t match_hex_prefix(const uint8_t *key, const uint8_t *prefix, size_t
uint8_t diff = 0;
size_t i;
for (i = 0; i < prefix_len / 2; i++) {
for (i = 0; i < prefix_len / 2; ++i) {
diff = key[i] ^ prefix[i];
// First check high nibble
if ((diff & 0xF0) == 0) {
same++;
++same;
}
// Then low nibble
if (diff == 0) {
same++;
++same;
} else {
break;
}
@ -102,7 +102,7 @@ static size_t match_hex_prefix(const uint8_t *key, const uint8_t *prefix, size_t
// First check high nibble
if ((diff & 0xF0) == 0) {
same++;
++same;
}
}
@ -114,7 +114,7 @@ static void cracker_core(uint64_t range_start, uint64_t range_end, uint64_t rang
{
#pragma omp parallel for firstprivate(priv_key_shadow) shared(longest_match, range_start, range_end, range_offs, hex_prefix, prefix_chars_len) schedule(static) default(none)
for (uint64_t batch = range_start; batch < range_end; batch++) {
for (uint64_t batch = range_start; batch < range_end; ++batch) {
uint8_t *priv_key = (uint8_t *) priv_key_shadow;
/*
* We can't use the first and last bytes because they are masked in

View File

@ -34,7 +34,7 @@ int main(void)
sodium_bin2hex(public_key_str, sizeof(public_key_str), public_key, sizeof(public_key));
sodium_bin2hex(secret_key_str, sizeof(secret_key_str), secret_key, sizeof(secret_key));
for (size_t i = 0; i < sizeof(public_key_str); i ++) {
for (size_t i = 0; i < sizeof(public_key_str); ++i) {
public_key_str[i] = toupper(public_key_str[i]);
secret_key_str[i] = toupper(secret_key_str[i]);
}
@ -45,14 +45,14 @@ int main(void)
// calculate checksum for tox id printing
unsigned char checksum[2] = {0};
for (size_t i = 0; i < crypto_box_PUBLICKEYBYTES; i ++) {
for (size_t i = 0; i < crypto_box_PUBLICKEYBYTES; ++i) {
checksum[i % 2] ^= public_key[i];
}
char checksum_str[sizeof(checksum) * 2 + 1];
sodium_bin2hex(checksum_str, sizeof(checksum_str), checksum, sizeof(checksum));
for (size_t i = 0; i < sizeof(checksum_str); i ++) {
for (size_t i = 0; i < sizeof(checksum_str); ++i) {
checksum_str[i] = toupper(checksum_str[i]);
}

View File

@ -55,15 +55,14 @@ int main(int argc, char *argv[])
if (argc == 2 && argv[1][0] == 'g') {
crypto_sign_ed25519_keypair(pk, sk);
printf("Public key:\n");
int i;
for (i = 0; i < crypto_sign_ed25519_PUBLICKEYBYTES; i++) {
for (int i = 0; i < crypto_sign_ed25519_PUBLICKEYBYTES; ++i) {
printf("%02X", pk[i]);
}
printf("\nSecret key:\n");
for (i = 0; i < crypto_sign_ed25519_SECRETKEYBYTES; i++) {
for (int i = 0; i < crypto_sign_ed25519_SECRETKEYBYTES; ++i) {
printf("%02X", sk[i]);
}

View File

@ -47,9 +47,7 @@
static void print_key(unsigned char *key)
{
size_t i;
for (i = 0; i < crypto_box_PUBLICKEYBYTES; i++) {
for (size_t i = 0; i < crypto_box_PUBLICKEYBYTES; ++i) {
if (key[i] < 16) {
fprintf(stdout, "0");
}
@ -115,12 +113,11 @@ int main(int argc, char *argv[])
do {
#ifdef PRINT_TRIES_COUNT
tries ++;
++tries;
#endif
crypto_box_keypair(public_key, secret_key);
int i;
for (i = 0; i <= crypto_box_PUBLICKEYBYTES - len; i ++) {
for (int i = 0; i <= crypto_box_PUBLICKEYBYTES - len; ++i) {
if (memcmp(public_key + i, desired_bin, len) == 0) {
found = 1;
break;
@ -132,7 +129,7 @@ int main(int argc, char *argv[])
do {
#ifdef PRINT_TRIES_COUNT
tries ++;
++tries;
#endif
crypto_box_keypair(public_key, secret_key);
} while (memcmp(p, desired_bin, len) != 0);

View File

@ -5,15 +5,15 @@
#ifndef C_TOXCORE_TOXAV_AUDIO_H
#define C_TOXCORE_TOXAV_AUDIO_H
#include <opus.h>
#include <pthread.h>
#include "toxav.h"
#include "../toxcore/logger.h"
#include "../toxcore/util.h"
#include "rtp.h"
#include <opus.h>
#include <pthread.h>
#define AUDIO_JITTERBUFFER_COUNT 3
#define AUDIO_MAX_SAMPLE_RATE 48000
#define AUDIO_MAX_CHANNEL_COUNT 2

View File

@ -5,12 +5,12 @@
#ifndef C_TOXCORE_TOXAV_GROUPAV_H
#define C_TOXCORE_TOXAV_GROUPAV_H
#include "../toxcore/group.h"
#include "../toxcore/tox.h"
// Audio encoding/decoding
#include <opus.h>
#include "../toxcore/group.h"
#include "../toxcore/tox.h"
#define GROUP_AUDIO_PACKET_ID 192
// TODO(iphydf): Use this better typed one instead of the void-pointer one below.

View File

@ -4,14 +4,14 @@
*/
#include "msi.h"
#include "../toxcore/logger.h"
#include "../toxcore/util.h"
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include "../toxcore/logger.h"
#include "../toxcore/util.h"
#define MSI_MAXMSG_SIZE 256
/**

View File

@ -5,15 +5,15 @@
#ifndef C_TOXCORE_TOXAV_MSI_H
#define C_TOXCORE_TOXAV_MSI_H
#include <inttypes.h>
#include <pthread.h>
#include "audio.h"
#include "video.h"
#include "../toxcore/Messenger.h"
#include "../toxcore/logger.h"
#include <inttypes.h>
#include <pthread.h>
/**
* Error codes.
*/

View File

@ -5,10 +5,10 @@
*/
#include "ring_buffer.h"
#include "../toxcore/ccompat.h"
#include <stdlib.h>
#include "../toxcore/ccompat.h"
struct RingBuffer {
uint16_t size; /* Max size */
uint16_t start;

View File

@ -5,14 +5,14 @@
#ifndef C_TOXCORE_TOXAV_RTP_H
#define C_TOXCORE_TOXAV_RTP_H
#include <stdbool.h>
#include "bwcontroller.h"
#include "../toxcore/Messenger.h"
#include "../toxcore/logger.h"
#include "../toxcore/tox.h"
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif

View File

@ -4,6 +4,12 @@
*/
#include "toxav.h"
#include <assert.h>
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include "msi.h"
#include "rtp.h"
@ -12,12 +18,6 @@
#include "../toxcore/mono_time.h"
#include "../toxcore/util.h"
#include <assert.h>
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
// TODO(zoff99): don't hardcode this, let the application choose it
// VPX Info: Time to spend encoding, in microseconds (it's a *soft* deadline)
#define WANTED_MAX_ENCODER_FPS 40

View File

@ -5,13 +5,6 @@
#ifndef C_TOXCORE_TOXAV_VIDEO_H
#define C_TOXCORE_TOXAV_VIDEO_H
#include "toxav.h"
#include "../toxcore/logger.h"
#include "../toxcore/util.h"
#include "ring_buffer.h"
#include "rtp.h"
#include <vpx/vpx_decoder.h>
#include <vpx/vpx_encoder.h>
#include <vpx/vpx_image.h>
@ -19,9 +12,15 @@
#include <vpx/vp8cx.h>
#include <vpx/vp8dx.h>
#include <pthread.h>
#include "toxav.h"
#include "../toxcore/logger.h"
#include "../toxcore/util.h"
#include "ring_buffer.h"
#include "rtp.h"
typedef struct VCSession {
/* encoding */
vpx_codec_ctx_t encoder[1];

View File

@ -8,6 +8,10 @@
*/
#include "DHT.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "LAN_discovery.h"
#include "logger.h"
#include "mono_time.h"
@ -16,10 +20,6 @@
#include "state.h"
#include "util.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
/* The timeout after which a node is discarded completely. */
#define KILL_NODE_TIMEOUT (BAD_NODE_TIMEOUT + PING_INTERVAL)

View File

@ -9,14 +9,14 @@
#ifndef C_TOXCORE_TOXCORE_DHT_H
#define C_TOXCORE_TOXCORE_DHT_H
#include <stdbool.h>
#include "crypto_core.h"
#include "logger.h"
#include "mono_time.h"
#include "network.h"
#include "ping_array.h"
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif

View File

@ -31,14 +31,16 @@ typedef struct Packets_Array {
} Packets_Array;
typedef enum Crypto_Conn_State {
CRYPTO_CONN_FREE = 0, /* the connection slot is free. This value is 0 so it is valid after
* `crypto_memzero(...)` of the parent struct
*/
/* the connection slot is free. This value is 0 so it is valid after
* `crypto_memzero(...)` of the parent struct
*/
CRYPTO_CONN_FREE = 0,
CRYPTO_CONN_NO_CONNECTION, /* the connection is allocated, but not yet used */
CRYPTO_CONN_COOKIE_REQUESTING, /* we are sending cookie request packets */
CRYPTO_CONN_HANDSHAKE_SENT, /* we are sending handshake packets */
CRYPTO_CONN_NOT_CONFIRMED, /* we are sending handshake packets.
* we have received one from the other, but no data */
/* we are sending handshake packets.
* we have received one from the other, but no data */
CRYPTO_CONN_NOT_CONFIRMED,
CRYPTO_CONN_ESTABLISHED, /* the connection is established */
} Crypto_Conn_State;

View File

@ -9,13 +9,13 @@
#ifndef C_TOXCORE_TOXCORE_NET_CRYPTO_H
#define C_TOXCORE_TOXCORE_NET_CRYPTO_H
#include <pthread.h>
#include "DHT.h"
#include "LAN_discovery.h"
#include "TCP_connection.h"
#include "logger.h"
#include <pthread.h>
/*** Crypto payloads. */
/*** Ranges. */

View File

@ -1615,7 +1615,7 @@ size_t net_socket_data_recv_buffer(Socket sock)
#else
#ifdef OS_WIN32
unsigned long count = 0;
u_long count = 0;
ioctlsocket(sock.socket, FIONREAD, &count);
#else
int count = 0;

View File

@ -9,12 +9,12 @@
#ifndef C_TOXCORE_TOXCORE_NETWORK_H
#define C_TOXCORE_TOXCORE_NETWORK_H
#include "logger.h"
#include <stdbool.h> // bool
#include <stddef.h> // size_t
#include <stdint.h> // uint*_t
#include "logger.h"
#ifdef __cplusplus
extern "C" {
#endif

View File

@ -10,11 +10,11 @@
#ifndef C_TOXCORE_TOXCORE_PING_H
#define C_TOXCORE_TOXCORE_PING_H
#include <stdint.h>
#include "DHT.h"
#include "network.h"
#include <stdint.h>
typedef struct Ping Ping;
Ping *ping_new(const struct Mono_Time *mono_time, DHT *dht);

View File

@ -9,11 +9,11 @@
#ifndef C_TOXCORE_TOXCORE_PING_ARRAY_H
#define C_TOXCORE_TOXCORE_PING_ARRAY_H
#include "mono_time.h"
#include <stddef.h>
#include <stdint.h>
#include "mono_time.h"
#ifdef __cplusplus
extern "C" {
#endif

View File

@ -3,11 +3,11 @@
*/
#include "tox.h"
#include "ccompat.h"
#include <stdlib.h>
#include <string.h>
#include "ccompat.h"
#define SET_ERROR_PARAMETER(param, x) \
do { \
if (param) { \

View File

@ -6,9 +6,6 @@
/*
* Batch encryption functions.
*/
#include "../toxcore/ccompat.h"
#include "../toxcore/crypto_core.h"
#include "defines.h"
#include "toxencryptsave.h"
#include <sodium.h>
@ -16,7 +13,10 @@
#include <stdlib.h>
#include <string.h>
//!TOKSTYLE-
#include "../toxcore/ccompat.h"
#include "../toxcore/crypto_core.h"
#include "defines.h"
static_assert(TOX_PASS_SALT_LENGTH == crypto_pwhash_scryptsalsa208sha256_SALTBYTES,
"TOX_PASS_SALT_LENGTH is assumed to be equal to crypto_pwhash_scryptsalsa208sha256_SALTBYTES");
static_assert(TOX_PASS_KEY_LENGTH == CRYPTO_SHARED_KEY_SIZE,
@ -24,7 +24,6 @@ static_assert(TOX_PASS_KEY_LENGTH == CRYPTO_SHARED_KEY_SIZE,
static_assert(TOX_PASS_ENCRYPTION_EXTRA_LENGTH == (crypto_box_MACBYTES + crypto_box_NONCEBYTES +
crypto_pwhash_scryptsalsa208sha256_SALTBYTES + TOX_ENC_SAVE_MAGIC_LENGTH),
"TOX_PASS_ENCRYPTION_EXTRA_LENGTH is assumed to be equal to (crypto_box_MACBYTES + crypto_box_NONCEBYTES + crypto_pwhash_scryptsalsa208sha256_SALTBYTES + TOX_ENC_SAVE_MAGIC_LENGTH)");
//!TOKSTYLE+
#define SET_ERROR_PARAMETER(param, x) \
do { \