Skip to content

Commit 95a7f6a

Browse files
author
Marcel Hecko
committed
Fix compilation warnings across the codebase
- Replace deprecated sprintf() with snprintf() in arg_conversion, SyslogCDR, AnswerMachine, XmlRpcClient, XmlRpcServer, and AmUtils - Remove deprecated 'register' storage class specifier in AmSdp, AmUriParser, and parse_100rel - Add virtual destructor to SBCEventLogHandler (polymorphic base class) - Fix string literal pointer arithmetic with array subscript in parse_header for C++ standard compliance - Guard #pragma GCC diagnostic for -Wclass-memaccess (GCC-only) in sip_parser_async.h to avoid warnings on Clang - Fix integer overflow in MuxStreamQueue stream_id loop (AmRtpMuxStream) - Conditionally add MacPorts paths on Darwin only if they exist - Set CMAKE_CXX_STANDARD to C++11 in CMakeLists.txt
1 parent 1050dab commit 95a7f6a

File tree

14 files changed

+45
-33
lines changed

14 files changed

+45
-33
lines changed

CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
77

88
project(SEMS)
99

10+
set(CMAKE_CXX_STANDARD 11)
11+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
12+
1013
# Read the version from the VERSION file
1114
execute_process(
1215
COMMAND cat "${CMAKE_SOURCE_DIR}/VERSION"
@@ -347,8 +350,12 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL SunOS)
347350
endif(${CMAKE_SYSTEM_NAME} STREQUAL SunOS)
348351

