Closed Bug 782616 Opened 12 years ago Closed 12 years ago

Fix still more abuse of nsresult (storage/, toolkit/components/places/)

Categories

(Core :: General, defect)

defect
Not set
minor

Tracking

()

RESOLVED FIXED
mozilla18

People

(Reporter: ayg, Assigned: ayg)

References

Details

Attachments

(3 files, 2 obsolete files)

      No description provided.
I don't know what this code is trying to do, but I know it's wrong.  SetJournalMode() will return one of the JOURNAL_* constants, which are in the range 0-3.  These will always pass the NS_SUCCEEDED check, so this patch shouldn't change behavior.
Attachment #651729 - Flags: review?(mak77)
These two functions are supposed to return bool and PRInt32 respectively, not nsresult.  The BindInt64ByName call might conceivably fail, based on code inspection -- in that case, this changes the caller to return false instead of true (since any non-NS_OK nsresult will evaluate to true).  Likewise, GetNewSessionID() will now return -1 for the session id instead of something above 0x80000000, if CreateStatement() fails.  Tell me if you'd prefer some other way of handling the errors.  I could preserve existing behavior if you prefer.
Attachment #651734 - Flags: review?(mak77)
Attachment #651725 - Flags: review?(mak77) → review+
Comment on attachment 651729 [details] [diff] [review]
Remove unreached failure path from Database::InitSchema

Review of attachment 651729 [details] [diff] [review]:
-----------------------------------------------------------------

ugh! Good catch. Actually, we should keep the old error path, just fix the if condition to:
if (JOURNAL_WAL != SetJournalMode(mMainConn, JOURNAL_WAL))
Attachment #651729 - Flags: review?(mak77) → review-
ehr, sorry I inverted the condition, should be
if (JOURNAL_WAL == SetJournalMode(mMainConn, JOURNAL_WAL)) {
  // success
} else {
  // fail
}
Comment on attachment 651734 [details] [diff] [review]
Use more appropriate return types than nsresult

Review of attachment 651734 [details] [diff] [review]:
-----------------------------------------------------------------

::: toolkit/components/places/nsNavHistory.cpp
@@ +713,5 @@
>    nsresult rv = mDB->MainConn()->CreateStatement(NS_LITERAL_CSTRING(
>      "SELECT session FROM moz_historyvisits "
>      "ORDER BY visit_date DESC "
>    ), getter_AddRefs(selectSession));
> +  NS_ENSURE_SUCCESS(rv, -1);

I'd say to just return 0, that's what we do in other code parts. Mostly cause I didn't audit all the code to check if it properly handles negative session ids (at first glance it does properly, but you know...)
Bonus points if you also fix this to use 0 instead of -1 http://mxr.mozilla.org/mozilla-central/source/toolkit/components/places/tests/unit/test_async_history_api.js#553 should just be a mere replace.
Attachment #651734 - Flags: review?(mak77) → review-
Comment on attachment 657243 [details] [diff] [review]
Don't treat SetJournalMode's return type as nsresult

Review of attachment 657243 [details] [diff] [review]:
-----------------------------------------------------------------

::: toolkit/components/places/Database.cpp
@@ +559,5 @@
>    NS_ENSURE_SUCCESS(rv, rv);
>  
>    // Be sure to set journal mode after page_size.  WAL would prevent the change
>    // otherwise.
> +  if (JOURNAL_WAL != SetJournalMode(mMainConn, JOURNAL_WAL)) {

sorry, you copied my typo, this one should be == (SetJournalMode returns the current mode, so we ask to set wal and if it returns wal it succeeded)

r=me with this change.
Attachment #657243 - Flags: review?(mak77) → review+
Comment on attachment 657244 [details] [diff] [review]
Use more appropriate return types than nsresult, v2

Review of attachment 657244 [details] [diff] [review]:
-----------------------------------------------------------------

yep, thank you!
Attachment #657244 - Flags: review?(mak77) → review+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: