Skip to content

Commit

Permalink
Enable -Werror and fix all warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
orgads committed Jan 13, 2024
1 parent 88a489e commit c9589af
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 40 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_EXTENSIONS False)
# specify the C++ standard on older CMake (<3.8)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -pedantic -Wno-error=format-truncation -Wno-error=deprecated-declarations")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -pedantic -Wno-multichar -Wno-deprecated-copy")
endif()

# Include binary dir first, where we add generated config.h and
# version.h. If nothing is found there (release tar) use the version.h
Expand Down
1 change: 0 additions & 1 deletion include/sipp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,6 @@ void timeout_alarm(int);
SIPpSocket **get_peer_socket(char *);
bool is_a_peer_socket(SIPpSocket *);
bool is_a_local_socket(SIPpSocket *);
void connect_to_peer(char *, int, sockaddr_storage *, char *, SIPpSocket **);
void connect_to_all_peers();
void connect_local_twin_socket(char *);
void close_peer_sockets();
Expand Down
2 changes: 1 addition & 1 deletion src/call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3845,7 +3845,7 @@ char* call::createSendingMessage(SendingMessage *src, int P_index, char *msg_buf
break;
case E_Message_SippVersion:
/* Drop the initial "v" from the SIPP_VERSION string for legacy reasons. */
dest += snprintf(dest, left, "%s", (const char*)SIPP_VERSION + 1);
dest += snprintf(dest, left, "%s", &SIPP_VERSION[1]);
break;
case E_Message_Variable: {
int varId = comp->varId;
Expand Down
48 changes: 26 additions & 22 deletions src/rtpstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ static void debugprint(const char* format, ...)
#endif
}

static unsigned long tid_self() {
return reinterpret_cast<unsigned long>(pthread_self());
}

struct free_delete {
void operator()(void* x) { free(x); }
};
Expand Down Expand Up @@ -202,7 +206,7 @@ void printAudioHexUS(char const* note, unsigned char const* string, unsigned int
rtpcheck_debug)
{
pthread_mutex_lock(&debugamutex);
fprintf(debugafile, "TID: %lu %s %u 0x%llx %d [", pthread_self(), note, size, extrainfo, moreinfo);
fprintf(debugafile, "TID: %lu %s %u 0x%llx %d [", tid_self(), note, size, extrainfo, moreinfo);
for (unsigned int i = 0; i < size; i++)
{
fprintf(debugafile, "%02X", 0x000000FF & string[i]);
Expand All @@ -220,7 +224,7 @@ void printVideoHexUS(char const* note, unsigned char const* string, unsigned int
rtpcheck_debug)
{
pthread_mutex_lock(&debugvmutex);
fprintf(debugvfile, "TID: %lu %s %u 0x%llx %d [", pthread_self(), note, size, extrainfo, moreinfo);
fprintf(debugvfile, "TID: %lu %s %u 0x%llx %d [", tid_self(), note, size, extrainfo, moreinfo);
for (unsigned int i = 0; i < size; i++)
{
fprintf(debugvfile, "%02X", 0x000000FF & string[i]);
Expand All @@ -238,7 +242,7 @@ void printAudioHex(char const* note, char const* string, unsigned int size, unsi
rtpcheck_debug)
{
pthread_mutex_lock(&debugamutex);
fprintf(debugafile, "TID: %lu %s %u 0x%llx %d [", pthread_self(), note, size, extrainfo, moreinfo);
fprintf(debugafile, "TID: %lu %s %u 0x%llx %d [", tid_self(), note, size, extrainfo, moreinfo);
for (unsigned int i = 0; i < size; i++)
{
fprintf(debugafile, "%02X", 0x000000FF & string[i]);
Expand All @@ -255,7 +259,7 @@ void printAudioVector(char const* note, std::vector<unsigned long> const &v)
rtpcheck_debug)
{
pthread_mutex_lock(&debugamutex);
fprintf(debugafile, "TID: %lu %s\n", pthread_self(), note);
fprintf(debugafile, "TID: %lu %s\n", tid_self(), note);
for (unsigned int i = 0; i < v.size(); i++)
{
fprintf(debugafile, "%lu\n", v[i]);
Expand All @@ -272,7 +276,7 @@ void printVideoHex(char const* note, char const* string, unsigned int size, unsi
rtpcheck_debug)
{
pthread_mutex_lock(&debugvmutex);
fprintf(debugvfile, "TID: %lu %s %u 0x%llx %d [", pthread_self(), note, size, extrainfo, moreinfo);
fprintf(debugvfile, "TID: %lu %s %u 0x%llx %d [", tid_self(), note, size, extrainfo, moreinfo);
for (unsigned int i = 0; i < size; i++)
{
fprintf(debugvfile, "%02X", 0x000000FF & string[i]);
Expand All @@ -289,7 +293,7 @@ void printVideoVector(char const* note, std::vector<unsigned long> const &v)
rtpcheck_debug)
{
pthread_mutex_lock(&debugvmutex);
fprintf(debugvfile, "TID: %lu %s\n", pthread_self(), note);
fprintf(debugvfile, "TID: %lu %s\n", tid_self(), note);
for (unsigned int i = 0; i < v.size(); i++)
{
fprintf(debugvfile, "%lu\n", v[i]);
Expand Down Expand Up @@ -2110,10 +2114,10 @@ int rtpstream_set_srtp_audio_local(rtpstream_callinfo_t* callinfo, SrtpAudioInfo
taskinfo->local_srtp_audio_params.audio_found = true;
taskinfo->local_srtp_audio_params.primary_audio_cryptotag = p.primary_audio_cryptotag;
taskinfo->local_srtp_audio_params.secondary_audio_cryptotag = p.secondary_audio_cryptotag;
strncpy(taskinfo->local_srtp_audio_params.primary_audio_cryptosuite, p.primary_audio_cryptosuite, 23);
strncpy(taskinfo->local_srtp_audio_params.secondary_audio_cryptosuite, p.secondary_audio_cryptosuite, 23);
strncpy(taskinfo->local_srtp_audio_params.primary_audio_cryptokeyparams, p.primary_audio_cryptokeyparams, 40);
strncpy(taskinfo->local_srtp_audio_params.secondary_audio_cryptokeyparams, p.secondary_audio_cryptokeyparams, 40);
strcpy(taskinfo->local_srtp_audio_params.primary_audio_cryptosuite, p.primary_audio_cryptosuite);
strcpy(taskinfo->local_srtp_audio_params.secondary_audio_cryptosuite, p.secondary_audio_cryptosuite);
strcpy(taskinfo->local_srtp_audio_params.primary_audio_cryptokeyparams, p.primary_audio_cryptokeyparams);
strcpy(taskinfo->local_srtp_audio_params.secondary_audio_cryptokeyparams, p.secondary_audio_cryptokeyparams);
taskinfo->local_srtp_audio_params.primary_unencrypted_audio_srtp = p.primary_unencrypted_audio_srtp;
taskinfo->local_srtp_audio_params.secondary_unencrypted_audio_srtp = p.secondary_unencrypted_audio_srtp;
}
Expand Down Expand Up @@ -2177,10 +2181,10 @@ int rtpstream_set_srtp_audio_remote(rtpstream_callinfo_t* callinfo, SrtpAudioInf
taskinfo->remote_srtp_audio_params.audio_found = true;
taskinfo->remote_srtp_audio_params.primary_audio_cryptotag = p.primary_audio_cryptotag;
taskinfo->remote_srtp_audio_params.secondary_audio_cryptotag = p.secondary_audio_cryptotag;
strncpy(taskinfo->remote_srtp_audio_params.primary_audio_cryptosuite, p.primary_audio_cryptosuite, 23);
strncpy(taskinfo->remote_srtp_audio_params.secondary_audio_cryptosuite, p.secondary_audio_cryptosuite, 23);
strncpy(taskinfo->remote_srtp_audio_params.primary_audio_cryptokeyparams, p.primary_audio_cryptokeyparams, 40);
strncpy(taskinfo->remote_srtp_audio_params.secondary_audio_cryptokeyparams, p.secondary_audio_cryptokeyparams, 40);
strcpy(taskinfo->remote_srtp_audio_params.primary_audio_cryptosuite, p.primary_audio_cryptosuite);
strcpy(taskinfo->remote_srtp_audio_params.secondary_audio_cryptosuite, p.secondary_audio_cryptosuite);
strcpy(taskinfo->remote_srtp_audio_params.primary_audio_cryptokeyparams, p.primary_audio_cryptokeyparams);
strcpy(taskinfo->remote_srtp_audio_params.secondary_audio_cryptokeyparams, p.secondary_audio_cryptokeyparams);
taskinfo->remote_srtp_audio_params.primary_unencrypted_audio_srtp = p.primary_unencrypted_audio_srtp;
taskinfo->remote_srtp_audio_params.secondary_unencrypted_audio_srtp = p.secondary_unencrypted_audio_srtp;
}
Expand Down Expand Up @@ -2244,10 +2248,10 @@ int rtpstream_set_srtp_video_local(rtpstream_callinfo_t* callinfo, SrtpVideoInfo
taskinfo->local_srtp_video_params.video_found = true;
taskinfo->local_srtp_video_params.primary_video_cryptotag = p.primary_video_cryptotag;
taskinfo->local_srtp_video_params.secondary_video_cryptotag = p.secondary_video_cryptotag;
strncpy(taskinfo->local_srtp_video_params.primary_video_cryptosuite, p.primary_video_cryptosuite, 23);
strncpy(taskinfo->local_srtp_video_params.secondary_video_cryptosuite, p.secondary_video_cryptosuite, 23);
strncpy(taskinfo->local_srtp_video_params.primary_video_cryptokeyparams, p.primary_video_cryptokeyparams, 40);
strncpy(taskinfo->local_srtp_video_params.secondary_video_cryptokeyparams, p.secondary_video_cryptokeyparams, 40);
strcpy(taskinfo->local_srtp_video_params.primary_video_cryptosuite, p.primary_video_cryptosuite);
strcpy(taskinfo->local_srtp_video_params.secondary_video_cryptosuite, p.secondary_video_cryptosuite);
strcpy(taskinfo->local_srtp_video_params.primary_video_cryptokeyparams, p.primary_video_cryptokeyparams);
strcpy(taskinfo->local_srtp_video_params.secondary_video_cryptokeyparams, p.secondary_video_cryptokeyparams);
taskinfo->local_srtp_video_params.primary_unencrypted_video_srtp = p.primary_unencrypted_video_srtp;
taskinfo->local_srtp_video_params.secondary_unencrypted_video_srtp = p.secondary_unencrypted_video_srtp;
}
Expand Down Expand Up @@ -2311,10 +2315,10 @@ int rtpstream_set_srtp_video_remote(rtpstream_callinfo_t* callinfo, SrtpVideoInf
taskinfo->remote_srtp_video_params.video_found = true;
taskinfo->remote_srtp_video_params.primary_video_cryptotag = p.primary_video_cryptotag;
taskinfo->remote_srtp_video_params.secondary_video_cryptotag = p.secondary_video_cryptotag;
strncpy(taskinfo->remote_srtp_video_params.primary_video_cryptosuite, p.primary_video_cryptosuite, 23);
strncpy(taskinfo->remote_srtp_video_params.secondary_video_cryptosuite, p.secondary_video_cryptosuite, 23);
strncpy(taskinfo->remote_srtp_video_params.primary_video_cryptokeyparams, p.primary_video_cryptokeyparams, 40);
strncpy(taskinfo->remote_srtp_video_params.secondary_video_cryptokeyparams, p.secondary_video_cryptokeyparams, 40);
strcpy(taskinfo->remote_srtp_video_params.primary_video_cryptosuite, p.primary_video_cryptosuite);
strcpy(taskinfo->remote_srtp_video_params.secondary_video_cryptosuite, p.secondary_video_cryptosuite);
strcpy(taskinfo->remote_srtp_video_params.primary_video_cryptokeyparams, p.primary_video_cryptokeyparams);
strcpy(taskinfo->remote_srtp_video_params.secondary_video_cryptokeyparams, p.secondary_video_cryptokeyparams);
taskinfo->remote_srtp_video_params.primary_unencrypted_video_srtp = p.primary_unencrypted_video_srtp;
taskinfo->remote_srtp_video_params.secondary_unencrypted_video_srtp = p.secondary_unencrypted_video_srtp;
}
Expand Down
19 changes: 8 additions & 11 deletions src/screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,7 @@ void ScreenPrinter::get_lines()
while (isspace(*errstart)) {
errstart++;
}
if (strlen(errstart) > 60) {
snprintf(buf, bufsiz, "Last Error: %.60s...", errstart);
} else {
snprintf(buf, bufsiz, "Last Error: %s", errstart);
}
snprintf(buf, bufsiz, "Last Error: %.60s...", errstart);
lines.push_back(buf);
}

Expand Down Expand Up @@ -264,9 +260,10 @@ bool do_hide = true;

void ScreenPrinter::draw_scenario_screen()
{
unsigned const bufsiz = 80;
unsigned const bufsiz = 100;
char buf[bufsiz];
char left_buf[40];
char left_buf_long[60];
char right_buf[bufsiz];
extern int pollnfds;

Expand Down Expand Up @@ -306,20 +303,20 @@ void ScreenPrinter::draw_scenario_screen()
/* 1st line */
unsigned long ms_since_last_tick = clock_tick - last_report_time;
if (total_calls < stop_after) {
snprintf(left_buf, 40, "%llu new calls during %lu.%03lu s period",
snprintf(left_buf_long, 60, "%llu new calls during %lu.%03lu s period",
display_scenario->stats->GetStat(
CStat::CPT_PD_IncomingCallCreated) +
display_scenario->stats->GetStat(
CStat::CPT_PD_OutgoingCallCreated),
ms_since_last_tick / 1000, ms_since_last_tick % 1000);
} else {
snprintf(left_buf, 40,
snprintf(left_buf_long, 60,
"Call limit %lu hit, %0.1f s period ", stop_after,
(double)ms_since_last_tick / 100.0);
}
snprintf(right_buf, 40, "%lu ms scheduler resolution",
ms_since_last_tick / std::max(scheduling_loops, 1ul));
snprintf(buf, bufsiz, " %-38.38s %-37.37s", left_buf, right_buf);
snprintf(buf, bufsiz, " %-38.38s %-37.37s", left_buf_long, right_buf);
lines.push_back(buf);

/* 2nd line */
Expand Down Expand Up @@ -641,8 +638,8 @@ void ScreenPrinter::draw_scenario_screen()
ERROR("Scenario command %d not implemented in display", curmsg->M_type);
}

char buf_with_index[80] = {0};
snprintf(buf_with_index, 80, "%-2lu:%s", index, buf);
char buf_with_index[121];
snprintf(buf_with_index, 121, "%-2lu:%s", index, buf);
lines.push_back(buf_with_index);
if (curmsg->crlf) {
lines.push_back("");
Expand Down
14 changes: 10 additions & 4 deletions src/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ int pending_messages = 0;

map<string, SIPpSocket *> map_perip_fd;

static void connect_to_peer(
char *peer_host, int peer_port, struct sockaddr_storage *peer_sockaddr,
char *peer_ip, int peer_ip_size, SIPpSocket **peer_socket);

int gai_getsockaddr(struct sockaddr_storage* ss, const char* host,
const char *service, int flags, int family)
{
Expand Down Expand Up @@ -2629,7 +2633,7 @@ int open_connections()
/* Trying to connect to Twin Sipp in 3PCC mode */
if (twinSippMode) {
if (thirdPartyMode == MODE_3PCC_CONTROLLER_A || thirdPartyMode == MODE_3PCC_A_PASSIVE) {
connect_to_peer(twinSippHost, twinSippPort, &twinSipp_sockaddr, twinSippIp, &twinSippSocket);
connect_to_peer(twinSippHost, twinSippPort, &twinSipp_sockaddr, twinSippIp, sizeof(twinSippIp), &twinSippSocket);
} else if (thirdPartyMode == MODE_3PCC_CONTROLLER_B) {
connect_local_twin_socket(twinSippHost);
} else {
Expand All @@ -2656,7 +2660,9 @@ int open_connections()
}


void connect_to_peer(char *peer_host, int peer_port, struct sockaddr_storage *peer_sockaddr, char *peer_ip, SIPpSocket **peer_socket)
static void connect_to_peer(
char *peer_host, int peer_port, struct sockaddr_storage *peer_sockaddr,
char *peer_ip, int peer_ip_size, SIPpSocket **peer_socket)
{
/* Resolving the peer IP */
printf("Resolving peer address : %s...\n", peer_host);
Expand All @@ -2673,7 +2679,7 @@ void connect_to_peer(char *peer_host, int peer_port, struct sockaddr_storage *pe
is_ipv6 = true;
}

get_inet_address(peer_sockaddr, peer_ip, sizeof(peer_ip));
get_inet_address(peer_sockaddr, peer_ip, peer_ip_size);

if ((*peer_socket = new_sipp_socket(is_ipv6, T_TCP)) == NULL) {
ERROR_NO("Unable to get a twin sipp TCP socket");
Expand Down Expand Up @@ -2801,7 +2807,7 @@ void connect_to_all_peers()
for (peer_it = peers.begin(); peer_it != peers.end(); peer_it++) {
infos = peer_it->second;
get_host_and_port(infos.peer_host, infos.peer_host, &infos.peer_port);
connect_to_peer(infos.peer_host, infos.peer_port, &(infos.peer_sockaddr), infos.peer_ip, &(infos.peer_socket));
connect_to_peer(infos.peer_host, infos.peer_port, &(infos.peer_sockaddr), infos.peer_ip, sizeof(infos.peer_ip), &(infos.peer_socket));
peer_sockets[infos.peer_socket] = peer_it->first;
peers[std::string(peer_it->first)] = infos;
}
Expand Down

0 comments on commit c9589af

Please sign in to comment.