GetTarget returns nsresult rv == 5177346, NS_FAILED(rv) returns false.

VERIFIED INVALID

Status

()

Core
RDF
P3
major
VERIFIED INVALID
19 years ago
18 years ago

People

(Reporter: edburns, Assigned: Chris Waterson)

Tracking

Trunk
All
Other
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

19 years ago
Look at the following code

        rv = gBookmarksDataSource->GetTarget(currentResource,
                                                    kNC_URL, true, 
                                                    getter_AddRefs(node));
        printf("debug: edburns rv: %d\n", rv);
        if (NS_FAILED(rv)) {
            printf("recursiveResourceTraversal: can't get url from 
currentResource\n");
            return;
        }
        
        // if so, make sure it's an nsIRDFLiteral
        rv = node->QueryInterface(NS_GET_IID(nsIRDFLiteral), 
                                  getter_AddRefs(literal));

Sometimes, the call to GetTarget returns 5177346.  Somehow, this value causes 
NS_FAILED(rv) to return TRUE.  But when I try to QI on the node, I get a seg 
fault.

If I replace NS_FAILED with 0 != rv, I'm ok.

Ed
(Assignee)

Comment 1

19 years ago
This error is NS_RDF_NO_VALUE, a "success code". A success code is
informational, and basically means, "nothing really bad happened, but since it's
not NS_OK, not exactly the thing you expected occurred."

The pattern you're using assumes that GetTarget() will always return a non-null
result parameter. That's just not the case; e.g., if you ask for the value of a
property that isn't there.

Instead, your code should read:

  rv = gBookmarksDataSource->GetTarget(currentResource, kNC_URL, true,
                                       getter_AddRefs(node));
  if (NS_FAILED(rv)) {
    // throw
  }

  if (node) {
    rv = node->QueryInterface(...); // etc.
  }
  else {
    // there was no kNC_URL property leading out of currentResource
  }

Hope that helps.
Status: NEW → RESOLVED
Last Resolved: 19 years ago
Resolution: --- → INVALID
(Reporter)

Comment 2

19 years ago
But that's just the thing: NS_FAILED(5177346) returns FALSE.  So I DO go down 
to do the QI and it segfaults!

Status: RESOLVED → REOPENED
Resolution: INVALID → ---
(Assignee)

Comment 3

19 years ago
NS_FAILED(5177346) *should* return 'false'. To assert this positively, 
NS_SUCCEEDED(5177346) is 'true'.

Please re-read what I wrote in my previous comment. Then, if not convinced, 
read the documentation in the IDL file. Here is a pointer:

http://lxr.mozilla.org/seamonkey/source/rdf/base/idl/nsIRDFDataSource.idl#64

To summarize, GetTarget() is allowed to return a null pointer as its result 
parameter. When it does so, it is polite and will give you NS_RDF_NO_VALUE as a 
result code. This is not "failure", which is why NS_FAILED() is not evaluating 
to 'true'.
Status: REOPENED → RESOLVED
Last Resolved: 19 years ago19 years ago
Resolution: --- → INVALID

Comment 4

18 years ago
verified invalid
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.