Closed
Bug 253941
Opened 20 years ago
Closed 20 years ago
It's possible to assign into a nsCOMPtr from an incompatible type
Categories
(Core :: XPCOM, defect)
Tracking
()
RESOLVED
FIXED
People
(Reporter: Biesinger, Assigned: neil)
Details
Attachments
(1 file)
469 bytes,
patch
|
scc
:
review+
dbaron
:
superreview+
|
Details | Diff | Splinter Review |
nsCOMPtr<imgIContainer> mContainer; nsCOMArray<imgIRequest> mCursorArray; // [inherited] The specified URL values. Takes precedence over mCursor. Now doing mContainer = mCursorArray[i]; works. mContainer is null afterwards. it is rather unexpected that this compiles despite the different types. it seems to do a QI. Is this desired behaviour?
Is this specific to nsCOMArray?
Reporter | ||
Comment 2•20 years ago
|
||
(this was with gcc version 3.3.3 (SuSE Linux)) This following code also compiles: nsCOMPtr<imgIContainer> c; imgIRequest* r = ui->mCursorArray[i]; c = r; So, doesn't look specific to nsCOMArray.
From bug 264987, this code also compiled: nsIDocument* document = content->GetOwnerDoc(); nsCOMPtr<nsIDOMHTMLDocument> htmlDoc(document);
Assignee | ||
Comment 4•20 years ago
|
||
Using gcc 2.9.6 the following code does not compile: nsISupportsPrimitive p; nsCOMPtr<nsISupportsString> s = p;
Assignee | ||
Comment 5•20 years ago
|
||
Or indeed even with p correctly declared as a pointer. However it will compile with the assignment changed to a constructor.
Assignee | ||
Comment 6•20 years ago
|
||
At least, I have scrollback claiming it compiled...
Assignee | ||
Comment 7•20 years ago
|
||
Ok, so having saved my test file correctly the problem is the implicit nsQueryInterface(nsISupports*) constructor. Making it explicit fixes it. I didn't look for other constructors that needed fixing.
Assignee | ||
Comment 8•20 years ago
|
||
I couldn't find any other implicit conversions that could get abused.
Assignee: dougt → neil.parkwaycc.co.uk
Status: NEW → ASSIGNED
Assignee | ||
Updated•20 years ago
|
Attachment #163005 -
Flags: superreview?(dbaron)
Attachment #163005 -
Flags: review?(scc)
Attachment #163005 -
Flags: superreview?(dbaron) → superreview+
Comment 9•20 years ago
|
||
Comment on attachment 163005 [details] [diff] [review] Proposed patch r=scc make sure you build a whole tree with this before you check it in, in case there has been abuse
Attachment #163005 -
Flags: review?(scc) → review+
Comment 10•20 years ago
|
||
I personally would have opted for a configure rule to/in nspr for a PR_EXPLICIT or some such, so that compilers which do not recognize explicit when built with Mozilla will still treat this correctly, but otherwise good work.
We use |explicit| all over the place, and nscore.h already handles compilers that don't support it by defining it.
Comment 12•20 years ago
|
||
Thanks for the clarification, I must have just missed those explicit cases...
Assignee | ||
Comment 13•20 years ago
|
||
Fix checked in (again... I checked it in then backed it out when I realized I hadn't built accessibility, but then bz fixed my regressions anyway, thanks!)
Status: ASSIGNED → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•