Преглед изворни кода

abort() on realloc() error.

default пре 3 година
родитељ
комит
a62e830ced
1 измењених фајлова са 12 додато и 2 уклоњено
  1. 12 2
      xs.h

+ 12 - 2
xs.h

@@ -213,8 +213,18 @@ d_char *xs_expand(d_char *data, int offset, int size)
     int n;
 
     /* open room */
-    if (sz == 0 || _xs_blk_size(sz) != _xs_blk_size(sz + size))
-        data = realloc(data, _xs_blk_size(sz + size));
+    if (sz == 0 || _xs_blk_size(sz) != _xs_blk_size(sz + size)) {
+        d_char *ndata;
+
+        ndata = realloc(data, _xs_blk_size(sz + size));
+
+        if (ndata == NULL) {
+            fprintf(stderr, "**OUT OF MEMORY**");
+            abort();
+        }
+        else
+            data = ndata;
+    }
 
     /* move up the rest of the data */
     for (n = sz + size - 1; n >= offset + size; n--)