Re: Why check NPP instance != NULL?
Oleksandr Gavenko <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.plugins |
|---|---|
| Message-ID | <[email protected]> |
On 2011-04-15 23:52, Benjamin Smedberg wrote:
> On 4/15/11 5:32 PM, Oleksandr Gavenko wrote:
>>
>> They use such pattern:
>>
>> if (instance==NULL)
>> return NPERR_INVALID_INSTANCE_ERROR;
>>
>> for functions that pass 'NPP instance' arg (like NPP_New, NPP_Destroy,
>> NPP_GetValue).
>>
>> Why this need?
> We are practicing defensive programming. The null check is cheap, and
> since we really don't know whether plugin code might have bugs, we just
> do it for sanity's sake.
>
From
http://devedge-temp.mozilla.org/library/manuals/2002/plugin/1.0/plugin.pdf
NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value)
{
if(instance == NULL)
return NPERR_INVALID_INSTANCE_ERROR;
...
else if (variable == NPPVpluginScriptableIID) {
nsIID* ptr = (nsIID *)NPN_MemAlloc(sizeof(nsIID));
*ptr = scriptableIID;
*(nsIID **)value = ptr;
...
}
Here check for 'instance' but no check for 'value'!
I like defensive programming. But if you call 'memcpy'
you SHOULD NOT pass NULL because this call have no sense.
So question: all input pointer MUST be checked for NULL?
Or 'NPP instance' is special case?
Seems that docs say that 'instance' always non NULL:
https://developer.mozilla.org/En/NPP_GetValue
https://developer.mozilla.org/en/NPP_New
--
Best regards!