Ted Unangst wrote:
> Ingo Schwarze wrote:
> > > this could just be memcmp.
> > 
> > I avoided that over quibbles about the argument type (off_t vs.
> > size_t), though i admit that database files larger than a Gigabyte
> > make no sense at all.
> > 
> > If you consider that an improvement, i'm not opposed to using
> > memcmp(3).  But i don't really have a good idea what to do if
> > st_size does happen to exceed SIZE_MAX.  Maybe just error out?
> 
> in that case, you have already failed to mmap it, so i wouldn't worry too
> much.

actually, maybe not. if it's 4GB + a bit, the truncation will occur in the
mmap call and you'll only map a part of the file. (and then, with the hand
loop, you'll read well past the end of mapped memory and crash. with memcmp,
it will truncate to the mapped length.) so if you want correctness, need to
check both stats and error out.

Reply via email to