Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A patch for sdbm #352

Closed
p5pRT opened this issue Aug 7, 1999 · 1 comment
Closed

A patch for sdbm #352

p5pRT opened this issue Aug 7, 1999 · 1 comment

Comments

@p5pRT
Copy link

@p5pRT p5pRT commented Aug 7, 1999

Migrated from rt.perl.org#1185 (status was 'resolved')

Searchable as RT1185$

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Aug 7, 1999

From uwe@ohse.de

i found a bug in the sdbm library. In short it loses data if it needs
more than one block in the .dir file.

The appended patch fixes the problem. It's not against the sdbm
included in perl and will possibly not patch in cleanly, but should
show what has to be done.

Regards, Uwe


Index​: sdbm.c

RCS file​: /var/cvs-pub/sdbm/sdbm.c,v
retrieving revision 1.1.1.1
diff -u -u -r1.1.1.1 sdbm.c
--- sdbm.c 1999/08/04 15​:49​:34 1.1.1.1
+++ sdbm.c 1999/08/07 14​:59​:12
@​@​ -8,7 +8,7 @​@​
  */

#ifndef lint
-static char rcsid[] = "$Id​: sdbm.c,v 1.1.1.1 1999/08/04 15​:49​:34 uwe Exp $";
+static char rcsid[] = "$Id​: sdbm.c,v 1.2 1999/08/04 22​:14​:11 uwe Exp $";
#endif

#include "config.h"
@​@​ -453,9 +453,12 @​@​
  dirb = c / DBLKSIZ;

  if (dirb != db->dirbno) {
+ int got;
  if (lseek(db->dirf, OFF_DIR(dirb), SEEK_SET) < 0
- || read(db->dirf, db->dirbuf, DBLKSIZ) < 0)
+ || (got=read(db->dirf, db->dirbuf, DBLKSIZ)) < 0)
  return 0;
+ if (got==0)
+ memset(db->dirbuf,0,DBLKSIZ);
  db->dirbno = dirb;

  debug(("dir read​: %d\n", dirb));
@​@​ -476,9 +479,12 @​@​
  dirb = c / DBLKSIZ;

  if (dirb != db->dirbno) {
+ int got;
  if (lseek(db->dirf, OFF_DIR(dirb), SEEK_SET) < 0
- || read(db->dirf, db->dirbuf, DBLKSIZ) < 0)
+ || (got=read(db->dirf, db->dirbuf, DBLKSIZ)) < 0)
  return 0;
+ if (got==0)
+ memset(db->dirbuf,0,DBLKSIZ);
  db->dirbno = dirb;

  debug(("dir read​: %d\n", dirb));
@​@​ -486,8 +492,13 @​@​

  db->dirbuf[c % DBLKSIZ] |= (1 << dbit % BYTESIZ);

+#if 0
  if (dbit >= db->maxbno)
  db->maxbno += DBLKSIZ * BYTESIZ;
+#else
+ if (OFF_DIR((dirb+1))*BYTESIZ > db->maxbno)
+ db->maxbno=OFF_DIR((dirb+1))*BYTESIZ;
+#endif

  if (lseek(db->dirf, OFF_DIR(dirb), SEEK_SET) < 0
  || write(db->dirf, db->dirbuf, DBLKSIZ) < 0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant