Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!caip!pyrnj!mirror!ima!johnl From: johnl@ima.UUCP (John R. Levine) Newsgroups: net.unix-wizards Subject: Has dbm ever worked? Message-ID: <240@ima.UUCP> Date: Tue, 7-Oct-86 12:29:26 EDT Article-I.D.: ima.240 Posted: Tue Oct 7 12:29:26 1986 Date-Received: Wed, 8-Oct-86 06:36:02 EDT Reply-To: johnl@ima.UUCP (John R. Levine) Distribution: net Organization: Javelin Software Corporation Lines: 26 Keywords: dbm nextkey bug Summary: nextkey() routine appears never to have worked correctly I was looking at the dbm routines the other day. If you haven't seen them, they're a neat little set of routines that maintain (key, data) pairs on the disk, with the key and data both being arbitrary byte strings, in such a way that you can fetch the data for a given key usually with only one disk read, even for a file many megabytes long, and the file is usually less than twice the size of the underlying data, which is not bad for such schemes. They were sent out with V7 and appear in the BSD releases and many Sys III and Sys V systems. Anyway, there are routines called firstkey() and nextkey() which let you sequence through all of the keys in the file. It appears to me that nextkey() has never worked for databases larger than one block. In the nextkey routine, it goes through some magic to get a key, and then (for reasonable reasons) checks to make sure that the key is in the data base and not the very first key. Unfortunately, when it looks up the very first key, that uses the same buffer where the key it was looking at lived, and smashes it. Am I missing something? It's not that complicated, and experiments verify that nextkey() fails miserably to dump out the contents of the dbm database for news history. I can fix it, but would just as soon not reinvent the wheel again. -- John R. Levine, Javelin Software Corp., Cambridge MA +1 617 494 1400 { ihnp4 | decvax | cbosgd | harvard | yale }!ima!johnl, Levine@YALE.EDU The opinions expressed herein are solely those of a 12-year-old hacker who has broken into my account and not those of any person or organization.