[Swfed-svn] swfed-svn [443] author: yoya

Zurück zum Archiv-Index

svnno****@sourc***** svnno****@sourc*****
2011年 3月 22日 (火) 17:08:52 JST


Revision: 443
          http://sourceforge.jp/projects/swfed/svn/view?view=rev&revision=443
Author:   yoya
Date:     2011-03-22 17:08:52 +0900 (Tue, 22 Mar 2011)

Log Message:
-----------
author: yoya
realloc 時にメモリが足りない場合の例外処理

Modified Paths:
--------------
    trunk/src/trans_table.c


-------------- next part --------------
Modified: trunk/src/trans_table.c
===================================================================
--- trunk/src/trans_table.c	2011-03-22 08:08:13 UTC (rev 442)
+++ trunk/src/trans_table.c	2011-03-22 08:08:52 UTC (rev 443)
@@ -24,14 +24,19 @@
 int
 trans_table_realloc(trans_table_t *trans_table, int offset) {
     int new_table_num = trans_table->table_num;
+    int *table;
     int i;
     while (new_table_num <= offset) {
         new_table_num *= 2;
     }
-    trans_table->table = realloc(trans_table->table, new_table_num * sizeof(int));
+    table = realloc(trans_table->table, new_table_num * sizeof(int));
+    if (table == NULL) {
+        return 1; // failed
+    }
     for (i = trans_table->table_num ; i < new_table_num ; i++) {
-        trans_table->table[i] = 0;
+        table[i] = 0;
     }
+    trans_table->table = table;
     trans_table->table_num = new_table_num;
     return 0;
 }
@@ -45,7 +50,9 @@
 int
 trans_table_set(trans_table_t  *trans_table, int offset, int cid) {
     if (trans_table->table_num <= offset) {
-        trans_table_realloc(trans_table, offset);
+      if (trans_table_realloc(trans_table, offset)) {
+	return 1; // failed
+      }
     }
     trans_table->table[offset] = cid;
     return 0;



Swfed-svn メーリングリストの案内
Zurück zum Archiv-Index