implicit declaration bug in seek_cur.c
ari edelkind <[email protected]> Sun, 30 Jan 2005 06:56:37 -0500
| Newsgroups | gmane.comp.djb.cdb |
|---|---|
| Message-ID | <[email protected]> |
On big endian systems that support files larger than two gigabytes using
a 64-bit off_t (e.g. darwin/macos X), there is a bug in seek_cur.c that
will cause cdbstats and cdbtest to fail. The lseek(2) function on such
systems returns a 64-bit offset, but since unistd.h (where lseek(2) is
declared) is not included, the compiler declares the function as
returning a 32-bit integer.
Consider the function call:
lseek(0, (off_t)0, SEEk_CUR);
Given a position of 8192 within seekable descriptor 0, the value
returned on a big endian system will be:
00 00 00 00 00 00 20 00
However, implicitly declared, the value returned will be only the first
four bytes, or zero. The compiler of course cannot automatically cast
the type if it doesn't know about the type to begin with.
On a little endian system, the first four bytes of file position
will be more significant, and the issue will cause no problems, at least
with a database size of up to two gigabytes.
The fix would be simply to add
#include <unistd.h>
near the top of seek_cur.c (after sys/types.h), or even
off_t lseek();
ari