Re: [AD] Error in set_config_file() function with non existing file.

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Monday 02 August 2004 21:06, Grzegorz Adam Hankiewicz wrote:
> As discovered by Apollo8, calling set_config_file before allegro_init
> is dangerous because if the file doesn't exist, or it is a directory,
> allegro will core. Test case:

Well, as far as I know, the docs do state that no Allegro function is safe 
to call before install_allegro(), with the exception of set_uformat...

> The reason for the core is that some IO routine wants to set
> allegro_errno, which is NULL, because allegro_init has not been
> called yet. The following patch fixes this by avoiding any IO
> operations if the system driver has not been initialised.

Looks good.

> OTOH, I would like to suggest adding assertions for system_driver
> (there are already a few) to check for an uninitialised allegro
> system.

I think this is always a good idea.

> Since this would be a fairly usual check done for most
> of the API, instead of a cryptic assert for newbies to Allegro's
> internal, the assertion could be hidden behind a define like
> VERIFY_ALLEGRO_IS_INITIALISED() or something like that.

I personally think that a normal set of asserts are ok, certainly if 
there's a comment like /* test if Allegro has been initialised */ going 
with them.
Making a seperate define would be ugly too I think because as far as I know 
you can't nest preprocessor defines.
(ie, #define VERIFY_ALLEGRO_IS_INITIALISED() ASSERT(system_driver) doesn't 
work)

Evert





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/