Skip to content

Commit bc62510

Browse files
committed
Merge branch 'tux3-cppcheck-style'
2 parents 760333b + 3044bd8 commit bc62510

File tree

8 files changed

+29
-27
lines changed

8 files changed

+29
-27
lines changed

testing/nTox.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -531,11 +531,11 @@ void line_eval(Tox *m, char *line)
531531
}
532532
}
533533
} else if (inpt_command == 't') {
534-
char msg[512];
535534
char *posi[1];
536535
int friendnum = strtoul(line + prompt_offset, posi, 0);
537536

538537
if (**posi != 0) {
538+
char msg[512];
539539
sprintf(msg, "[t] Sending file %s to friendnum %u filenumber is %i (-1 means failure)", *posi + 1, friendnum,
540540
add_filesender(m, friendnum, *posi + 1));
541541
new_lines(msg);
@@ -634,7 +634,7 @@ void line_eval(Tox *m, char *line)
634634
* otherwise turns spaces into newlines if possible */
635635
void wrap(char output[STRING_LENGTH_WRAPPED], char input[STRING_LENGTH], int line_width)
636636
{
637-
size_t i, k, m, len = strlen(input);
637+
size_t i, len = strlen(input);
638638

639639
if ((line_width < 4) || (len < (size_t)line_width)) {
640640
/* if line_width ridiculously tiny, it's not worth the effort */
@@ -652,8 +652,8 @@ void wrap(char output[STRING_LENGTH_WRAPPED], char input[STRING_LENGTH], int lin
652652

653653
for (i = line_width; i < len; i += line_width) {
654654
/* look backward for a space to expand/turn into a new line */
655-
k = i;
656-
m = i - line_width;
655+
size_t k = i;
656+
size_t m = i - line_width;
657657

658658
while (input[k] != ' ' && k > m) {
659659
k--;
@@ -837,7 +837,6 @@ void do_refresh()
837837
{
838838
int count = 0;
839839
char wrap_output[STRING_LENGTH_WRAPPED];
840-
int L;
841840
int i;
842841

843842
for (i = 0; i < HISTORY; i++) {
@@ -846,7 +845,7 @@ void do_refresh()
846845
else
847846
wrap(wrap_output, lines[i], x);
848847

849-
L = count_lines(wrap_output);
848+
int L = count_lines(wrap_output);
850849
count = count + L;
851850

852851
if (count < y) {
@@ -921,11 +920,10 @@ static char *data_file_name = NULL;
921920
static int load_data(Tox *m)
922921
{
923922
FILE *data_file = fopen(data_file_name, "r");
924-
size_t size = 0;
925923

926924
if (data_file) {
927925
fseek(data_file, 0, SEEK_END);
928-
size = ftell(data_file);
926+
size_t size = ftell(data_file);
929927
rewind(data_file);
930928

931929
uint8_t data[size];
@@ -1215,7 +1213,6 @@ int main(int argc, char *argv[])
12151213
exit(1);
12161214

12171215
int on = 0;
1218-
int c = 0;
12191216
char *filename = "data";
12201217
char idstring[200] = {0};
12211218
Tox *m;
@@ -1282,8 +1279,6 @@ int main(int argc, char *argv[])
12821279

12831280
time_t timestamp0 = time(NULL);
12841281

1285-
uint8_t pollok = 0;
1286-
12871282
while (1) {
12881283
if (on == 0) {
12891284
if (tox_isconnected(m)) {
@@ -1305,7 +1300,7 @@ int main(int argc, char *argv[])
13051300
tox_do(m);
13061301
do_refresh();
13071302

1308-
c = timeout_getch(m);
1303+
int c = timeout_getch(m);
13091304

13101305
if (c == ERR || c == 27)
13111306
continue;

toxav/media.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,11 @@ void queue(JitterBuffer *q, RTPMessage *pk)
153153
q->queue[q->rear] = pk;
154154

155155
int a;
156-
int b;
157156
int j;
158157
a = q->rear;
159158

160159
for (j = 0; j < q->size - 1; ++j) {
161-
b = a - 1;
160+
int b = a - 1;
162161

163162
if (b < 0)
164163
b += q->capacity;

toxav/msi.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,11 @@ MSIMessage *parse_message ( const uint8_t *data, uint16_t length )
431431
*/
432432
int stringify_message(MSIMessage *msg, char *dest)
433433
{
434+
// THIS CODE HAS NO EFFECT, AND THE ARGUMENTS ARE NOT MODIFIED
435+
#if 0
436+
434437
#define HDR_TO_STR(__dest, __hdr) if (__hdr.header_value) {\
435-
char nltstr[MSI_MAXMSG_SIZE]; memset(nltstr, '\0', MSI_MAXMSG_SIZE); int i = 0; \
438+
char nltstr[MSI_MAXMSG_SIZE]; memset(nltstr+__hdr.size, '\0', MSI_MAXMSG_SIZE-__hdr.size); int i = 0; \
436439
for ( ; i < __hdr.size; i ++) nltstr[i] = (char)__hdr.header_value[i]; \
437440
}
438441

@@ -452,6 +455,7 @@ int stringify_message(MSIMessage *msg, char *dest)
452455
// U8_TO_NLTCHAR(msg->version.header_value, msg->version.size, nltstr, MSI_MAXMSG_SIZE);
453456
// sprintf(dest, "Version: %s\n", nltstr);
454457
// }
458+
#endif
455459

456460
return 0;
457461
}

toxav/toxav.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -473,16 +473,20 @@ inline__ int toxav_recv_video ( ToxAv *av, int32_t call_index, vpx_image_t **out
473473
if (cii(call_index, av->msi_session)) return ErrorNoCall;
474474

475475
uint8_t packet [RTP_PAYLOAD_SIZE];
476-
int recved_size = 0;
477-
int rc;
478476
CallSpecific *call = &av->calls[call_index];
479477

478+
int recved_size = 0;
479+
480480
do {
481481
recved_size = toxav_recv_rtp_payload(av, call_index, TypeVideo, packet);
482482

483-
if (recved_size > 0 && ( rc = vpx_codec_decode(&call->cs->v_decoder, packet, recved_size, NULL, 0) ) != VPX_CODEC_OK) {
484-
LOGGER_ERROR("Error decoding video: %s\n", vpx_codec_err_to_string(rc));
485-
return ErrorInternal;
483+
if (recved_size > 0) {
484+
int rc = vpx_codec_decode(&call->cs->v_decoder, packet, recved_size, NULL, 0);
485+
486+
if (rc != VPX_CODEC_OK) {
487+
LOGGER_ERROR("Error decoding video: %s\n", vpx_codec_err_to_string(rc));
488+
return ErrorInternal;
489+
}
486490
}
487491

488492
} while (recved_size > 0);

toxcore/DHT.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2221,11 +2221,11 @@ uint16_t random_nodes_path(DHT *dht, Node_format *nodes, uint16_t max_num)
22212221
return 0;
22222222

22232223
uint16_t count = 0;
2224-
Client_data *list = NULL;
22252224
uint16_t list_size = 0;
22262225
uint32_t i;
22272226

22282227
for (i = 0; i < max_num; ++i) {
2228+
Client_data *list = NULL;
22292229
uint16_t rand_num = rand() % (dht->num_friends);
22302230
list = dht->friends_list[rand_num].client_list;
22312231
list_size = MAX_FRIEND_CLIENTS;

toxcore/assoc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -886,15 +886,15 @@ void do_Assoc(Assoc *assoc, DHT *dht)
886886
* send getnode() requests to both */
887887
uint8_t *target_id = NULL;
888888
Client_entry *heard = NULL, *seen = NULL;
889-
size_t i, k, m, bckt;
889+
size_t i, k, m;
890890

891891
for (i = 1; i < assoc->candidates_bucket_count; i++) {
892892
if (i % 2)
893893
k = - (i >> 1);
894894
else
895895
k = i >> 1;
896896

897-
bckt = (candidate + k) % assoc->candidates_bucket_count;
897+
size_t bckt = (candidate + k) % assoc->candidates_bucket_count;
898898

899899
for (m = 0; m < assoc->candidates_bucket_size; m++)
900900
if (assoc->candidates[bckt].list[m].hash) {

toxcore/network.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,10 +596,10 @@ Networking_Core *new_networking(IP ip, uint16_t port)
596596
*/
597597
uint16_t port_to_try = port;
598598
*portptr = htons(port_to_try);
599-
int tries, res;
599+
int tries;
600600

601601
for (tries = TOX_PORTRANGE_FROM; tries <= TOX_PORTRANGE_TO; tries++) {
602-
res = bind(temp->sock, (struct sockaddr *)&addr, addrsize);
602+
int res = bind(temp->sock, (struct sockaddr *)&addr, addrsize);
603603

604604
if (!res) {
605605
temp->port = *portptr;

toxcore/onion_client.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum)
10011001
if (count < (uint32_t)rand() % MAX_ONION_CLIENTS) {
10021002
Node_format nodes_list[MAX_SENT_NODES];
10031003
uint32_t num_nodes = get_close_nodes(onion_c->dht, onion_c->friends_list[friendnum].real_client_id, nodes_list,
1004-
rand() % 2 ? AF_INET : AF_INET6, 1, 0);
1004+
(rand() % 2) ? AF_INET : AF_INET6, 1, 0);
10051005

10061006
for (i = 0; i < num_nodes; ++i)
10071007
client_send_announce_request(onion_c, friendnum + 1, nodes_list[i].ip_port, nodes_list[i].client_id, 0, ~0);
@@ -1083,7 +1083,7 @@ static void do_announce(Onion_Client *onion_c)
10831083
if (count < (uint32_t)rand() % MAX_ONION_CLIENTS) {
10841084
Node_format nodes_list[MAX_SENT_NODES];
10851085
uint32_t num_nodes = get_close_nodes(onion_c->dht, onion_c->c->self_public_key, nodes_list,
1086-
rand() % 2 ? AF_INET : AF_INET6, 1, 0);
1086+
(rand() % 2) ? AF_INET : AF_INET6, 1, 0);
10871087

10881088
for (i = 0; i < num_nodes; ++i) {
10891089
client_send_announce_request(onion_c, 0, nodes_list[i].ip_port, nodes_list[i].client_id, 0, ~0);

0 commit comments

Comments
 (0)