[GRASS-dev] etc file finder, take 2

Glynn Clements glynn at gclements.plus.com
Fri Apr 20 04:27:48 EDT 2007


Hamish wrote:

> > > > use GPATH_MAX as the size of the path buffer (I've
> > > > been replacing various random constants with that value as I find
> > > > them; also for GNAME_MAX and GMAPSET_MAX)..
> > > 
> > > more of a comment than a question-
> > > 
> > > "char input_map[GNAME_MAX];" is often used to hold input=map at mapset
> > > name, when the array often should be able to hold "GNAME_MAX + @ +
> > > GMAPSET_MAX + \0" = 514 chars.
> > > 
> > > GNAME_MAX is long enough (256, gis.h) that map at mapset should rarely
> > > exceed that, but it's something to look out for.
> > > 
> > > Perhaps gis.h should also have G_FULLYQUALIFIED_MAX ?
> 
> Glynn:
> > Who said that GNAME_MAX referred to the length of an *unqualified*
> > name?
> > 
> > It's just an arbitrary value used for array dimensions; nothing
> > actually checks map names against that value.
> 
> 
> /* File/directory name lengths */
> #define GNAME_MAX 256
> #define GMAPSET_MAX 256
> 
> #define GPATH_MAX 4096
> 
> 
> if GMAPSET_MAX is 256, and GNAME_MAX should be able to hold name at mapset,
> shouldn't GNAME_MAX be at least GMAPSET_MAX+2? 
> [2= 1 char long mapset name + @]

Not necessarily; it just means that if you have really long names[1]
for both maps and mapsets, you may not be able to use fully-qualified
names.

[1] 256 characters > 3 * 80-character lines, which is *really*
long[2].

[2] Long enough that I should probably look at changing struct Reclass
to use a dynamically-allocated char* rather than a fixed-sized array,
given that the G__ structure has one instance per descriptor.

> otherwise concat can theoretically overflow.

Simply copying the map name into the array can theoretically overflow. 
Nothing prevents the user from specifying a map name which exceeds
GNAME_MAX (likewise for mapsets).

> (playing devil's advocate here to make the allocs a little more bad-
> assumption-proof)

The actual values don't really matter unless something actually checks
them. The main advantage of pre-defined constants is that it
discourages authors from using excessively small buffers.

-- 
Glynn Clements <glynn at gclements.plus.com>




More information about the grass-dev mailing list