[Bf-committers] Klocwork source analysis

Joe Eagar joeedh at gmail.com
Sun Dec 3 15:37:04 CET 2006


Stephen Swaney wrote:
> On Sat, Dec 02, 2006 at 07:43:04PM -0700, Joe Eagar wrote:
>   
>> Why would PyObject_New fail though? I don't get it, that seems as likely 
>> as MEM_callocN failing.
>>     
>
> We check for errors not based on their likelihood but on their
> possibility.
>
> Allocation failures are usually described as out of memory errors.
> This is a shorthand description for the actual conditions: you asked
> for a block of memory and the system was unable to provide a
> *contiguous* block of that size.
>
> You may have 50 Meg free, but if it is fragmented into 1/2 K chunks, a
> request for 1K will fail.
>
> Another possibility is you simply requested an insanely huge amount.
> >From an actual forum post:
>
> Calloc returns nill: len=2053778024 in layerCopy_mdeformvert dw, total
> 10887064
>
> Yeah. 2,053,778,024 bytes.  Whether this represents a programming
> error, or simply outrageous user settings, we still don't want to
> crash blender.
>
> Good error checking is a mark of a robust application.
>
>   
I still think it's stupid for alloc functions; either you implement a 
full exception system to properly handle those sorts of errors or don't 
check them at all.

And in "We check for errors not based on their likelihood but on their

possibilit," likelihood and possibility and synonyms ;)

Anyway, I guess it doesn't matter since I've decided to commit the checks anyway, to maintain bpy code standards.

:)

Joe



More information about the Bf-committers mailing list