Problems with ndbm

Chris Torek chris at mimsy.UUCP
Tue Aug 8 04:57:26 AEST 1989


In article <18933 at mimsy.UUCP> I wrote:
>[someone else's code was probably something like this]:
>		x = dbm_fetch(thedb, thekey);
>		x.dptr[x.dsize] = '\0';
>		printf("%s\n", x.dptr);

and---O fool that I was---did not even notice that this corrupts
the memory buffer returned from dbm_fetch.

You are NOT allowed to scribble on the memory pointed to by
x.dptr!

In this particular case, the result is to clobber the key that
follows the key `thekey' in the ndbm buffer, or, if that is the
last datum, the next byte in the buffer, which is most likely
unused, but could be one byte of a two-byte index.

In any case, the operation is not legal, and while a subsequent
fetch of the same key is likely to work, nothing is guaranteed.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.unix.questions mailing list