Skip to content

Commit

Permalink
Merge pull request #588 from nomis52/master
Browse files Browse the repository at this point in the history
Address some more defects.
  • Loading branch information
nomis52 committed Jan 3, 2015
2 parents 6421881 + 6101023 commit 47721de
Show file tree
Hide file tree
Showing 29 changed files with 193 additions and 126 deletions.
5 changes: 4 additions & 1 deletion common/network/Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ InterfaceBuilder::InterfaceBuilder()
: m_ip_address(0),
m_broadcast_address(0),
m_subnet_mask(0),
m_hw_address() {
m_hw_address(),
m_loopback(false),
m_index(Interface::DEFAULT_INDEX),
m_type(Interface::ARP_VOID_TYPE) {
}


Expand Down
7 changes: 7 additions & 0 deletions common/network/PosixInterfacePicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,12 @@ using std::vector;
vector<Interface> PosixInterfacePicker::GetInterfaces(
bool include_loopback) const {
vector<Interface> interfaces;

#ifdef HAVE_SOCKADDR_DL_STRUCT
string last_dl_iface_name;
uint8_t hwlen = 0;
char *hwaddr = NULL;
#endif

// create socket to get iface config
int sd = socket(PF_INET, SOCK_DGRAM, 0);
Expand Down Expand Up @@ -160,6 +163,8 @@ vector<Interface> PosixInterfacePicker::GetInterfaces(
}
}

#ifdef HAVE_SOCKADDR_DL_STRUCT
// The only way hwaddr is non-null is if HAVE_SOCKADDR_DL_STRUCT is defined.
if ((interface.name == last_dl_iface_name) && hwaddr) {
if (hwlen == MACAddress::LENGTH) {
interface.hw_address = MACAddress(reinterpret_cast<uint8_t*>(hwaddr));
Expand All @@ -169,6 +174,8 @@ vector<Interface> PosixInterfacePicker::GetInterfaces(
<< ", expecting " << MACAddress::LENGTH;
}
}
#endif

struct sockaddr_in *sin = (struct sockaddr_in *) &iface->ifr_addr;
interface.ip_address = IPV4Address(sin->sin_addr.s_addr);

Expand Down
4 changes: 3 additions & 1 deletion common/network/TCPConnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ TCPConnector::TCPConnectionID TCPConnector::Connect(
return 0;
}
} else {
// connect returned immediately
// Connect returned immediately
// The callback takes ownership of the socket descriptor.
// coverity(RESOURCE_LEAK)
callback->Run(sd, 0);
return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions common/network/TCPSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ void TCPAcceptingSocket::PerformRead() {
}

if (m_factory) {
// The callback takes ownership of the new socket descriptor
// coverity(RESOURCE_LEAK)
m_factory->NewTCPSocket(sd);
} else {
OLA_WARN << "Accepted new TCP Connection but no factory registered";
Expand Down
3 changes: 3 additions & 0 deletions common/rdm/AckTimerResponder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ const RDMResponse *AckTimerResponder::ResponseFromQueuedMessage(
queued_response->ParamDataSize());
break;
case RDMCommand::SET_COMMAND_RESPONSE:
// coverity(SWAPPED_ARGUMENTS)
return new RDMSetResponse(
request->DestinationUID(),
request->SourceUID(),
Expand Down Expand Up @@ -352,6 +353,7 @@ const RDMResponse *AckTimerResponder::SetDmxStartAddress(

uint16_t ack_time = 1 + ACK_TIMER_MS / 100;
ack_time = HostToNetwork(ack_time);
// coverity(SWAPPED_ARGUMENTS)
return new RDMSetResponse(
request->DestinationUID(),
request->SourceUID(),
Expand Down Expand Up @@ -402,6 +404,7 @@ const RDMResponse *AckTimerResponder::SetIdentify(

uint16_t ack_time = 1 + ACK_TIMER_MS / 100;
ack_time = HostToNetwork(ack_time);
// coverity(SWAPPED_ARGUMENTS)
return new RDMSetResponse(
request->DestinationUID(),
request->SourceUID(),
Expand Down
4 changes: 3 additions & 1 deletion common/rdm/MessageDeserializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ using std::vector;
MessageDeserializer::MessageDeserializer()
: m_data(NULL),
m_length(0),
m_offset(0) {
m_offset(0),
m_variable_field_size(0),
m_insufficient_data(false) {
}


Expand Down
2 changes: 2 additions & 0 deletions common/rdm/MovingLightResponder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ const RDMResponse *MovingLightResponder::GetLanguageCapabilities(
'f', 'r',
'd', 'e',
};
// coverity(SWAPPED_ARGUMENTS)
return new RDMGetResponse(
request->DestinationUID(),
request->SourceUID(),
Expand All @@ -345,6 +346,7 @@ const RDMResponse *MovingLightResponder::GetLanguage(
return NackWithReason(request, NR_FORMAT_ERROR);
}

// coverity(SWAPPED_ARGUMENTS)
return new RDMGetResponse(
request->DestinationUID(),
request->SourceUID(),
Expand Down
5 changes: 5 additions & 0 deletions common/rdm/RDMCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ RDMResponse *NackWithReason(const RDMRequest *request,
uint16_t reason = ola::network::HostToNetwork(static_cast<uint16_t>(
reason_enum));
if (request->CommandClass() == ola::rdm::RDMCommand::GET_COMMAND) {
// coverity(SWAPPED_ARGUMENTS)
return new ola::rdm::RDMGetResponse(
request->DestinationUID(),
request->SourceUID(),
Expand All @@ -692,6 +693,7 @@ RDMResponse *NackWithReason(const RDMRequest *request,
reinterpret_cast<uint8_t*>(&reason),
sizeof(reason));
} else {
// coverity(SWAPPED_ARGUMENTS)
return new ola::rdm::RDMSetResponse(
request->DestinationUID(),
request->SourceUID(),
Expand Down Expand Up @@ -734,6 +736,7 @@ RDMResponse *GetResponseWithPid(const RDMRequest *request,
uint8_t outstanding_messages) {
switch (request->CommandClass()) {
case RDMCommand::GET_COMMAND:
// coverity(SWAPPED_ARGUMENTS)
return new RDMGetResponse(
request->DestinationUID(),
request->SourceUID(),
Expand All @@ -745,6 +748,7 @@ RDMResponse *GetResponseWithPid(const RDMRequest *request,
data,
length);
case RDMCommand::SET_COMMAND:
// coverity(SWAPPED_ARGUMENTS)
return new RDMSetResponse(
request->DestinationUID(),
request->SourceUID(),
Expand All @@ -756,6 +760,7 @@ RDMResponse *GetResponseWithPid(const RDMRequest *request,
data,
length);
case RDMCommand::DISCOVER_COMMAND:
// coverity(SWAPPED_ARGUMENTS)
return new RDMDiscoveryResponse(
request->DestinationUID(),
request->SourceUID(),
Expand Down
1 change: 1 addition & 0 deletions common/rdm/ResponderHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,7 @@ const RDMResponse *ResponderHelper::EmptyGetResponse(
const RDMResponse *ResponderHelper::EmptySetResponse(
const RDMRequest *request,
uint8_t queued_message_count) {
// coverity(SWAPPED_ARGUMENTS)
return new RDMSetResponse(
request->DestinationUID(),
request->SourceUID(),
Expand Down
1 change: 1 addition & 0 deletions common/rdm/StringMessageBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ using std::vector;
StringMessageBuilder::StringMessageBuilder()
: m_offset(0),
m_input_size(0),
m_group_instance_count(0),
m_error(false) {
}

Expand Down
5 changes: 3 additions & 2 deletions common/system/Limits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#ifndef _WIN32
#include "ola/system/Limits.h"

#include <errno.h>
#include <string.h>
#include <sys/resource.h>

Expand All @@ -33,7 +34,7 @@ namespace system {
bool GetRLimit(int resource, struct rlimit *lim) {
int r = getrlimit(resource, lim);
if (r) {
OLA_WARN << "getrlimit(" << resource << "): " << strerror(r);
OLA_WARN << "getrlimit(" << resource << "): " << strerror(errno);
return false;
}
return true;
Expand All @@ -42,7 +43,7 @@ bool GetRLimit(int resource, struct rlimit *lim) {
bool SetRLimit(int resource, const struct rlimit &lim) {
int r = setrlimit(resource, &lim);
if (r) {
OLA_WARN << "setrlimit(" << resource << "): " << strerror(r);
OLA_WARN << "setrlimit(" << resource << "): " << strerror(errno);
return false;
}
return true;
Expand Down
1 change: 1 addition & 0 deletions common/web/JsonLexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ static bool ParseNumber(const char **input, JsonParserInterface *parser) {
switch (**input) {
case '-':
negative_exponent = true;
// fall through
case '+':
(*input)++;
break;
Expand Down
14 changes: 11 additions & 3 deletions examples/ola-rdm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,16 +223,24 @@ class RDMController {
const string &rdm_data);

private:
typedef struct {
struct PendingRequest {
public:
PendingRequest()
: universe(0),
uid(NULL),
sub_device(0),
pid_value(0) {
}

unsigned int universe;
const UID *uid;
uint16_t sub_device;
uint16_t pid_value;
} pending_request_t;
};

ola::OlaCallbackClientWrapper m_ola_client;
PidStoreHelper m_pid_helper;
pending_request_t m_pending_request;
PendingRequest m_pending_request;

void FetchQueuedMessage();
void PrintRemainingMessages(uint8_t message_count);
Expand Down
5 changes: 4 additions & 1 deletion include/ola/rdm/RDMMessagePrinters.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,10 @@ class LanguageCapabilityPrinter: public ola::messaging::MessagePrinter {
*/
class ClockPrinter: public ola::messaging::MessagePrinter {
public:
ClockPrinter() : ola::messaging::MessagePrinter(), m_offset(0) {}
ClockPrinter()
: ola::messaging::MessagePrinter(),
m_year(0),
m_offset(0) {}
void Visit(const ola::messaging::UInt16MessageField *message) {
m_year = message->Value();
}
Expand Down
3 changes: 3 additions & 0 deletions include/ola/strings/FormatPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ struct _ToHex {
};

inline uint32_t _HexCast(uint8_t v) { return v; }
inline uint32_t _HexCast(int8_t v) { return static_cast<uint8_t>(v); }
inline uint16_t _HexCast(uint16_t v) { return v; }
inline uint16_t _HexCast(int16_t v) { return static_cast<uint16_t>(v); }
inline uint32_t _HexCast(uint32_t v) { return v; }
inline uint32_t _HexCast(int32_t v) { return static_cast<uint32_t>(v); }

} // namespace strings
} // namespace ola
Expand Down
5 changes: 4 additions & 1 deletion include/ola/web/JsonPatchParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ class JsonPatchParser : public JsonParserInterface {
public:
explicit JsonPatchParser(JsonPatchSet *patch_set)
: JsonParserInterface(),
m_patch_set(patch_set) {}
m_patch_set(patch_set),
m_parser_depth(0),
m_state(TOP) {
}

void Begin();
void End();
Expand Down
3 changes: 2 additions & 1 deletion olad/RDMHTTPModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ RDMHTTPModule::RDMHTTPModule(HTTPServer *http_server,
: m_server(http_server),
m_client(client),
m_shim(client),
m_rdm_api(&m_shim) {
m_rdm_api(&m_shim),
m_pid_store(NULL) {

m_server->RegisterHandler(
"/rdm/run_discovery",
Expand Down
2 changes: 2 additions & 0 deletions plugins/artnet/ArtNetNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ ArtNetNodeImpl::ArtNetNodeImpl(const ola::network::Interface &iface,
m_always_broadcast(options.always_broadcast),
m_use_limited_broadcast_address(options.use_limited_broadcast_address),
m_in_configuration_mode(false),
m_artpoll_required(false),
m_artpollreply_required(false),
m_interface(iface),
m_socket(socket) {

Expand Down
9 changes: 6 additions & 3 deletions plugins/artnet/ArtNetNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,6 @@ class ArtNetNodeImpl {
ola::network::Interface m_interface;
std::auto_ptr<ola::network::UDPSocketInterface> m_socket;

ArtNetNodeImpl(const ArtNetNodeImpl&);
ArtNetNodeImpl& operator=(const ArtNetNodeImpl&);

/**
* @brief Called when there is data on this socket
*/
Expand Down Expand Up @@ -655,6 +652,8 @@ class ArtNetNodeImpl {
static const unsigned int RDM_REQUEST_QUEUE_LIMIT = 100;
// How long to wait for a response to an RDM Request
static const unsigned int RDM_REQUEST_TIMEOUT_MS = 2000;

DISALLOW_COPY_AND_ASSIGN(ArtNetNodeImpl);
};


Expand Down Expand Up @@ -687,6 +686,8 @@ class ArtNetNodeImplRDMWrapper
private:
ArtNetNodeImpl *m_impl;
uint8_t m_port_id;

DISALLOW_COPY_AND_ASSIGN(ArtNetNodeImplRDMWrapper);
};


Expand Down Expand Up @@ -853,6 +854,8 @@ class ArtNetNode {
* @return true if the port id is valid, false otherwise
*/
bool CheckInputPortId(uint8_t port_id);

DISALLOW_COPY_AND_ASSIGN(ArtNetNode);
};
} // namespace artnet
} // namespace plugin
Expand Down
23 changes: 11 additions & 12 deletions plugins/dummy/DummyDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,20 @@ namespace dummy {

class DummyDevice: public Device {
public:
DummyDevice(
AbstractPlugin *owner,
const std::string &name,
const DummyPort::Options &port_options)
: Device(owner, name),
m_port_options(port_options) {
}
std::string DeviceId() const { return "1"; }
DummyDevice(
AbstractPlugin *owner,
const std::string &name,
const DummyPort::Options &port_options)
: Device(owner, name),
m_port_options(port_options) {
}

std::string DeviceId() const { return "1"; }

protected:
uint16_t m_number_of_devices;
uint16_t m_number_of_subdevices;
const DummyPort::Options m_port_options;
const DummyPort::Options m_port_options;

bool StartHook();
bool StartHook();
};
} // namespace dummy
} // namespace plugin
Expand Down
8 changes: 4 additions & 4 deletions plugins/e131/e131/E131PDU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,17 @@ bool E131PDU::PackData(uint8_t *data, unsigned int *length) const {
void E131PDU::PackHeader(OutputStream *stream) const {
if (m_header.UsingRev2()) {
E131Rev2Header::e131_rev2_pdu_header header;
strncpy(header.source, m_header.Source().data(),
E131Rev2Header::REV2_SOURCE_NAME_LEN);
strings::CopyToFixedLengthBuffer(m_header.Source(), header.source,
arraysize(header.source));
header.priority = m_header.Priority();
header.sequence = m_header.Sequence();
header.universe = HostToNetwork(m_header.Universe());
stream->Write(reinterpret_cast<uint8_t*>(&header),
sizeof(E131Rev2Header::e131_rev2_pdu_header));
} else {
E131Header::e131_pdu_header header;
strncpy(header.source, m_header.Source().data(),
E131Header::SOURCE_NAME_LEN);
strings::CopyToFixedLengthBuffer(m_header.Source(), header.source,
arraysize(header.source));
header.priority = m_header.Priority();
header.reserved = 0;
header.sequence = m_header.Sequence();
Expand Down
14 changes: 14 additions & 0 deletions plugins/e131/e131/E131TestFramework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ using std::endl;
using std::string;
using std::vector;

StateManager::StateManager(const std::vector<TestState*> &states,
bool interactive_mode)
: m_interactive(interactive_mode),
m_count(0),
m_ticker(0),
m_local_node(NULL),
m_node1(NULL),
m_node2(NULL),
m_ss(NULL),
m_states(states),
m_stdin_descriptor(STDIN_FILENO) {
memset(&m_old_tc, 0, sizeof(m_old_tc));
}

bool StateManager::Init() {
m_cid1 = CID::Generate();
m_cid2 = CID::Generate();
Expand Down
Loading

0 comments on commit 47721de

Please sign in to comment.