summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@cpan.org>1999-09-05 22:28:57 +0000
committerGurusamy Sarathy <gsar@cpan.org>1999-09-05 22:28:57 +0000
commit98627ae8f09f88a753760c651828da353f8c4989 (patch)
treed3e89396ce4754fbd1090514b0fbc11e2adf9b31 /ext
parentcd06dffe59d60ee6a2fdd7c81f8cef42c7026b36 (diff)
downloadperl-98627ae8f09f88a753760c651828da353f8c4989.tar.gz
fix data loss when more than one block is read from SDBM
*.dir file (suggested by Uwe Ohse <uwe@ohse.de>) p4raw-id: //depot/perl@4082
Diffstat (limited to 'ext')
-rw-r--r--ext/SDBM_File/sdbm/sdbm.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/ext/SDBM_File/sdbm/sdbm.c b/ext/SDBM_File/sdbm/sdbm.c
index 499871dfab..5952d719e7 100644
--- a/ext/SDBM_File/sdbm/sdbm.c
+++ b/ext/SDBM_File/sdbm/sdbm.c
@@ -431,9 +431,12 @@ getdbit(register DBM *db, register long int dbit)
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));
@@ -452,10 +455,12 @@ setdbit(register DBM *db, register long int dbit)
dirb = c / DBLKSIZ;
if (dirb != db->dirbno) {
- (void) memset(db->dirbuf, 0, DBLKSIZ);
+ 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));
@@ -463,8 +468,13 @@ setdbit(register DBM *db, register long int dbit)
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)