349352
if(${CMAKE_SYSTEM_NAME} STREQUAL Darwin)
350-
include_directories(/opt/local/include)
351-
link_directories(/opt/local/lib)
353+
if(EXISTS /opt/local/include)
354+
include_directories(/opt/local/include)
355+
endif()
356+
if(EXISTS /opt/local/lib)
357+
link_directories(/opt/local/lib)
358+
endif()
352359
set(CMAKE_C_FLAGS
353360
"${CMAKE_C_FLAGS} -fno-common -DBSD44SOCKETS -D__DARWIN_UNIX03")
354361
set(CMAKE_CXX_FLAGS

apps/sbc/SBCEventLog.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ using std::map;
4040

4141
struct SBCEventLogHandler
4242
{
43-
virtual void logEvent(long int timestamp, const string& id,
43+
virtual ~SBCEventLogHandler() {}
44+
virtual void logEvent(long int timestamp, const string& id,
4445
const string& type, const AmArg& ev)=0;
4546
};
4647

apps/sbc/arg_conversion.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ static string arg2string(const AmArg &a)
1717
switch (a.getType()) {
1818
case AmArg::CStr:
1919
p = a.asCStr();
20-
sprintf(tmp, "%c%zd/", CSTR_LABEL, strlen(p));
20+
snprintf(tmp, sizeof(tmp), "%c%zd/", CSTR_LABEL, strlen(p));
2121
s = tmp;
2222
s += p;
2323
return s;
2424

2525
case AmArg::Array:
26-
sprintf(tmp, "%c%zd/", ARRAY_LABEL, a.size());
26+
snprintf(tmp, sizeof(tmp), "%c%zd/", ARRAY_LABEL, a.size());
2727
s = tmp;
2828
for (size_t i = 0; i < a.size(); i ++) s += arg2string(a[i]);
2929
return s;
3030

3131
case AmArg::Struct:
32-
sprintf(tmp, "%c%zd/", STRUCT_LABEL, a.size());
32+
snprintf(tmp, sizeof(tmp), "%c%zd/", STRUCT_LABEL, a.size());
3333
s = tmp;
3434
for (AmArg::ValueStruct::const_iterator it = a.asStruct()->begin();
3535
it != a.asStruct()->end(); ++it) {
36-
sprintf(tmp, "%zd/", it->first.size());
36+
snprintf(tmp, sizeof(tmp), "%zd/", it->first.size());
3737
s += tmp;
3838
s += it->first;
3939
s += arg2string(it->second);

apps/sbc/call_control/syslog_cdr/SyslogCDR.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ string timeString(time_t tv_sec) {
168168
struct tm tmp;
169169
if (!localtime_r(&tv_sec, &tmp) || strftime(outstr, sizeof(outstr), "%F %T", &tmp) == 0) {
170170
ERROR("converting time\n");
171-
sprintf(outstr, "<unknown>");
171+
snprintf(outstr, sizeof(outstr), "<unknown>");
172172
}
173173
return string(outstr);
174174
}

apps/voicemail/AnswerMachine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ void AnswerMachineDialog::onSessionStart()
886886
setInOut(&playlist,&playlist);
887887

888888
char now[15];
889-
sprintf(now, "%d", (int) time(NULL));
889+
snprintf(now, sizeof(now), "%d", (int) time(NULL));
890890
email_dict["ts"] = now;
891891

892892
AmSession::onSessionStart();

apps/xmlrpc2di/xmlrpc++/src/XmlRpcClient.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ XmlRpcClient::generateHeader(std::string const& body)
349349
header += _host;
350350

351351
char buff[40];
352-
sprintf(buff,":%d\r\n", _port);
352+
snprintf(buff, sizeof(buff), ":%d\r\n", _port);
353353

354354
header += buff;
355355

@@ -383,7 +383,7 @@ XmlRpcClient::generateHeader(std::string const& body)
383383

384384
header += "Content-Type: text/xml\r\nContent-length: ";
385385

386-
sprintf(buff,"%zd\r\n\r\n", body.size());
386+
snprintf(buff, sizeof(buff), "%zd\r\n\r\n", body.size());
387387

388388
return header + buff;
389389
}

apps/xmlrpc2di/xmlrpc++/src/XmlRpcServer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ XmlRpcServer::generateHeader(std::string const& body)
470470
"Content-length: ";
471471

472472
char buffLen[40];
473-
sprintf(buffLen,"%zd\r\n\r\n", body.size());
473+
snprintf(buffLen, sizeof(buffLen), "%zd\r\n\r\n", body.size());
474474

475475
return header + buffLen;
476476
}

core/AmRtpMuxStream.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,13 @@ int MuxStreamQueue::send(unsigned char* buffer, unsigned int b_size,
255255
map<unsigned short, unsigned char>::iterator mux_id_it = stream_ids.find(rtp_dst_port);
256256
if (mux_id_it == stream_ids.end()) {
257257
// set up a new stream_id for port rtp_dst_port
258-
for (stream_id=0;stream_id<=256;stream_id++) {
259-
if (streamstates.find(stream_id)==streamstates.end())
258+
unsigned int sid;
259+
for (sid=0;sid<=255;sid++) {
260+
if (streamstates.find((unsigned char)sid)==streamstates.end())
260261
break;
261262
}
262-
if (stream_id==256) {
263+
stream_id = (unsigned char)sid;
264+
if (sid>255) {
263265
ERROR("trying to send more than 256 streams on RTP MUX connection to %s:%u\n", remote_ip.c_str(), remote_port);
264266
// or: find the oldest stream and overwrite that one
265267
return -1;

core/AmSdp.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ static bool parse_sdp_line_ex(AmSdp* sdp_msg, char*& s)
570570
if (!s) return true; // SDP can't be empty, return error (true really used for failure?)
571571

572572
char* next=0; size_t line_len = 0;
573-
register parse_st state;
573+
parse_st state;
574574
//default state
575575
state=SDP_DESCR;
576576
DBG("parsing SDP message...\n");
@@ -745,7 +745,7 @@ static char* parse_sdp_connection(AmSdp* sdp_msg, char* s, char t)
745745
return next_line;
746746
}
747747

748-
register sdp_connection_st state;
748+
sdp_connection_st state;
749749
state = NET_TYPE;
750750

751751
//DBG("parse_sdp_line_ex: parse_sdp_connection: parsing sdp connection\n");
@@ -821,7 +821,7 @@ static void parse_sdp_media(AmSdp* sdp_msg, char* s)
821821
{
822822
SdpMedia m;
823823

824-
register sdp_media_st state;
824+
sdp_media_st state;
825825
state = MEDIA;
826826
int parsing = 1;
827827
char* media_line=s;
@@ -999,8 +999,8 @@ static char* parse_sdp_attr(AmSdp* sdp_msg, char* s)
999999

10001000
SdpPayload payload;
10011001

1002-
register sdp_attr_rtpmap_st rtpmap_st;
1003-
register sdp_attr_fmtp_st fmtp_st;
1002+
sdp_attr_rtpmap_st rtpmap_st;
1003+
sdp_attr_fmtp_st fmtp_st;
10041004
rtpmap_st = TYPE;
10051005
fmtp_st = FORMAT;
10061006
char* attr_line=s;
@@ -1209,7 +1209,7 @@ static void parse_sdp_origin(AmSdp* sdp_msg, char* s)
12091209
size_t line_len=0;
12101210
line_end = skip_till_next_line(s, line_len);
12111211

1212-
register sdp_origin_st origin_st;
1212+
sdp_origin_st origin_st;
12131213
origin_st = USER;
12141214
int parsing = 1;
12151215

core/AmUriParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static inline int skip_uri(const string& s, unsigned int pos)
9090
unsigned int len = s.length() - pos;
9191
unsigned int p = pos;
9292

93-
register int st = ST1;
93+
int st = ST1;
9494

9595
while(len) {
9696
switch(s[p]) {

0 commit comments

Comments
 (0)