Skip to content

Commit b7404f2

Browse files
committed
cleanup: Remove implicit bool conversions.
1 parent 4e2dba4 commit b7404f2

File tree

18 files changed

+140
-140
lines changed

18 files changed

+140
-140
lines changed

other/DHT_bootstrap.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ static void print_log(void *context, Logger_Level level, const char *file, int l
125125

126126
int main(int argc, char *argv[])
127127
{
128-
if (argc == 2 && !tox_strncasecmp(argv[1], "-h", 3)) {
128+
if (argc == 2 && tox_strncasecmp(argv[1], "-h", 3) == 0) {
129129
printf("Usage (connected) : %s [--ipv4|--ipv6] IP PORT KEY\n", argv[0]);
130130
printf("Usage (unconnected): %s [--ipv4|--ipv6]\n", argv[0]);
131131
return 0;
@@ -167,7 +167,7 @@ int main(int argc, char *argv[])
167167
bootstrap_set_callbacks(dht_get_net(dht), (uint32_t)DAEMON_VERSION_NUMBER, (const uint8_t *) motd_str, strlen(motd_str) + 1);
168168
#endif
169169

170-
if (!(onion && forwarding && onion_a)) {
170+
if (onion == nullptr || forwarding == nullptr || onion_a == nullptr) {
171171
printf("Something failed to initialize.\n");
172172
// cppcheck-suppress resourceLeak
173173
return 1;
@@ -229,8 +229,8 @@ int main(int argc, char *argv[])
229229
const uint16_t port = net_htons((uint16_t)port_conv);
230230

231231
uint8_t *bootstrap_key = hex_string_to_bin(argv[argvoffset + 3]);
232-
int res = dht_bootstrap_from_address(dht, argv[argvoffset + 1],
233-
ipv6enabled, port, bootstrap_key);
232+
const bool res = dht_bootstrap_from_address(dht, argv[argvoffset + 1],
233+
ipv6enabled, port, bootstrap_key);
234234
free(bootstrap_key);
235235

236236
if (!res) {
@@ -239,17 +239,17 @@ int main(int argc, char *argv[])
239239
}
240240
}
241241

242-
int is_waiting_for_dht_connection = 1;
242+
bool is_waiting_for_dht_connection = true;
243243

244244
uint64_t last_lan_discovery = 0;
245245
const Broadcast_Info *broadcast = lan_discovery_init(ns);
246246

247-
while (1) {
247+
while (true) {
248248
mono_time_update(mono_time);
249249

250250
if (is_waiting_for_dht_connection && dht_isconnected(dht)) {
251251
printf("Connected to other bootstrap node successfully.\n");
252-
is_waiting_for_dht_connection = 0;
252+
is_waiting_for_dht_connection = false;
253253
}
254254

255255
do_dht(dht);

other/bootstrap_daemon/src/config.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por
134134
}
135135
}
136136

137-
int get_general_config(const char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port,
138-
int *enable_ipv6, int *enable_ipv4_fallback, int *enable_lan_discovery, int *enable_tcp_relay,
139-
uint16_t **tcp_relay_ports, int *tcp_relay_port_count, int *enable_motd, char **motd)
137+
bool get_general_config(const char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port,
138+
int *enable_ipv6, int *enable_ipv4_fallback, int *enable_lan_discovery, int *enable_tcp_relay,
139+
uint16_t **tcp_relay_ports, int *tcp_relay_port_count, int *enable_motd, char **motd)
140140
{
141141
config_t cfg;
142142

@@ -156,7 +156,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
156156
if (config_read_file(&cfg, cfg_file_path) == CONFIG_FALSE) {
157157
log_write(LOG_LEVEL_ERROR, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg));
158158
config_destroy(&cfg);
159-
return 0;
159+
return false;
160160
}
161161

162162
// Get port
@@ -223,7 +223,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
223223
*enable_tcp_relay = DEFAULT_ENABLE_TCP_RELAY;
224224
}
225225

226-
if (*enable_tcp_relay) {
226+
if (*enable_tcp_relay != 0) {
227227
parse_tcp_relay_ports_config(&cfg, tcp_relay_ports, tcp_relay_port_count);
228228
} else {
229229
*tcp_relay_port_count = 0;
@@ -237,7 +237,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
237237
*enable_motd = DEFAULT_ENABLE_MOTD;
238238
}
239239

240-
if (*enable_motd) {
240+
if (*enable_motd != 0) {
241241
// Get MOTD
242242
const char *tmp_motd;
243243

@@ -259,14 +259,14 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
259259
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_PID_FILE_PATH, *pid_file_path);
260260
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_KEYS_FILE_PATH, *keys_file_path);
261261
log_write(LOG_LEVEL_INFO, "'%s': %d\n", NAME_PORT, *port);
262-
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_IPV6, *enable_ipv6 ? "true" : "false");
263-
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_IPV4_FALLBACK, *enable_ipv4_fallback ? "true" : "false");
264-
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, *enable_lan_discovery ? "true" : "false");
262+
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_IPV6, *enable_ipv6 != 0 ? "true" : "false");
263+
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_IPV4_FALLBACK, *enable_ipv4_fallback != 0 ? "true" : "false");
264+
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, *enable_lan_discovery != 0 ? "true" : "false");
265265

