Initialize all member variables in constructors. (#1026)

This commit is contained in:
Jonathan Hui
2016-12-01 08:51:55 -08:00
committed by GitHub
parent 353c3afbdd
commit 9586cfb700
8 changed files with 66 additions and 42 deletions
+2
View File
@@ -133,12 +133,14 @@ const struct Command Interpreter::sCommands[] =
};
Interpreter::Interpreter(otInstance *aInstance):
sServer(NULL),
sLength(8),
sCount(1),
sInterval(1000),
sPingTimer(aInstance->mIp6.mTimerScheduler, &Interpreter::s_HandlePingTimer, this),
mInstance(aInstance)
{
memset(mSlaacAddresses, 0, sizeof(mSlaacAddresses));
mInstance->mIp6.mIcmp.SetEchoReplyHandler(&s_HandleEchoResponse, this);
otSetStateChangedCallback(mInstance, &Interpreter::s_HandleNetifStateChanged, this);
}
+4 -3
View File
@@ -59,9 +59,10 @@ extern "C" void otCliConsoleInputLine(char *aBuf, uint16_t aBufLength)
sServer->ReceiveTask(aBuf, aBufLength);
}
Console::Console(otInstance *aInstance)
: mCallback(NULL),
mInterpreter(aInstance)
Console::Console(otInstance *aInstance):
mCallback(NULL),
mContext(NULL),
mInterpreter(aInstance)
{
}
+2
View File
@@ -46,6 +46,8 @@ Udp::Udp(otInstance *aInstance, Interpreter *aInterpreter):
mInstance(aInstance),
mInterpreter(aInterpreter)
{
memset(&mSocket, 0, sizeof(mSocket));
memset(&mPeer, 0, sizeof(mPeer));
}
ThreadError Udp::Start(void)
+8 -7
View File
@@ -102,14 +102,15 @@ exit:
}
Decoder::Decoder(uint8_t *aOutBuf, uint16_t aOutLength, FrameHandler aFrameHandler, void *aContext)
Decoder::Decoder(uint8_t *aOutBuf, uint16_t aOutLength, FrameHandler aFrameHandler, void *aContext):
mState(kStateNeedFlag),
mFrameHandler(aFrameHandler),
mContext(aContext),
mOutBuf(aOutBuf),
mOutOffset(0),
mOutLength(aOutLength),
mReadLength(0)
{
mState = kStateNeedFlag;
mFrameHandler = aFrameHandler;
mContext = aContext;
mOutBuf = aOutBuf;
mOutOffset = 0;
mOutLength = aOutLength;
}
void Decoder::Decode(const uint8_t *aInBuf, uint16_t aInLength)
+14 -8
View File
@@ -128,6 +128,11 @@ bool Encoder::BufferWriteIterator::CanWrite(uint16_t aWriteLength) const
return (mRemainingLength >= aWriteLength);
}
Encoder::Encoder(void):
mFcs(0)
{
}
ThreadError Encoder::Init(BufferWriteIterator &aIterator)
{
mFcs = kInitFcs;
@@ -202,15 +207,16 @@ exit:
return error;
}
Decoder::Decoder(uint8_t *aOutBuf, uint16_t aOutLength, FrameHandler aFrameHandler, ErrorHandler aErrorHandler, void *aContext)
Decoder::Decoder(uint8_t *aOutBuf, uint16_t aOutLength, FrameHandler aFrameHandler, ErrorHandler aErrorHandler, void *aContext):
mState(kStateNoSync),
mFrameHandler(aFrameHandler),
mErrorHandler(aErrorHandler),
mContext(aContext),
mOutBuf(aOutBuf),
mOutOffset(0),
mOutLength(aOutLength),
mFcs(0)
{
mState = kStateNoSync;
mFrameHandler = aFrameHandler;
mErrorHandler = aErrorHandler;
mContext = aContext;
mOutBuf = aOutBuf;
mOutOffset = 0;
mOutLength = aOutLength;
}
void Decoder::Decode(const uint8_t *aInBuf, uint16_t aInLength)
+6
View File
@@ -92,6 +92,12 @@ public:
uint16_t mRemainingLength; ///< Number of remaining bytes available to write.
};
/**
* This constructor initializes the object.
*
*/
Encoder(void);
/**
* This method begins an HDLC frame and puts the initial bytes into a buffer at the given @p aIterator.
*
+26 -22
View File
@@ -459,31 +459,35 @@ static uint8_t BorderRouterConfigToFlagByte(const otBorderRouterConfig &config)
NcpBase::NcpBase(otInstance *aInstance):
mInstance(aInstance),
mUpdateChangedPropsTask(aInstance->mIp6.mTaskletScheduler, &NcpBase::UpdateChangedProps, this)
mLastStatus(SPINEL_STATUS_OK),
mSupportedChannelMask(kPhySupportedChannelMask),
mChannelMask(mSupportedChannelMask),
mScanPeriod(200), // ms
mUpdateChangedPropsTask(aInstance->mIp6.mTaskletScheduler, &NcpBase::UpdateChangedProps, this),
mChangedFlags(NCP_PLAT_RESET_REASON),
mShouldSignalEndOfScan(false),
#if OPENTHREAD_ENABLE_JAM_DETECTION
mShouldSignalJamStateChange(false),
#endif
mDroppedReplyTid(0),
mDroppedReplyTidBitSet(0),
mAllowLocalNetworkDataChange(false),
mRequireJoinExistingNetwork(false),
mIsRawStreamEnabled(false),
mFramingErrorCounter(0),
mRxSpinelFrameCounter(0),
mTxSpinelFrameCounter(0),
mInboundSecureIpFrameCounter(0),
mInboundInsecureIpFrameCounter(0),
mOutboundSecureIpFrameCounter(0),
mOutboundInsecureIpFrameCounter(0),
mDroppedOutboundIpFrameCounter(0),
mDroppedInboundIpFrameCounter(0)
{
assert(mInstance != NULL);
mSupportedChannelMask = kPhySupportedChannelMask;
mChannelMask = mSupportedChannelMask;
mScanPeriod = 200; // ms
mShouldSignalEndOfScan = false;
#if OPENTHREAD_ENABLE_JAM_DETECTION
mShouldSignalJamStateChange = false;
#endif
sNcpContext = this;
mChangedFlags = NCP_PLAT_RESET_REASON;
mAllowLocalNetworkDataChange = false;
mRequireJoinExistingNetwork = false;
mIsRawStreamEnabled = false;
mFramingErrorCounter = 0;
mRxSpinelFrameCounter = 0;
mTxSpinelFrameCounter = 0;
mInboundSecureIpFrameCounter = 0;
mInboundInsecureIpFrameCounter = 0;
mOutboundSecureIpFrameCounter = 0;
mOutboundInsecureIpFrameCounter = 0;
mDroppedOutboundIpFrameCounter = 0;
mDroppedInboundIpFrameCounter = 0;
sNcpContext = NULL;
otSetStateChangedCallback(mInstance, &NcpBase::HandleNetifStateChanged, this);
otSetReceiveIp6DatagramCallback(mInstance, &NcpBase::HandleDatagramFromStack, this);
+4 -2
View File
@@ -90,10 +90,10 @@ NcpUart::NcpUart(otInstance *aInstance):
mFrameDecoder(mRxBuffer, sizeof(mRxBuffer), &NcpUart::HandleFrame, &NcpUart::HandleError, this),
mUartBuffer(),
mTxFrameBuffer(mTxBuffer, sizeof(mTxBuffer)),
mState(kStartingFrame),
mByte(0),
mUartSendTask(aInstance->mIp6.mTaskletScheduler, EncodeAndSendToUart, this)
{
mState = kStartingFrame;
mTxFrameBuffer.SetCallbacks(NULL, TxFrameBufferHasData, this);
}
@@ -175,6 +175,8 @@ void NcpUart::EncodeAndSendToUart(void)
mState = kFinalizingFrame;
// fall through
case kFinalizingFrame:
SuccessOrExit(mFrameEncoder.Finalize(mUartBuffer));