Path: utzoo!utgpu!watmath!iuvax!purdue!haven!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.unix.questions Subject: Re: Problems with ndbm Message-ID: <18934@mimsy.UUCP> Date: 7 Aug 89 18:57:26 GMT References: <34200002@zaphod> <34200003@zaphod> <18933@mimsy.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 22 In article <18933@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@mimsy.umd.edu Path: uunet!mimsy!chris