266-
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_TCP_RELAY, *enable_tcp_relay ? "true" : "false");
266+
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_TCP_RELAY, *enable_tcp_relay != 0 ? "true" : "false");
267267

268268
// Show info about tcp ports only if tcp relay is enabled
269-
if (*enable_tcp_relay) {
269+
if (*enable_tcp_relay != 0) {
270270
if (*tcp_relay_port_count == 0) {
271271
log_write(LOG_LEVEL_ERROR, "No TCP ports could be read.\n");
272272
} else {
@@ -278,13 +278,13 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
278278
}
279279
}
280280

281-
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_MOTD, *enable_motd ? "true" : "false");
281+
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_MOTD, *enable_motd != 0 ? "true" : "false");
282282

283-
if (*enable_motd) {
283+
if (*enable_motd != 0) {
284284
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_MOTD, *motd);
285285
}
286286

287-
return 1;
287+
return true;
288288
}
289289

290290
/**
@@ -316,7 +316,7 @@ static uint8_t *bootstrap_hex_string_to_bin(const char *hex_string)
316316
return ret;
317317
}
318318

319-
int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6)
319+
bool bootstrap_from_config(const char *cfg_file_path, DHT *dht, bool enable_ipv6)
320320
{
321321
const char *const NAME_BOOTSTRAP_NODES = "bootstrap_nodes";
322322

@@ -331,7 +331,7 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6)
331331
if (config_read_file(&cfg, cfg_file_path) == CONFIG_FALSE) {
332332
log_write(LOG_LEVEL_ERROR, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg));
333333
config_destroy(&cfg);
334-
return 0;
334+
return false;
335335
}
336336

337337
config_setting_t *node_list = config_lookup(&cfg, NAME_BOOTSTRAP_NODES);
@@ -340,13 +340,13 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6)
340340
log_write(LOG_LEVEL_WARNING, "No '%s' setting in the configuration file. Skipping bootstrapping.\n",
341341
NAME_BOOTSTRAP_NODES);
342342
config_destroy(&cfg);
343-
return 1;
343+
return true;
344344
}
345345

346346
if (config_setting_length(node_list) == 0) {
347347
log_write(LOG_LEVEL_WARNING, "No bootstrap nodes found. Skipping bootstrapping.\n");
348348
config_destroy(&cfg);
349-
return 1;
349+
return true;
350350
}
351351

352352
int bs_port;
@@ -357,15 +357,15 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6)
357357

358358
int i = 0;
359359

360-
while (config_setting_length(node_list)) {
361-
int address_resolved;
360+
while (config_setting_length(node_list) != 0) {
361+
bool address_resolved;
362362
uint8_t *bs_public_key_bin;
363363

364364
node = config_setting_get_elem(node_list, 0);
365365

366366
if (node == nullptr) {
367367
config_destroy(&cfg);
368-
return 0;
368+
return false;
369369
}
370370

371371
// Check that all settings are present
@@ -421,5 +421,5 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6)
421421

422422
config_destroy(&cfg);
423423

424-
return 1;
424+
return true;
425425
}

other/bootstrap_daemon/src/config.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@
1919
* also, iff `tcp_relay_ports_count` > 0, then you are responsible for freeing `tcp_relay_ports`
2020
* and also `motd` iff `enable_motd` is set.
2121
*
22-
* @return 1 on success,
23-
* 0 on failure, doesn't modify any data pointed by arguments.
22+
* @return true on success,
23+
* false on failure, doesn't modify any data pointed by arguments.
2424
*/
25-
int get_general_config(const char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port,
26-
int *enable_ipv6, int *enable_ipv4_fallback, int *enable_lan_discovery, int *enable_tcp_relay,
27-
uint16_t **tcp_relay_ports, int *tcp_relay_port_count, int *enable_motd, char **motd);
25+
bool get_general_config(const char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port,
26+
int *enable_ipv6, int *enable_ipv4_fallback, int *enable_lan_discovery, int *enable_tcp_relay,
27+
uint16_t **tcp_relay_ports, int *tcp_relay_port_count, int *enable_motd, char **motd);
2828

2929
/**
3030
* Bootstraps off nodes listed in the config file.
3131
*
32-
* @return 1 on success, some or no bootstrap nodes were added
33-
* 0 on failure, an error occurred while parsing the config file.
32+
* @return true on success, some or no bootstrap nodes were added
33+
* false on failure, an error occurred while parsing the config file.
3434
*/
35-
int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6);
35+
bool bootstrap_from_config(const char *cfg_file_path, DHT *dht, bool enable_ipv6);
3636

3737
#endif // C_TOXCORE_OTHER_BOOTSTRAP_DAEMON_SRC_CONFIG_H

0 commit comments

Comments
 (0)