Fixing a long standing bug in view.c

Jakub Jelinek jakub at redhat.com
Wed Feb 26 19:43:15 UTC 2003


On Wed, Feb 26, 2003 at 01:08:34PM -0500, Pavel Roskin wrote:
> Hello, Philipp!
> 
> > view.c erroneously assumes it can easily malloc a file if mmap failed and
> > passes view->s.st_size to g_malloc. But if largefile support has been enabled,
> > view->s.st_size is a 64 bit value and thus possibly exceeds the limit of
> > gulong which g_malloc takes for size. This patch fixes it.
> 
> I've applied a much simple patch for this:
> 
> /* Make sure view->s.st_size is not truncated when passed to g_malloc */
> if ((gulong) view->s.st_size == view->s.st_size)
>     view->data = (unsigned char *) g_malloc ((gulong) view->s.st_size);

Shouldn't that be g_try_malloc? mc died on me today when trying to view
a 2.8GB file, I assume because mmap failed and
g_malloc kills the application if it fails...

	Jakub



More information about the mc-devel mailing list