Closed Bug 117418 Opened 23 years ago Closed 23 years ago

nsWSRunObject.cpp:704: warning: `PRInt32 curStartOffset' might be used uninitialized in this function

Categories

(Core :: DOM: Editor, defect, P3)

x86
Linux
defect

Tracking

()

VERIFIED FIXED
mozilla0.9.9

People

(Reporter: timeless, Assigned: mozeditor)

References

()

Details

Attachments

(2 files, 3 obsolete files)

/mnt/3/braddr/mozilla/Linux_2.4.17- rc1_Clobber/mozilla/editor/libeditor/html/nsWSRunObject.cpp: In function `static nsresult nsWSRunObject::PrepareToJoinBlocks(nsHTMLEditor *, nsIDOMNode *, nsIDOMNode *)': /mnt/3/braddr/mozilla/Linux_2.4.17- rc1_Clobber/mozilla/editor/libeditor/html/nsWSRunObject.cpp:158: warning: unused variable `nsresult res' /mnt/3/braddr/mozilla/Linux_2.4.17- rc1_Clobber/mozilla/editor/libeditor/html/nsWSRunObject.cpp: In function `static nsresult nsWSRunObject::PrepareToDeleteRange(nsHTMLEditor *, nsCOMPtr<nsIDOMNode> *, PRInt32 *, nsCOMPtr<nsIDOMNode> *, PRInt32 *)': /mnt/3/braddr/mozilla/Linux_2.4.17- rc1_Clobber/mozilla/editor/libeditor/html/nsWSRunObject.cpp:176: warning: unused variable `nsresult res' /mnt/3/braddr/mozilla/Linux_2.4.17- rc1_Clobber/mozilla/editor/libeditor/html/nsWSRunObject.cpp: In function `static nsresult nsWSRunObject::PrepareToSplitAcrossBlocks(nsHTMLEditor *, nsCOMPtr<nsIDOMNode> *, PRInt32 *)': /mnt/3/braddr/mozilla/Linux_2.4.17- rc1_Clobber/mozilla/editor/libeditor/html/nsWSRunObject.cpp:213: warning: unused variable `nsresult res' /mnt/3/braddr/mozilla/Linux_2.4.17- rc1_Clobber/mozilla/editor/libeditor/html/nsWSRunObject.cpp: In method `nsresult nsWSRunObject::InsertText(const nsAReadableString &, nsCOMPtr<nsIDOMNode> *, PRInt32 *, nsIDOMDocument *)': /mnt/3/braddr/mozilla/Linux_2.4.17- rc1_Clobber/mozilla/editor/libeditor/html/nsWSRunObject.cpp:447: warning: comparison between signed and unsigned /mnt/3/braddr/mozilla/Linux_2.4.17- rc1_Clobber/mozilla/editor/libeditor/html/nsWSRunObject.cpp: In method `nsresult nsWSRunObject::PriorVisibleNode(nsIDOMNode *, int, nsCOMPtr<nsIDOMNode> *, PRInt32 *, PRInt16 *)': /mnt/3/braddr/mozilla/Linux_2.4.17- rc1_Clobber/mozilla/editor/libeditor/html/nsWSRunObject.cpp:572: warning: unused variable `nsresult res' /mnt/3/braddr/mozilla/Linux_2.4.17- rc1_Clobber/mozilla/editor/libeditor/html/nsWSRunObject.cpp: In method `nsresult nsWSRunObject::NextVisibleNode(nsIDOMNode *, int, nsCOMPtr<nsIDOMNode> *, PRInt32 *, PRInt16 *)': /mnt/3/braddr/mozilla/Linux_2.4.17- rc1_Clobber/mozilla/editor/libeditor/html/nsWSRunObject.cpp:627: warning: unused variable `nsresult res' /mnt/3/braddr/mozilla/Linux_2.4.17- rc1_Clobber/mozilla/editor/libeditor/html/nsWSRunObject.cpp: In method `nsresult nsWSRunObject::GetWSNodes()': /mnt/3/braddr/mozilla/Linux_2.4.17- rc1_Clobber/mozilla/editor/libeditor/html/nsWSRunObject.cpp:704: warning: `PRInt32 curStartOffset' might be used uninitialized in this function /mnt/3/braddr/mozilla/Linux_2.4.17- rc1_Clobber/mozilla/editor/libeditor/html/nsWSRunObject.cpp:704: warning: `PRInt32 curEndOffset' might be used uninitialized in this function /mnt/3/braddr/mozilla/Linux_2.4.17- rc1_Clobber/mozilla/editor/libeditor/html/nsWSRunObject.cpp: In method `nsresult nsWSRunObject::DeleteChars(nsIDOMNode *, int, nsIDOMNode *, int)': /mnt/3/braddr/mozilla/Linux_2.4.17- rc1_Clobber/mozilla/editor/libeditor/html/nsWSRunObject.cpp:1604: warning: comparison between signed and unsigned /mnt/3/braddr/mozilla/Linux_2.4.17- rc1_Clobber/mozilla/editor/libeditor/html/nsWSRunObject.cpp:1615: warning: comparison between signed and unsigned /mnt/3/braddr/mozilla/Linux_2.4.17- rc1_Clobber/mozilla/editor/libeditor/html/nsWSRunObject.cpp: In method `nsresult nsWSRunObject::GetCharAfter(nsWSRunObject::WSPoint &, nsWSRunObject::WSPoint *)': /mnt/3/braddr/mozilla/Linux_2.4.17- rc1_Clobber/mozilla/editor/libeditor/html/nsWSRunObject.cpp:1730: warning: statement with no effect The highlighted portions are for the #704 build warnings. they're especially scary and strange. there are only two assignments: curStartOffset = 0; curEndOffset = len; otherwise both of them are undefined. please clean this code out, it's scary. as is the code could be rewritten with cur*Offset as #defines.
098
Severity: normal → major
Status: NEW → ASSIGNED
Target Milestone: --- → mozilla0.9.8
Hey Joe, this is pretty easy to fix, though, I wasn't sure if you were intentionally not checking for returned error values in some cases. Also, as timeless points out, it's a bit strange how curStartOffset is used in nsWSRunObject::GetWSNodes(), was there some code that used to exist in that method that modified curStartOffset? If not perhaps we should just remove it, and init curEndOffset to zero.
Assignee: kin → jfrancis
Status: ASSIGNED → NEW
Priority: -- → P3
I have begun auditing this code, which was written in a blur of caffeine. But I'm not done yet. As you describe, it looks halfway rewritten.
Status: NEW → ASSIGNED
pushing off 098 to 099
Target Milestone: mozilla0.9.8 → mozilla0.9.9
the swami says: things that will not land in 099!
Target Milestone: mozilla0.9.9 → mozilla1.0
Attached patch i prefer guru's (obsolete) — Splinter Review
Keywords: mozilla0.9.9
Target Milestone: mozilla1.0 → ---
Comment on attachment 66420 [details] [diff] [review] i prefer guru's Strangely, I'm not seeing these warnings, though I usually do see "might be used uninitialized" warnings. Anyway, the fix looks like a good idea, r=akkana
Attachment #66420 - Flags: review+
Another "uninitialized" warnings that are still there: editor/libeditor/html/nsWSRunObject.cpp:1804 `PRInt32 startOffset' might be used uninitialized in this function `PRInt32 endOffset' might be used uninitialized in this function
Blocks: 59652
fix checked in
Status: ASSIGNED → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
hrm, yes i checked in *a* fix, but this bug isn't fixed. what in the world was i thinking?
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Attached patch Diffs of nsWSRunObject.cpp (obsolete) — Splinter Review
I have rewritten this routine.
Attachment #66420 - Attachment is obsolete: true
Status: REOPENED → ASSIGNED
Whiteboard: fixinhand; need r=,sr=
Target Milestone: --- → mozilla0.9.9
more lines removed than added :-) nsCOMPtr<nsIDOMNode> priorNode; while (!mStartNode) { // we haven't found the start of ws yet. Keep looking + res = GetPreviousWSNode(curStartNode, blockParent, address_of(priorNode)); + NS_ENSURE_SUCCESS(res, res); 1230 nsresult 1231 nsWSRunObject::GetPreviousWSNode(nsIDOMNode *aStartNode, 1232 nsIDOMNode *aBlockParent, 1233 nsCOMPtr<nsIDOMNode> *aPriorNode) 1234 { 1235 // can't really recycle various getnext/prior routines because we have special needs 1236 // here. Need to step into inline containers but not block containers. 1237 if (!aStartNode || !aBlockParent || !aPriorNode) return NS_ERROR_NULL_POINTER; at first i thought i hade found a problem, and then i noticed the address_of. conclusion: this code is *scary*. As lxr qa, http://lxr.mozilla.org/seamonkey/ident?i=GetPreviousWSNode turned up two hits for the same function definition, i'll try to file a bug about it later.
fixing typo in prior diff
Attachment #67673 - Attachment is obsolete: true
When it's this hard to get something right, it's a sign you have the wrong data structures for the job. I revamped some stuff to make this routine simpler.
Attachment #67675 - Attachment is obsolete: true
header file changes
timeless, with latest patch yo uwill see 3 versions of GetPreviousWSNode(). However, this is not a bug, merely overloading. Nor is using pointers to comptrs a bug, though I admit it is pretty ugly here.
ok. it turns out my eyes deceived me. the problem was that i thought i saw two links to the same line, it turns out i transposed digits. If i had seen three, i probably wouldn't have worried (although it'd really help if i rewrote lxr to display the definitions).
Comment on attachment 67680 [details] [diff] [review] Differences of nsWSRunObject.cpp sr=kin@netscape.com with the changes we discussed.
Attachment #67680 - Flags: superreview+
Comment on attachment 67681 [details] [diff] [review] Differences of nsWSRunObject.h sr=kin@netscape.com
Attachment #67681 - Flags: superreview+
Whiteboard: fixinhand; need r=,sr= → fixinhand; need r=
Comment on attachment 67681 [details] [diff] [review] Differences of nsWSRunObject.h r=brade
Attachment #67681 - Flags: review+
Comment on attachment 67680 [details] [diff] [review] Differences of nsWSRunObject.cpp rs=brade
Attachment #67680 - Flags: review+
fix landed on trunk
Status: ASSIGNED → RESOLVED
Closed: 23 years ago23 years ago
Resolution: --- → FIXED
Can you fix this too: 9-10. editor/libeditor/html/nsWSRunObject.cpp:1711 (See 1st of 2 warnings in build log) `PRInt32 startOffset' might be used uninitialized in this function `PRInt32 endOffset' might be used uninitialized in this function 1709 1710 nsCOMPtr<nsIDOMNode> startNode, endNode; 1711 PRInt32 startOffset, endOffset; 1712 1713 nsresult res = NS_OK; you might fix the following for bonus points: 8. editor/libeditor/html/nsWSRunObject.cpp:1614 (See build log excerpt) Statement with no effect 1612 { 1613 *outPoint = aPoint; 1614 outPoint->mOffset; 1615 outPoint->mChar = GetCharAt(aPoint.mTextNode, aPoint.mOffset); 1616 } 15. editor/libeditor/html/nsWSRunObject.cpp:71 (See build log excerpt) `PRBool IsInlineNode(nsIDOMNode *)' defined but not used 69 70 static PRBool IsInlineNode(nsIDOMNode* node) 71 { 72 return !IsBlockNode(node); 73 }
timeless can you verify this one? thanks.
I still see some "might be used uninitialized" warnings in nsWSRunObject.cpp editor/libeditor/html/nsWSRunObject.cpp:1711 `PRInt32 startOffset' might be used uninitialized in this function `PRInt32 endOffset' might be used uninitialized in this function
reopen to address uninitialized variables
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Whiteboard: fixinhand; need r=
might be, but theyt aren't. Compiler seems a bit picky here.
Status: REOPENED → RESOLVED
Closed: 23 years ago23 years ago
Resolution: --- → FIXED
If GetCharAfter/GetCharBefore fails or returns a point with a null mTextNode, startOffset and endOffset will be used (and returned in outStartOffset and outEndOffset!) uninitialized in nsWSRunObject::GetAsciiWSBounds
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Even aside from that: warnings make it more difficult for other developers, since they have to wade through old warnings to figure out whether they've introduced any new problems.
editor no longer has any "xxx might be used uninitialized" warnings. Thanks!
Status: REOPENED → RESOLVED
Closed: 23 years ago23 years ago
Resolution: --- → FIXED
vrfy fixed (brad tinderbox)
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: