FYI: Moving discussion to Axis2/C list. Read the inline reply

> Manjula Peiris wrote:
>
>>On Wed, 2008-03-19 at 15:19 +0530, Senaka Fernando wrote:
>>
>>
>>>Hi all,
>>>
>>>We have a habit of lavishly using,
>>>
>>>AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
>>>
>>>However, we have to set this error only if we fail in a AXIS2_MALLOC()
>>>
>>>For instance, if something like a axutil_strdup() fails, it is the duty
>>> of
>>>axutil_strdup() to log this error. If we do a axutil_strdup() on a NULL
>>>string, it too will return NULL. And, if we do this,
>>>
>>>type->my_string = axutil_strdup(env, str);
>>>
>>>if (!type->my_string)
>>>{
>>>    AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
>>>    return NULL;
>>>}
>>>
>>>We are making a big mistake.
>>>
>>>Then, according to our error logging, it will be incorrectly logged as a
>>>AXIS2_ERROR_NO_MEMORY.
>>>
>>>What we should be having is,
>>>
>>>type->my_string = axutil_strdup(env, str);
>>>
>>>if (!type->my_string)
>>>{
>>>    return NULL;
>>>}
>>>
>>>OR,
>>>
>>>type->my_string = axutil_strdup(env, str);
>>>
>>>if (!type->my_string)
>>>{
>>>    AXIS2_ERROR_SET(env->error, AXIS2_type_in_caps_CREATION_FALIED,
>>>        AXIS2_FAILURE);
>>>    return NULL;
>>>}
>>>
>>>
>>
>>So in these cases how we log the exact reason whether it is due to no
>>memory or null string?.
>>Can't we call the strdup function only if the passing string is not
>>null. Then it will fail only due to no memory.
>>
>>
> +1. It is meaningless strduping a NULL string
> thanks
> Damitha

Yes, that is true. However, strdup() was just one example. You can find
the same in many other forms. A failure in such is not always due to a
NULL param. I explained this in my previous reply to this thread.

Regards,
Senaka

>
>>
>>
>>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to