Description: <short summary of the patch>
 TODO: Put a short summary on the line above and replace this paragraph
 with a longer explanation of this change. Complete the meta-information
 with other relevant fields (see below for details). To make it easier, the
 information below has been extracted from the changelog. Adjust it or drop
 it.
 .
 gcl (2.6.10-14) unstable; urgency=high
 .
   * 2.6.11pre test 13
Author: Camm Maguire <camm@debian.org>

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: http://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: <YYYY-MM-DD>

--- gcl-2.6.10.orig/o/main.c
+++ gcl-2.6.10/o/main.c
@@ -154,7 +154,7 @@ update_real_maxpage(void) {
 
   massert(cur=sbrk(0));
   for (i=0,j=(1L<<log_maxpage_bound);j>PAGESIZE;j>>=1)
-    if ((end=data_start+i+j-PAGESIZE)>cur)
+    if ((end=(data_start ? data_start : cur)+i+j-PAGESIZE)>cur)
       if (!mbrk(end)) {
 	real_maxpage=page(end);
 	i+=j;
@@ -162,7 +162,7 @@ update_real_maxpage(void) {
   massert(!mbrk(cur));
 
 #ifdef HAVE_SYSCONF_PHYS_PAGES
-  phys_pages=data_start ? sysconf(_SC_PHYS_PAGES) : 0;
+  phys_pages=raw_image ? 0 : sysconf(_SC_PHYS_PAGES);
 #ifdef BRK_DOES_NOT_GUARANTEE_ALLOCATION
   if (phys_pages>0 && real_maxpage>phys_pages+first_data_page) real_maxpage=phys_pages+first_data_page;
 #endif
