Remove redundant casts to the same type.

Also removed an unused identifier in messenger_test.c.
This commit is contained in:
iphydf 2018-07-19 22:05:43 +00:00
parent adb12d5340
commit 7c2b95ef5e
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
3 changed files with 20 additions and 27 deletions

View File

@ -36,17 +36,12 @@
static bool enable_broken_tests = false; static bool enable_broken_tests = false;
static const char *friend_id_str = "e4b3d5030bc99494605aecc33ceec8875640c1d74aa32790e821b17e98771c4a00000000f1db"; static const char *friend_id_str = "e4b3d5030bc99494605aecc33ceec8875640c1d74aa32790e821b17e98771c4a00000000f1db";
static const char *good_id_str = "d3f14b6d384d8f5f2a66cff637e69f28f539c5de61bc29744785291fa4ef4d64";
static const char *bad_id_str = "9B569D14ff637e69f2";
/* in case we need more than one ID for a test */ static uint8_t *friend_id = nullptr;
static const char *good_id_a_str = "DB9B569D14850ED8364C3744CAC2C8FF78985D213E980C7C508D0E91E8E45441"; static uint8_t *good_id = nullptr;
static const char *good_id_b_str = "d3f14b6d384d8f5f2a66cff637e69f28f539c5de61bc29744785291fa4ef4d64"; static uint8_t *bad_id = nullptr;
static const char *bad_id_str = "9B569D14ff637e69f2";
static unsigned char *friend_id = nullptr;
static unsigned char *good_id_a = nullptr;
static unsigned char *good_id_b = nullptr;
static unsigned char *bad_id = nullptr;
static int friend_id_num = 0; static int friend_id_num = 0;
@ -146,24 +141,24 @@ START_TEST(test_m_addfriend)
+ crypto_box_ZEROBYTES + 100); + crypto_box_ZEROBYTES + 100);
/* TODO(irungentoo): Update this properly to latest master */ /* TODO(irungentoo): Update this properly to latest master */
if (m_addfriend(m, (const uint8_t *)friend_id, (const uint8_t *)good_data, really_bad_len) != FAERR_TOOLONG) { if (m_addfriend(m, friend_id, (const uint8_t *)good_data, really_bad_len) != FAERR_TOOLONG) {
ck_abort_msg("m_addfriend did NOT catch the following length: %d\n", really_bad_len); ck_abort_msg("m_addfriend did NOT catch the following length: %d\n", really_bad_len);
} }
/* this will return an error if the original m_addfriend_norequest() failed */ /* this will return an error if the original m_addfriend_norequest() failed */
if (m_addfriend(m, (const uint8_t *)friend_id, (const uint8_t *)good_data, good_len) != FAERR_ALREADYSENT) { if (m_addfriend(m, friend_id, (const uint8_t *)good_data, good_len) != FAERR_ALREADYSENT) {
ck_abort_msg("m_addfriend did NOT catch adding a friend we already have.\n" ck_abort_msg("m_addfriend did NOT catch adding a friend we already have.\n"
"(this can be caused by the error of m_addfriend_norequest in" "(this can be caused by the error of m_addfriend_norequest in"
" the beginning of the suite)\n"); " the beginning of the suite)\n");
} }
if (m_addfriend(m, (const uint8_t *)good_id_b, (const uint8_t *)bad_data, bad_len) != FAERR_NOMESSAGE) { if (m_addfriend(m, good_id, (const uint8_t *)bad_data, bad_len) != FAERR_NOMESSAGE) {
ck_abort_msg("m_addfriend did NOT catch the following length: %d\n", bad_len); ck_abort_msg("m_addfriend did NOT catch the following length: %d\n", bad_len);
} }
/* this should REALLY return an error */ /* this should REALLY return an error */
/* TODO(irungentoo): validate client_id in m_addfriend? */ /* TODO(irungentoo): validate client_id in m_addfriend? */
if (m_addfriend(m, (const uint8_t *)bad_id, (const uint8_t *)good_data, good_len) >= 0) { if (m_addfriend(m, bad_id, (const uint8_t *)good_data, good_len) >= 0) {
ck_abort_msg("The following ID passed through " ck_abort_msg("The following ID passed through "
"m_addfriend without an error:\n'%s'\n", bad_id_str); "m_addfriend without an error:\n'%s'\n", bad_id_str);
} }
@ -348,8 +343,7 @@ int main(void)
setvbuf(stdout, nullptr, _IONBF, 0); setvbuf(stdout, nullptr, _IONBF, 0);
friend_id = hex_string_to_bin(friend_id_str); friend_id = hex_string_to_bin(friend_id_str);
good_id_a = hex_string_to_bin(good_id_a_str); good_id = hex_string_to_bin(good_id_str);
good_id_b = hex_string_to_bin(good_id_b_str);
bad_id = hex_string_to_bin(bad_id_str); bad_id = hex_string_to_bin(bad_id_str);
/* IPv6 status from global define */ /* IPv6 status from global define */
@ -361,13 +355,13 @@ int main(void)
m = new_messenger(&options, nullptr); m = new_messenger(&options, nullptr);
/* setup a default friend and friendnum */ /* setup a default friend and friendnum */
if (m_addfriend_norequest(m, (uint8_t *)friend_id) < 0) { if (m_addfriend_norequest(m, friend_id) < 0) {
fputs("m_addfriend_norequest() failed on a valid ID!\n" fputs("m_addfriend_norequest() failed on a valid ID!\n"
"this was CRITICAL to the test, and the build WILL fail.\n" "this was CRITICAL to the test, and the build WILL fail.\n"
"the tests will continue now...\n\n", stderr); "the tests will continue now...\n\n", stderr);
} }
if ((friend_id_num = getfriend_id(m, (uint8_t *)friend_id)) < 0) { if ((friend_id_num = getfriend_id(m, friend_id)) < 0) {
fputs("getfriend_id() failed on a valid ID!\n" fputs("getfriend_id() failed on a valid ID!\n"
"this was CRITICAL to the test, and the build WILL fail.\n" "this was CRITICAL to the test, and the build WILL fail.\n"
"the tests will continue now...\n\n", stderr); "the tests will continue now...\n\n", stderr);
@ -382,8 +376,7 @@ int main(void)
srunner_free(test_runner); srunner_free(test_runner);
free(friend_id); free(friend_id);
free(good_id_a); free(good_id);
free(good_id_b);
free(bad_id); free(bad_id);
kill_messenger(m); kill_messenger(m);

View File

@ -138,7 +138,7 @@ int msi_kill(MSISession *session, const Logger *log)
return -1; return -1;
} }
m_callback_msi_packet((struct Messenger *) session->messenger, nullptr, nullptr); m_callback_msi_packet(session->messenger, nullptr, nullptr);
if (pthread_mutex_trylock(session->mutex) != 0) { if (pthread_mutex_trylock(session->mutex) != 0) {
LOGGER_ERROR(session->messenger->log, "Failed to acquire lock on msi mutex"); LOGGER_ERROR(session->messenger->log, "Failed to acquire lock on msi mutex");

View File

@ -268,7 +268,7 @@ BASE_CLEANUP_1:
vpx_codec_destroy(vc->decoder); vpx_codec_destroy(vc->decoder);
BASE_CLEANUP: BASE_CLEANUP:
pthread_mutex_destroy(vc->queue_mutex); pthread_mutex_destroy(vc->queue_mutex);
rb_kill((RingBuffer *)vc->vbuf_raw); rb_kill(vc->vbuf_raw);
free(vc); free(vc);
return nullptr; return nullptr;
} }
@ -283,11 +283,11 @@ void vc_kill(VCSession *vc)
vpx_codec_destroy(vc->decoder); vpx_codec_destroy(vc->decoder);
void *p; void *p;
while (rb_read((RingBuffer *)vc->vbuf_raw, &p)) { while (rb_read(vc->vbuf_raw, &p)) {
free(p); free(p);
} }
rb_kill((RingBuffer *)vc->vbuf_raw); rb_kill(vc->vbuf_raw);
pthread_mutex_destroy(vc->queue_mutex); pthread_mutex_destroy(vc->queue_mutex);
LOGGER_DEBUG(vc->log, "Terminated video handler: %p", (void *)vc); LOGGER_DEBUG(vc->log, "Terminated video handler: %p", (void *)vc);
free(vc); free(vc);
@ -303,7 +303,7 @@ void vc_iterate(VCSession *vc)
struct RTPMessage *p; struct RTPMessage *p;
if (!rb_read((RingBuffer *)vc->vbuf_raw, (void **)&p)) { if (!rb_read(vc->vbuf_raw, (void **)&p)) {
LOGGER_TRACE(vc->log, "no Video frame data available"); LOGGER_TRACE(vc->log, "no Video frame data available");
pthread_mutex_unlock(vc->queue_mutex); pthread_mutex_unlock(vc->queue_mutex);
return; return;
@ -323,7 +323,7 @@ void vc_iterate(VCSession *vc)
} }
LOGGER_DEBUG(vc->log, "vc_iterate: rb_read p->len=%d p->header.xe=%d", (int)full_data_len, p->header.xe); LOGGER_DEBUG(vc->log, "vc_iterate: rb_read p->len=%d p->header.xe=%d", (int)full_data_len, p->header.xe);
LOGGER_DEBUG(vc->log, "vc_iterate: rb_read rb size=%d", (int)rb_size((RingBuffer *)vc->vbuf_raw)); LOGGER_DEBUG(vc->log, "vc_iterate: rb_read rb size=%d", (int)rb_size(vc->vbuf_raw));
const vpx_codec_err_t rc = vpx_codec_decode(vc->decoder, p->data, full_data_len, nullptr, MAX_DECODE_TIME_US); const vpx_codec_err_t rc = vpx_codec_decode(vc->decoder, p->data, full_data_len, nullptr, MAX_DECODE_TIME_US);
free(p); free(p);
@ -378,7 +378,7 @@ int vc_queue_message(void *vcp, struct RTPMessage *msg)
LOGGER_DEBUG(vc->log, "rb_write msg->len=%d b0=%d b1=%d", (int)msg->len, (int)msg->data[0], (int)msg->data[1]); LOGGER_DEBUG(vc->log, "rb_write msg->len=%d b0=%d b1=%d", (int)msg->len, (int)msg->data[0], (int)msg->data[1]);
} }
free(rb_write((RingBuffer *)vc->vbuf_raw, msg)); free(rb_write(vc->vbuf_raw, msg));
/* Calculate time it took for peer to send us this frame */ /* Calculate time it took for peer to send us this frame */
uint32_t t_lcfd = current_time_monotonic() - vc->linfts; uint32_t t_lcfd = current_time_monotonic() - vc->linfts;