[GRASS5] Re: G_fatal

Hi Edzer, hi all,
(cc to grass5)

I would like to know the opinion of the develovers on this:

On Mon, Apr 23, 2001 at 12:05:16PM +0200, Edzer J. Pebesma wrote:

Hi Markus,

according to the programmers manual, G_fatal is defined as

int G_fatal_error(char *);

but according to gisdefs.h, it is

int G_fatal_error(char *,...);

I see that quite some code is relying on the second definition.
Should it be changed in the progr. manual, or should everyone
adopt the former?

Same thing for G_warning().
--
Edzer

Thanks for pointing it out,

Markus

----------------------------------------
If you want to unsubscribe from GRASS Development Team mailing list write to:
minordomo@geog.uni-hannover.de with
subject 'unsubscribe grass5'

Markus Neteler wrote:

> according to the programmers manual, G_fatal is defined as
>
> int G_fatal_error(char *);
>
> but according to gisdefs.h, it is
>
> int G_fatal_error(char *,...);

The first one will usually require the programmer to sprintf to a
buffer, which easily leads to buffer overflows. The second one could
be implemented much more safely.
--
Edzer

----------------------------------------
If you want to unsubscribe from GRASS Development Team mailing list write to:
minordomo@geog.uni-hannover.de with
subject 'unsubscribe grass5'

Hi Markus and Edzer

Markus Neteler wrote:

On Mon, Apr 23, 2001 at 12:05:16PM +0200, Edzer J. Pebesma wrote:
> Hi Markus,
>
> according to the programmers manual, G_fatal is defined as
>
> int G_fatal_error(char *);
>
> but according to gisdefs.h, it is
>
> int G_fatal_error(char *,...);
>
> I see that quite some code is relying on the second definition.
> Should it be changed in the progr. manual, or should everyone
> adopt the former?
>
> Same thing for G_warning().

Change the programmers manual. At some point, somebody wanted these
functions to be able to accept variable arguments, and I see no reason
(logical or software engineering wise) at this time to change them back
to a single string. Besides, changing the manual is less work than
changing several different places in the code.

Just my 2 cents worth.

--
Sincerely,

Jazzman (a.k.a. Justin Hickey) e-mail: jhickey@hpcc.nectec.or.th
High Performance Computing Center
National Electronics and Computer Technology Center (NECTEC)
Bangkok, Thailand

People who think they know everything are very irritating to those
of us who do. ---Anonymous

Jazz and Trek Rule!!!

----------------------------------------
If you want to unsubscribe from GRASS Development Team mailing list write to:
minordomo@geog.uni-hannover.de with
subject 'unsubscribe grass5'

"Edzer J. Pebesma" wrote:

Markus Neteler wrote:

> > according to the programmers manual, G_fatal is defined as
> >
> > int G_fatal_error(char *);
> >
> > but according to gisdefs.h, it is
> >
> > int G_fatal_error(char *,...);

The first one will usually require the programmer to sprintf to a
buffer, which easily leads to buffer overflows. The second one could
be implemented much more safely.
--

I agree with Edzer, althought I still haven't seen a module
that uses the second one (but until now I only played with
raster/vector conversion modules and with s.voronoi/s.delaunay...
BTW, I nearly fixed/rewrited them, in the next few days I will send
them to Markus...). IMHO it would be better to update the manual :slight_smile:
Andrea Aime

----------------------------------------
If you want to unsubscribe from GRASS Development Team mailing list write to:
minordomo@geog.uni-hannover.de with
subject 'unsubscribe grass5'

From: Markus Neteler <neteler@geog.uni-hannover.de>

Hi Edzer, hi all,
(cc to grass5)

I would like to know the opinion of the develovers on this:

On Mon, Apr 23, 2001 at 12:05:16PM +0200, Edzer J. Pebesma wrote:
> Hi Markus,
>
> according to the programmers manual, G_fatal is defined as
>
> int G_fatal_error(char *);
>
> but according to gisdefs.h, it is
>
> int G_fatal_error(char *,...);
>
> I see that quite some code is relying on the second definition.
> Should it be changed in the progr. manual, or should everyone
> adopt the former?
>

Hi all,

src/libes/gis/error.c defines the latter(G_fatal_error(char *msg,...),
G_warning(char *msg,...)). And its usage is more convenient than the former.
The former requires an additional buffer to store a message in most cases.

Just my thought.

Regards,
Huidae Cho

----------------------------------------
If you want to unsubscribe from GRASS Development Team mailing list write to:
minordomo@geog.uni-hannover.de with
subject 'unsubscribe grass5'

Hi all,

On Mon, Apr 23, 2001 at 07:43:13PM +0900, GRASS wrote:

From: Markus Neteler <neteler@geog.uni-hannover.de>
> Hi Edzer, hi all,
> (cc to grass5)
>
> I would like to know the opinion of the develovers on this:
>
> On Mon, Apr 23, 2001 at 12:05:16PM +0200, Edzer J. Pebesma wrote:
> > Hi Markus,
> >
> > according to the programmers manual, G_fatal is defined as
> >
> > int G_fatal_error(char *);
> >
> > but according to gisdefs.h, it is
> >
> > int G_fatal_error(char *,...);
> >
> > I see that quite some code is relying on the second definition.
> > Should it be changed in the progr. manual, or should everyone
> > adopt the former?
> >

Hi all,

src/libes/gis/error.c defines the latter(G_fatal_error(char *msg,...),
G_warning(char *msg,...)). And its usage is more convenient than the former.
The former requires an additional buffer to store a message in most cases.

.. I have updated the manual and put online:
http://www.geog.uni-hannover.de/grass/grassdevel.html#prog

Thanks to Edzer for indicating this,

Markus

----------------------------------------
If you want to unsubscribe from GRASS Development Team mailing list write to:
minordomo@geog.uni-hannover.de with
subject 'unsubscribe grass5'

Justin Hickey wrote:

> > according to the programmers manual, G_fatal is defined as
> >
> > int G_fatal_error(char *);
> >
> > but according to gisdefs.h, it is
> >
> > int G_fatal_error(char *,...);
> >
> > I see that quite some code is relying on the second definition.
> > Should it be changed in the progr. manual, or should everyone
> > adopt the former?
> >
> > Same thing for G_warning().

Change the programmers manual. At some point, somebody wanted these
functions to be able to accept variable arguments, and I see no reason
(logical or software engineering wise) at this time to change them back
to a single string. Besides, changing the manual is less work than
changing several different places in the code.

A counterpoint is that, when G_fatal_error etc were changed to use
vsprintf (or similar), any code which did this:

  G_fatal_error(msg);

should have been changed to:

  G_fatal_error("%s", msg);

Note that gcc has the "format" attribute for printf()-like functions,
so G_fatal_error etc should probably be declared like:

#ifdef __GNUC_MINOR__
int G_fatal_error(char *,...) __attribute__ ((__noreturn__, __format__ (__printf__, 1, 2)));

This allows the compiler to detect mismatches between the format
string and the arguments.

--
Glynn Clements <glynn.clements@virgin.net>

----------------------------------------
If you want to unsubscribe from GRASS Development Team mailing list write to:
minordomo@geog.uni-hannover.de with
subject 'unsubscribe grass5'