Closed Bug 64209 Opened 24 years ago Closed 22 years ago

bad string usage in nsObjectFrame::Reflow

Categories

(Core Graveyard :: Plug-ins, defect, P3)

defect

Tracking

(Not tracked)

VERIFIED DUPLICATE of bug 108557
Future

People

(Reporter: dbaron, Assigned: dbaron)

References

Details

Attachments

(7 files, 3 obsolete files)

There's some bad string usage in nsObjectFrame::Reflow.  There's a free memory
mismatch (FMM) at |delete [] cString|, and also some leaks.  Patch coming
shortly, although it will need a good bit more testing...
Oops, I meant to assign this to myself.
Assignee: av → dbaron
Keywords: approval, patch, review
Status: NEW → ASSIGNED
Priority: -- → P3
Target Milestone: --- → mozilla0.8
-        if((rv = GetBaseURL(baseURL)) != NS_OK)
-            return rv;
+        if (NS_SUCCEEDED(rv = GetBaseURL(*getter_AddRefs(baseURL))))
+          return rv;

Shouldn't that be NS_FAILED ?


-        rv = NS_NewURI(&fullURL, src, baseURL);
-        if ( rv != NS_OK )
+        rv = NS_NewURI(getter_AddRefs(fullURL), src, baseURL);
+        if (NS_SUCCEEDED(rv))

And same there...

+        rv = NS_NewURI(getter_AddRefs(fullURL), src, baseURL);
         if ( rv != NS_OK )

And then you could use NS_FAILED there too...

+        char *extension = (offset == kNotFound)
...
+        if (extension)
+          nsMemory::Free(extension);

Could you use an nsXPIDLCString here?
r=jag
Target Milestone: mozilla0.8 → mozilla0.9
*** Bug 68807 has been marked as a duplicate of this bug. ***
I should probably replace my replacement for mimeType in two places with a

static const char* kJavaMimeType = "application/x-java-vm";

so I don't write it in two places...
Yeah, that'd be nice.
24553 -- r=av

Just out of curiosity: what is your 'comfortable' line length after which you 
break it in two?
80col?
Should

  if (classid.Find("java:") != -1)

be something like:

  if (Substring(classid, 0, 5) == NS_LITERAL_CSTRING("java:"))

otherwise, you'll match

  xxxjava:etc

and end up with

  va:etc

Same for ``clsid:''. (scc, correct my string-fu if I've botched it.) Certainly, 
you haven't changed the semantics, so feel free to check in as-is. (I just don't 
know if you want to be cvs-blamed for it. ;-)

The rest looks ok.

sr=waterson
Fix checked in 2001-03-09 19:17 PST but keeping the bug opened to deal with the
issues waterson mentioned (which were in code that I was re-indenting).
Moving to 0.9.1 for dealing with the remaining issues.
Target Milestone: mozilla0.9 → mozilla0.9.1
Target Milestone: mozilla0.9.1 → mozilla0.9.2
Target Milestone: mozilla0.9.2 → Future
Attached patch classid.Find fix (obsolete) — Splinter Review
Why not just to check offset returned by Find?
If it's zero, then we have exactly what we're looking for
Attached patch oops, fix second Find too (obsolete) — Splinter Review
in theory, a find should be more expensive than a substring+compare
This is what last "1" in Find() for...
Actually, that will cause it to look at offsets 0 and 1. That old code is weird
:-) If you mean "Compare this substring against that string" then why not write
it like that? See waterson's comment for a good example.
I wanted it to look only at offset 0, but this is impossible
(should new bug be filed on this?). The ideal case would be to have
StartsWith(). Unfortunately, we don't have it. Substring and compare 
causes extra (and unneeded) allocation...
Substring doesn't allocate a new buffer.  It's dependent on the existing one.
Then again, I wouldn't mind putting StringBeginsWith and StringEndsWith in
nsReadableUtils...
OK, don't want to bother with nsReadableUtils.
Attachment #70495 - Attachment is obsolete: true
Attachment #70496 - Attachment is obsolete: true
Oops, attached wrong diff, sorry (64209 vs. 64092)





BTW, what about 


   nsCRT::strncmp(classid.get() NS_LITERAL_STRING("java:").get(), 5) 


?
Attachment #71471 - Attachment is obsolete: true
You can only have the compiler concatenate string literals that way, not char
pointers or char arrays. Code looks okay on first glance.
JAVA_CLASS_ID needs to go away as well. See bug 108557.
Huh, fix for bug #108557 completely removed these string manipulations.
(it's wrong, though :-) ).
Should we close this bug (and make sure fix for 108557 correctly works with
strings) or make it depend on 108557 ?

jag: I meant to write nsCRT::strncmp(classid.get(), .....); (missed comma). :-)
It certainly wouldn't hurt to combine those two efforts. Can you post your
comments in there on their patch (based on your patch)? I'll mark it "depends
on" for now.
Depends on: 108557
They get rid of second string find ("clsid:") and use
Substring(classid, 0, 5) == NS_LITERAL_STRING(blah-blah) for first one.
Even more, I think they can get rid of classid.Cut() at all...
jag, dbaron: I still wonder if substring() and compare is faster/better
that nsCRT::strncmp()?
Comment on attachment 71474 [details] [diff] [review]
use Substring() instead of Find()

Why not simply use nsCRT::strncmp() to do the comparisons, rather than
Substring()?

http://lxr.mozilla.org/seamonkey/source/xpcom/ds/nsCRT.h#208
Attachment #71474 - Flags: needs-work+
I don't care. Substring doesn't copy, so it should be just as cheap, and I guess

  if (Substring(str1, 0, 5) == NS_LITERAL_STRING("java:"))

reads easier for me than

  if (!nsCRT::strncmp(str1.get(), NS_LITERAL_STRING("java:").get(), 5))
Note that bug #108557 is fixed; all we have now is
nsCRT::strncmp(classid.get(), NS_LITERAL_STRING("java:").get(), 5);

Can we close this bug now?

*** This bug has been marked as a duplicate of 108557 ***
Status: ASSIGNED → RESOLVED
Closed: 22 years ago
Resolution: --- → DUPLICATE
mass duplicate verifications . For filtering purposes, pls use keywd
"massdupverification"

Status: RESOLVED → VERIFIED
Product: Core → Core Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: