(cache_face): Abort if c->size exceeds MAX_FACE_ID.
authorKim F. Storm <storm@cua.dk>
Sun, 28 Dec 2003 00:12:45 +0000 (00:12 +0000)
committerKim F. Storm <storm@cua.dk>
Sun, 28 Dec 2003 00:12:45 +0000 (00:12 +0000)
src/xfaces.c

index f079e2e..55455ab 100644 (file)
@@ -5577,12 +5577,19 @@ cache_face (c, face, hash)
   face->id = i;
 
   /* Maybe enlarge C->faces_by_id.  */
-  if (i == c->used && c->used == c->size)
+  if (i == c->used)
     {
-      int new_size = 2 * c->size;
-      int sz = new_size * sizeof *c->faces_by_id;
-      c->faces_by_id = (struct face **) xrealloc (c->faces_by_id, sz);
-      c->size = new_size;
+      if (c->used == c->size)
+       {
+         int new_size, sz;
+         new_size = min (2 * c->size, MAX_FACE_ID);
+         if (new_size == c->size)
+           abort ();  /* Alternatives?  ++kfs */
+         sz = new_size * sizeof *c->faces_by_id;
+         c->faces_by_id = (struct face **) xrealloc (c->faces_by_id, sz);
+         c->size = new_size;
+       }
+      c->used++;
     }
 
 #if GLYPH_DEBUG
@@ -5601,8 +5608,6 @@ cache_face (c, face, hash)
 #endif /* GLYPH_DEBUG */
 
   c->faces_by_id[i] = face;
-  if (i == c->used)
-    ++c->used;
 }