Closed Bug 267073 Opened 20 years ago Closed 4 years ago

Fix code errors in nsStringBundle

Categories

(Core :: Internationalization, defect)

x86
Windows XP
defect
Not set
trivial

Tracking

()

RESOLVED INACTIVE

People

(Reporter: timeless, Unassigned)

References

()

Details

(Keywords: good-first-bug, helpwanted)

Attachments

(1 file, 5 obsolete files)

The url contains a code audit. Most of these are unchecked allocs, some trigger
FMM, one references an undeclared variable, one isn't released at all, and
there's an else after return for good measure.

if you are interested in picking up this bug and need help figuring out the
right allocator/release pair, note that the answer can be found by checking the
header that declares the allocator.
i can try to play a little bit.
Whiteboard: [good first bug]
Attached patch Some fixes (obsolete) — Splinter Review
This should fix some of the problems. When I find time again, I'll look at the
others (where I'll have to look a bit through lxr to see what's wrong).
Attachment #171641 - Flags: review?(timeless)
Calling delete on a pointer allocated via ToNewCString is wrong.  It should use
nsMemory::Free.

Attachment #171641 - Flags: review?(timeless)
Attached patch The same corrected (obsolete) — Splinter Review
Thanks!
Attachment #171652 - Flags: review?(bzbarsky)
I think asking timeless for review is the right idea... I won't have time for a
real review of this patch for probably a week at least...
Attachment #171652 - Flags: review?(bzbarsky) → review?(timeless)
Comment on attachment 171652 [details] [diff] [review]
The same corrected

thanks for working on this.

>Index: intl/strres/src/nsStringBundle.cpp
>@@ -248,17 +249,20 @@ nsStringBundle::GetStringFromID(PRInt32 
>   rv = LoadProperties();
>   if (NS_FAILED(rv)) return rv;
>   
>   *aResult = nsnull;
>   nsAutoString tmpstr;

it looks like rv isn't used past this point.
could we replace ret with rv?
>   nsresult ret = GetStringFromID(aID, tmpstr);

I think i'd rather an early return:
  if (NS_FAILED(ret)) return ret; /* i'd rather rv as mentioned above */
instead of this indented if block:
>   if (NS_SUCCEEDED(ret))
>+  {
>     *aResult = ToNewUnicode(tmpstr);
>+    NS_ENSURE_TRUE(*aResult,NS_ERROR_OUT_OF_MEMORY);
please include spaces after commas. (occurs a couple of times)
>+  }
>   return ret;
> }

>@@ -268,17 +272,20 @@ nsStringBundle::GetStringFromName(const 
same comment

>@@ -698,21 +705,17 @@ nsStringBundleService::recycleEntry(bund
> }
> 
> NS_IMETHODIMP
> nsStringBundleService::CreateBundle(const char* aURLSpec, 
>                                     nsIStringBundle** aResult)
> {
> #ifdef DEBUG_tao_
>   printf("\n++ nsStringBundleService::CreateBundle ++\n");
>-  {
>-    printf("\n** nsStringBundleService::CreateBundle: %s\n",
>-           aURLSpec ? aURLSpec : "null");
>-    delete s;
>-  }
>+  printf("\n** nsStringBundleService::CreateBundle: %s\n",

this won't compile.

> #endif
> 
>   return getStringBundle(aURLSpec,aResult);
> }
Attachment #171652 - Flags: review?(timeless) → review-
Attached patch Corrected version (obsolete) — Splinter Review
How about that?
Attachment #171641 - Attachment is obsolete: true
Attachment #171652 - Attachment is obsolete: true
Attachment #171747 - Flags: review?(timeless)
Comment on attachment 171747 [details] [diff] [review]
Corrected version

Sorry timeless, I found some mistakes myself...
Attachment #171747 - Flags: review?(timeless)
Attached patch More fixes (obsolete) — Splinter Review
Now, this should be better. I'm afraid it took some time, but I completely
forgot about uploading that patch...
Attachment #171747 - Attachment is obsolete: true
Attachment #172379 - Flags: review?(timeless)
(In reply to comment #9)
> Created an attachment (id=172379) [edit]
> More fixes
> 
> Now, this should be better. I'm afraid it took some time, but I completely
> forgot about uploading that patch...

timeless asked me to look at the patch - nsStringBundle::GetCombinedEnumeration
has some marked lines that you don't seem to touch.  Do those not need to be
fixed?  291, 292, and 299 look ok to me, but I think the return value from line
284 needs to be checked.
I don't see what needs to be checked in 284 (ENSURE_TRUE(*aResult...) is already
present), please tell me what you mean (the same would be for 261).
I know I haven't yet corrected all errors, as I've had not much time and it was
not completely clear to me what to do there. But I'll look at them as soon as
possible.
Found what to do therefore, it wasn't really that hard...
Attached patch patch (obsolete) — Splinter Review
Does lines are fixed now, please let me know what additional checks you want!
Attachment #172379 - Attachment is obsolete: true
Attachment #172572 - Flags: review?(cst)
Attachment #172379 - Flags: review?(timeless)
Comment on attachment 172572 [details] [diff] [review]
patch

Sorry, I'm not a peer for the relevant module, so I can't actually r+ the patch
(it looks good to me, though).
Attachment #172572 - Flags: review?(cst) → review?(smontagu)
Attachment #172572 - Flags: review?(smontagu) → review+
Attachment #172572 - Flags: superreview?(timeless)
Comment on attachment 172572 [details] [diff] [review]
patch

sorry, i'm not an sr. but thanks for working on this :).

+  rv=GetStringFromID(aID, tmpstr);
+  rv=NS_NewArray(getter_AddRefs(resultArray));
+    rv=propEnumerator->HasMoreElements(&hasMore);

to match the style for this file, you should have spaces around the = .
Attachment #172572 - Flags: superreview?(timeless) → superreview?(bzbarsky)
Is it important to follow the style of a particular file up to those details?
Do you have any reason not to? Mozilla.org doesn't impose any particular coding
style, but within a single file (or depending on the situation, within a single
directory or a single module), the consistency is a good thing (TM). 
 
OK, you persuaded me...
Attachment #172572 - Attachment is obsolete: true
Attachment #172667 - Flags: superreview?(bzbarsky)
Attachment #172572 - Flags: superreview?(bzbarsky)
Comment on attachment 172667 [details] [diff] [review]
with spaces changed

sr=bzbarsky.  Let me know if this needs landing (though I assume timeless will
check this in).
Attachment #172667 - Flags: superreview?(bzbarsky) → superreview+
Assignee: smontagu → domob
Checked in on trunk for 1.8b.  Not resolving, since I'm not sure whether there
is more to be done here.
This patch introduced a bunch of meaningless assertions. It is not illegal for
GetStringFromName to fail. I'm not even sure that it is illegal for
LoadProperties to fail, but I do think that NS_ENSURE_SUCCESS is overkill.
QA Contact: amyy → i18n
Keywords: good-first-bug
Whiteboard: [good first bug]

This good-first-bug hasn't had any activity for 6 months, it is automatically unassigned.
For more information, please visit auto_nag documentation.

Assignee: domob → nobody
Status: NEW → RESOLVED
Closed: 4 years ago
Resolution: --- → INACTIVE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: