Skip to content

Commit 1a1f42d

Browse files
committed
Bug 1714307 - Run modernize-use-default-member-init --fix check on netwerk r=necko-reviewers,kershaw
This changeset is the result of adding modernize-use-default-member-init to tools/clang-tidy/config.yaml then proceeding to run `./mach static-analysis check netwerk/ --fix` I then went through the resulting fix and manually updated all of the member variables which were missed due to them having a non-trivial constructor. Note that the tool was only run on Linux, so code that only runs on some platforms may have been missed. The member variables that are still initialized in the contructor definition are: - bitfields (not all currently supported compilers allow default-member-init - variables that are initialized via a parameter - variables that use code not visible in the header file There are a few advantages to landing this change: - fewer lines of code - now declaration is in the same place as initialization this also makes it easier to see when looking at the header. - it makes it harder to miss initializing a member when adding a new contructor - variables that depend on an include guard look much nicer now Additionally I removed some unnecessary reinitialization of NetAddr members (it has a constructor that does that now), and changed nsWifiScannerDBus to use the thread-safe strtok_r instead of strtok. Differential Revision: https://phabricator.services.mozilla.com/D116980
1 parent 690a925 commit 1a1f42d

File tree

112 files changed

+632
-1185
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+632
-1185
lines changed

netwerk/base/ArrayBufferInputStream.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ using mozilla::dom::RootingCx;
1717
NS_IMPL_ISUPPORTS(ArrayBufferInputStream, nsIArrayBufferInputStream,
1818
nsIInputStream);
1919

20-
ArrayBufferInputStream::ArrayBufferInputStream()
21-
: mBufferLength(0), mPos(0), mClosed(false) {}
22-
2320
NS_IMETHODIMP
2421
ArrayBufferInputStream::SetData(JS::Handle<JS::Value> aBuffer,
2522
uint64_t aByteOffset, uint64_t aLength) {

netwerk/base/ArrayBufferInputStream.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
class ArrayBufferInputStream : public nsIArrayBufferInputStream {
2525
public:
26-
ArrayBufferInputStream();
26+
ArrayBufferInputStream() = default;
2727

2828
NS_DECL_THREADSAFE_ISUPPORTS
2929
NS_DECL_NSIARRAYBUFFERINPUTSTREAM
@@ -32,9 +32,9 @@ class ArrayBufferInputStream : public nsIArrayBufferInputStream {
3232
private:
3333
virtual ~ArrayBufferInputStream() = default;
3434
mozilla::UniquePtr<char[]> mArrayBuffer;
35-
uint32_t mBufferLength;
36-
uint32_t mPos;
37-
bool mClosed;
35+
uint32_t mBufferLength{0};
36+
uint32_t mPos{0};
37+
bool mClosed{false};
3838
};
3939

4040
#endif // ArrayBufferInputStream_h

netwerk/base/BackgroundFileSaver.cpp

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -82,27 +82,7 @@ class NotifyTargetChangeRunnable final : public Runnable {
8282
uint32_t BackgroundFileSaver::sThreadCount = 0;
8383
uint32_t BackgroundFileSaver::sTelemetryMaxThreadCount = 0;
8484

85-
BackgroundFileSaver::BackgroundFileSaver()
86-
: mControlEventTarget(nullptr),
87-
mBackgroundET(nullptr),
88-
mPipeOutputStream(nullptr),
89-
mPipeInputStream(nullptr),
90-
mObserver(nullptr),
91-
mLock("BackgroundFileSaver.mLock"),
92-
mWorkerThreadAttentionRequested(false),
93-
mFinishRequested(false),
94-
mComplete(false),
95-
mStatus(NS_OK),
96-
mAppend(false),
97-
mInitialTarget(nullptr),
98-
mInitialTargetKeepPartial(false),
99-
mRenamedTarget(nullptr),
100-
mRenamedTargetKeepPartial(false),
101-
mAsyncCopyContext(nullptr),
102-
mSha256Enabled(false),
103-
mSignatureInfoEnabled(false),
104-
mActualTarget(nullptr),
105-
mActualTargetKeepPartial(false) {
85+
BackgroundFileSaver::BackgroundFileSaver() {
10686
LOG(("Created BackgroundFileSaver [this = %p]", this));
10787
}
10888

@@ -931,13 +911,6 @@ BackgroundFileSaverOutputStream::OnOutputStreamReady(
931911
NS_IMPL_ISUPPORTS(BackgroundFileSaverStreamListener, nsIBackgroundFileSaver,
932912
nsIRequestObserver, nsIStreamListener)
933913

934-
BackgroundFileSaverStreamListener::BackgroundFileSaverStreamListener()
935-
: BackgroundFileSaver(),
936-
mSuspensionLock("BackgroundFileSaverStreamListener.mSuspensionLock"),
937-
mReceivedTooMuchData(false),
938-
mRequest(nullptr),
939-
mRequestSuspended(false) {}
940-
941914
bool BackgroundFileSaverStreamListener::HasInfiniteBuffer() { return true; }
942915

943916
nsAsyncCopyProgressFun

netwerk/base/BackgroundFileSaver.h

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -117,36 +117,36 @@ class BackgroundFileSaver : public nsIBackgroundFileSaver {
117117
* Protects the shared state between control and worker threads. This mutex
118118
* is always locked for a very short time, never during input/output.
119119
*/
120-
mozilla::Mutex mLock;
120+
mozilla::Mutex mLock{"BackgroundFileSaver.mLock"};
121121

122122
/**
123123
* True if the worker thread is already waiting to process a change in state.
124124
*/
125-
bool mWorkerThreadAttentionRequested;
125+
bool mWorkerThreadAttentionRequested{false};
126126

127127
/**
128128
* True if the operation should finish as soon as possibile.
129129
*/
130-
bool mFinishRequested;
130+
bool mFinishRequested{false};
131131

132132
/**
133133
* True if the operation completed, with either success or failure.
134134
*/
135-
bool mComplete;
135+
bool mComplete{false};
136136

137137
/**
138138
* Holds the current file saver status. This is a success status while the
139139
* object is working correctly, and remains such if the operation completes
140140
* successfully. This becomes an error status when an error occurs on the
141141
* worker thread, or when the operation is canceled.
142142
*/
143-
nsresult mStatus;
143+
nsresult mStatus{NS_OK};
144144

145145
/**
146146
* True if we should append data to the initial target file, instead of
147147
* overwriting it.
148148
*/
149-
bool mAppend;
149+
bool mAppend{false};
150150

151151
/**
152152
* This is set by the first SetTarget call on the control thread, and contains
@@ -161,7 +161,7 @@ class BackgroundFileSaver : public nsIBackgroundFileSaver {
161161
* indicates whether mInitialTarget should be kept as partially completed,
162162
* rather than deleted, if the operation fails or is canceled.
163163
*/
164-
bool mInitialTargetKeepPartial;
164+
bool mInitialTargetKeepPartial{false};
165165

166166
/**
167167
* This is set by subsequent SetTarget calls on the control thread, and
@@ -179,7 +179,7 @@ class BackgroundFileSaver : public nsIBackgroundFileSaver {
179179
* indicates whether mRenamedTarget should be kept as partially completed,
180180
* rather than deleted, if the operation fails or is canceled.
181181
*/
182-
bool mRenamedTargetKeepPartial;
182+
bool mRenamedTargetKeepPartial{false};
183183

184184
/**
185185
* While NS_AsyncCopy is in progress, allows canceling it. Null otherwise.
@@ -197,7 +197,7 @@ class BackgroundFileSaver : public nsIBackgroundFileSaver {
197197
* Whether or not to compute the hash. Must be set on the main thread before
198198
* setTarget is called.
199199
*/
200-
bool mSha256Enabled;
200+
bool mSha256Enabled{false};
201201

202202
/**
203203
* Store the signature info.
@@ -208,7 +208,7 @@ class BackgroundFileSaver : public nsIBackgroundFileSaver {
208208
* Whether or not to extract the signature. Must be set on the main thread
209209
* before setTarget is called.
210210
*/
211-
bool mSignatureInfoEnabled;
211+
bool mSignatureInfoEnabled{false};
212212

213213
//////////////////////////////////////////////////////////////////////////////
214214
//// State handled exclusively by the worker thread
@@ -222,7 +222,7 @@ class BackgroundFileSaver : public nsIBackgroundFileSaver {
222222
* Indicates whether mActualTarget should be kept as partially completed,
223223
* rather than deleted, if the operation fails or is canceled.
224224
*/
225-
bool mActualTargetKeepPartial;
225+
bool mActualTargetKeepPartial{false};
226226

227227
/**
228228
* Used to calculate the file hash. This keeps state across file renames and
@@ -327,7 +327,7 @@ class BackgroundFileSaverStreamListener final : public BackgroundFileSaver,
327327
NS_DECL_NSIREQUESTOBSERVER
328328
NS_DECL_NSISTREAMLISTENER
329329

330-
BackgroundFileSaverStreamListener();
330+
BackgroundFileSaverStreamListener() = default;
331331

332332
protected:
333333
virtual bool HasInfiniteBuffer() override;
@@ -339,12 +339,13 @@ class BackgroundFileSaverStreamListener final : public BackgroundFileSaver,
339339
/**
340340
* Protects the state related to whether the request should be suspended.
341341
*/
342-
mozilla::Mutex mSuspensionLock;
342+
mozilla::Mutex mSuspensionLock{
343+
"BackgroundFileSaverStreamListener.mSuspensionLock"};
343344

344345
/**
345346
* Whether we should suspend the request because we received too much data.
346347
*/
347-
bool mReceivedTooMuchData;
348+
bool mReceivedTooMuchData{false};
348349

349350
/**
350351
* Request for which we received too much data. This is populated when
@@ -355,7 +356,7 @@ class BackgroundFileSaverStreamListener final : public BackgroundFileSaver,
355356
/**
356357
* Whether mRequest is currently suspended.
357358
*/
358-
bool mRequestSuspended;
359+
bool mRequestSuspended{false};
359360

360361
/**
361362
* Called while NS_AsyncCopy is copying data.

netwerk/base/Dashboard.cpp

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,13 @@ class SocketData : public nsISupports {
3838
public:
3939
NS_DECL_THREADSAFE_ISUPPORTS
4040

41-
SocketData() {
42-
mTotalSent = 0;
43-
mTotalRecv = 0;
44-
mEventTarget = nullptr;
45-
}
41+
SocketData() = default;
4642

47-
uint64_t mTotalSent;
48-
uint64_t mTotalRecv;
43+
uint64_t mTotalSent{0};
44+
uint64_t mTotalRecv{0};
4945
nsTArray<SocketInfo> mData;
5046
nsMainThreadPtrHandle<nsINetDashboardCallback> mCallback;
51-
nsIEventTarget* mEventTarget;
47+
nsIEventTarget* mEventTarget{nullptr};
5248

5349
private:
5450
virtual ~SocketData() = default;
@@ -64,11 +60,11 @@ class HttpData : public nsISupports {
6460
public:
6561
NS_DECL_THREADSAFE_ISUPPORTS
6662

67-
HttpData() { mEventTarget = nullptr; }
63+
HttpData() = default;
6864

6965
nsTArray<HttpRetParams> mData;
7066
nsMainThreadPtrHandle<nsINetDashboardCallback> mCallback;
71-
nsIEventTarget* mEventTarget;
67+
nsIEventTarget* mEventTarget{nullptr};
7268
};
7369

7470
NS_IMPL_ISUPPORTS0(HttpData)
@@ -79,10 +75,10 @@ class WebSocketRequest : public nsISupports {
7975
public:
8076
NS_DECL_THREADSAFE_ISUPPORTS
8177

82-
WebSocketRequest() { mEventTarget = nullptr; }
78+
WebSocketRequest() = default;
8379

8480
nsMainThreadPtrHandle<nsINetDashboardCallback> mCallback;
85-
nsIEventTarget* mEventTarget;
81+
nsIEventTarget* mEventTarget{nullptr};
8682
};
8783

8884
NS_IMPL_ISUPPORTS0(WebSocketRequest)
@@ -93,11 +89,11 @@ class DnsData : public nsISupports {
9389
public:
9490
NS_DECL_THREADSAFE_ISUPPORTS
9591

96-
DnsData() { mEventTarget = nullptr; }
92+
DnsData() = default;
9793

9894
nsTArray<DNSCacheEntries> mData;
9995
nsMainThreadPtrHandle<nsINetDashboardCallback> mCallback;
100-
nsIEventTarget* mEventTarget;
96+
nsIEventTarget* mEventTarget{nullptr};
10197
};
10298

10399
NS_IMPL_ISUPPORTS0(DnsData)
@@ -124,22 +120,19 @@ class ConnectionData : public nsITransportEventSink,
124120
void StartTimer(uint32_t aTimeout);
125121
void StopTimer();
126122

127-
explicit ConnectionData(Dashboard* target) : mPort(0), mTimeout(0) {
128-
mEventTarget = nullptr;
129-
mDashboard = target;
130-
}
123+
explicit ConnectionData(Dashboard* target) { mDashboard = target; }
131124

132125
nsCOMPtr<nsISocketTransport> mSocket;
133126
nsCOMPtr<nsIInputStream> mStreamIn;
134127
nsCOMPtr<nsITimer> mTimer;
135128
nsMainThreadPtrHandle<nsINetDashboardCallback> mCallback;
136-
nsIEventTarget* mEventTarget;
129+
nsIEventTarget* mEventTarget{nullptr};
137130
Dashboard* mDashboard;
138131

139132
nsCString mHost;
140-
uint32_t mPort;
133+
uint32_t mPort{0};
141134
nsCString mProtocol;
142-
uint32_t mTimeout;
135+
uint32_t mTimeout{0};
143136

144137
nsString mStatus;
145138
};
@@ -153,10 +146,10 @@ class RcwnData : public nsISupports {
153146
public:
154147
NS_DECL_THREADSAFE_ISUPPORTS
155148

156-
RcwnData() { mEventTarget = nullptr; }
149+
RcwnData() = default;
157150

158151
nsMainThreadPtrHandle<nsINetDashboardCallback> mCallback;
159-
nsIEventTarget* mEventTarget;
152+
nsIEventTarget* mEventTarget{nullptr};
160153
};
161154

162155
NS_IMPL_ISUPPORTS0(RcwnData)
@@ -243,16 +236,16 @@ class LookupHelper final : public nsIDNSListener {
243236
NS_DECL_THREADSAFE_ISUPPORTS
244237
NS_DECL_NSIDNSLISTENER
245238

246-
LookupHelper() : mEventTarget{nullptr}, mStatus{NS_ERROR_NOT_INITIALIZED} {}
239+
LookupHelper() = default;
247240

248241
nsresult ConstructAnswer(LookupArgument* aArgument);
249242
nsresult ConstructHTTPSRRAnswer(LookupArgument* aArgument);
250243

251244
public:
252245
nsCOMPtr<nsICancelable> mCancel;
253246
nsMainThreadPtrHandle<nsINetDashboardCallback> mCallback;
254-
nsIEventTarget* mEventTarget;
255-
nsresult mStatus;
247+
nsIEventTarget* mEventTarget{nullptr};
248+
nsresult mStatus{NS_ERROR_NOT_INITIALIZED};
256249
};
257250

258251
NS_IMPL_ISUPPORTS(LookupHelper, nsIDNSListener)

netwerk/base/LoadInfo.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ LoadInfo::LoadInfo(
104104
mLoadingContext(do_GetWeakReference(aLoadingContext)),
105105
mSecurityFlags(aSecurityFlags),
106106
mSandboxFlags(aSandboxFlags),
107-
mTriggeringSandboxFlags(0),
107+
108108
mInternalContentPolicyType(aContentPolicyType) {
109109
MOZ_ASSERT(mLoadingPrincipal);
110110
MOZ_ASSERT(mTriggeringPrincipal);
@@ -320,7 +320,7 @@ LoadInfo::LoadInfo(nsPIDOMWindowOuter* aOuterWindow,
320320
mContextForTopLevelLoad(do_GetWeakReference(aContextForTopLevelLoad)),
321321
mSecurityFlags(aSecurityFlags),
322322
mSandboxFlags(aSandboxFlags),
323-
mTriggeringSandboxFlags(0),
323+
324324
mInternalContentPolicyType(nsIContentPolicy::TYPE_DOCUMENT) {
325325
// Top-level loads are never third-party
326326
// Grab the information we can out of the window.
@@ -379,7 +379,7 @@ LoadInfo::LoadInfo(dom::CanonicalBrowsingContext* aBrowsingContext,
379379
: mTriggeringPrincipal(aTriggeringPrincipal),
380380
mSecurityFlags(aSecurityFlags),
381381
mSandboxFlags(aSandboxFlags),
382-
mTriggeringSandboxFlags(0),
382+
383383
mInternalContentPolicyType(nsIContentPolicy::TYPE_DOCUMENT) {
384384
// Top-level loads are never third-party
385385
// Grab the information we can out of the window.
@@ -575,9 +575,7 @@ LoadInfo::LoadInfo(const LoadInfo& rhs)
575575
mForcePreflight(rhs.mForcePreflight),
576576
mIsPreflight(rhs.mIsPreflight),
577577
mLoadTriggeredFromExternal(rhs.mLoadTriggeredFromExternal),
578-
// mServiceWorkerTaintingSynthesized must be handled specially during
579-
// redirect
580-
mServiceWorkerTaintingSynthesized(false),
578+
581579
mDocumentHasUserInteracted(rhs.mDocumentHasUserInteracted),
582580
mAllowListFutureDocumentsCreatedFromThisRedirectChain(
583581
rhs.mAllowListFutureDocumentsCreatedFromThisRedirectChain),
@@ -702,9 +700,7 @@ LoadInfo::LoadInfo(
702700
mParserCreatedScript(aParserCreatedScript),
703701
mHasStoragePermission(aHasStoragePermission),
704702
mIsMetaRefresh(aIsMetaRefresh),
705-
mIsFromProcessingFrameAttributes(false),
706-
mIsMediaRequest(false),
707-
mIsMediaInitialRequest(false),
703+
708704
mLoadingEmbedderPolicy(aLoadingEmbedderPolicy),
709705
mUnstrippedURI(aUnstrippedURI) {
710706
// Only top level TYPE_DOCUMENT loads can have a null loadingPrincipal

netwerk/base/PollableEvent.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,8 @@ static bool NewTCPSocketPair(PRFileDesc* fd[], bool aSetRecvBuff) {
138138
#endif
139139

140140
PollableEvent::PollableEvent()
141-
: mWriteFD(nullptr),
142-
mReadFD(nullptr),
143-
mSignaled(false),
144-
mWriteFailed(false),
145-
mSignalTimestampAdjusted(false) {
141+
142+
{
146143
MOZ_COUNT_CTOR(PollableEvent);
147144
MOZ_ASSERT(OnSocketThread(), "not on socket thread");
148145
// create pair of prfiledesc that can be used as a poll()ble

0 commit comments

Comments
 (0)