emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] scratch/record 9122e24 12/13: Signal errors from APIs.


From: Lars Brinkhoff
Subject: [Emacs-diffs] scratch/record 9122e24 12/13: Signal errors from APIs.
Date: Mon, 20 Mar 2017 16:11:10 -0400 (EDT)

branch: scratch/record
commit 9122e2415dfe4e20ed30c30c23acdd340250fcc2
Author: Lars Brinkhoff <address@hidden>
Commit: Lars Brinkhoff <address@hidden>

    Signal errors from APIs.
---
 src/alloc.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/alloc.c b/src/alloc.c
index 1a3a38e..d46f2a7 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -3393,11 +3393,14 @@ allocate_buffer (void)
 }
 
 
+/* Allocate a new record with COUNT slots.  Return NULL if COUNT is
+   too large.  */
+
 static struct Lisp_Vector *
 allocate_record (int count)
 {
   if (count >= (1 << PSEUDOVECTOR_SIZE_BITS))
-    error ("Record too large");
+    return NULL;
 
   struct Lisp_Vector *p = allocate_vector (count);
   XSETPVECTYPE (p, PVEC_RECORD);
@@ -3421,6 +3424,10 @@ type slot, must fit in PSEUDOVECTOR_SIZE_BITS.  */)
 
   size = XFASTINT (slots) + 1;
   p = allocate_record (size);
+  if (p == NULL)
+    error ("Attempt to allocate a record of %ld slots; max is %d",
+          size, (1 << PSEUDOVECTOR_SIZE_BITS) - 1);
+
   p->contents[0] = type;
   for (i = 1; i < size; i++)
     p->contents[i] = init;
@@ -3440,6 +3447,10 @@ usage: (record TYPE &rest SLOTS) */)
   (ptrdiff_t nargs, Lisp_Object *args)
 {
   struct Lisp_Vector *p = allocate_record (nargs);
+  if (p == NULL)
+    error ("Attempt to allocate a record of %ld slots; max is %d",
+          nargs, (1 << PSEUDOVECTOR_SIZE_BITS) - 1);
+
   Lisp_Object type = args[0];
   Lisp_Object record;
 
@@ -3460,6 +3471,10 @@ DEFUN ("copy-record", Fcopy_record, Scopy_record, 1, 1, 
0,
   struct Lisp_Vector *src = XVECTOR (record);
   ptrdiff_t size = ASIZE (record) & PSEUDOVECTOR_SIZE_MASK;
   struct Lisp_Vector *new = allocate_record (size);
+  if (new == NULL)
+    error ("Attempt to allocate a record of %ld slots; max is %d",
+          size, (1 << PSEUDOVECTOR_SIZE_BITS) - 1);
+
   memcpy (&(new->contents[0]), &(src->contents[0]),
           size * sizeof (Lisp_Object));
   XSETVECTOR (record, new);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]