Xref: utzoo comp.bugs.4bsd:683 comp.unix.questions:5286 Path: utzoo!utgpu!water!watmath!clyde!rutgers!gatech!ncsuvx!lll-winken!lll-crg.llnl.gov!casey From: casey@lll-crg.llnl.gov (Casey Leedom) Newsgroups: comp.bugs.4bsd,comp.unix.questions Subject: Re: Dbm library Keywords: ndbm library Message-ID: <3046@lll-winken.llnl.gov> Date: 28 Jan 88 23:54:08 GMT References: <580@xyzzy.UUCP> Sender: usenet@lll-winken.llnl.gov Reply-To: casey@lll-crg.llnl.gov.UUCP (Casey Leedom) Organization: Lawrence Livermore National Laboratory Lines: 40 In article <580@xyzzy.UUCP> meissner@.UUCP (Michael Meissner) writes: > I remember quite awhile ago, there was a discussion of problems in the > dbm library, particularly when it has to split an index node. The problem is on line 499 of the 4.3BSD source for /usr/src/lib/libc/gen/ndbm.c. There is a comparison that involves a sizeof which converts an expression yielding a possibly negative value into an unsigned expression which doesn't compare right. As it turns out, sizeof yields an int in the VAX compiler instead of an unsigned, so the comparison works. There's some question as to what the official result type of sizeof should be since the early K&R simply said sizeof(E) was semantically an integer constant (K&R; C Reference Manual; section 7.2; page 188). However, later versions of K&R specified that it was an unsigned integer constant (sorry, I don't have a copy of such a later version to reference). The fix: *** /usr/src/lib/libc/gen/ndbm.c Sun Mar 9 19:51:28 1986 --- /tmp/xxx Thu Jan 28 15:52:11 1988 *************** *** 496,502 **** if (i2 > 0) i1 = sp[i2]; i1 -= item.dsize + item1.dsize; ! if (i1 <= (i2+3) * sizeof(short)) return (0); sp[0] += 2; sp[++i2] = i1 + item1.dsize; --- 496,502 ---- if (i2 > 0) i1 = sp[i2]; i1 -= item.dsize + item1.dsize; ! if (i1 <= (i2+3) * (int)sizeof(short)) return (0); sp[0] += 2; sp[++i2] = i1 + item1.dsize; Casey