rev 229 - trunk/src

SVN User <[email protected]>
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: bcollins
Date: 2004-03-31 10:10:56 -0500 (Wed, 31 Mar 2004)
New Revision: 229

Modified:
   trunk/src/builtins.c
Log:
Check for NULL's from as_str in Dict.__str__. Was getting a segfault if
the key or value was from as_str.

Also fix module-doc setting from True


Modified: trunk/src/builtins.c
===================================================================
--- trunk/src/builtins.c	2004-03-31 15:08:35 UTC (rev 228)
+++ trunk/src/builtins.c	2004-03-31 15:10:56 UTC (rev 229)
@@ -285,7 +285,7 @@
 MODULE_START(True)
 {
 	True_OBJ = OBJ(PR_TRUE);
-	MODULE_SET_DOC(Object, "boolean true singleton value");
+	MODULE_SET_DOC(True, "boolean true singleton value");
 	set_attr(ist, OBJ(OBJECT), sym(ist, "True"), True_OBJ);
 }
 
@@ -1178,7 +1178,6 @@
 	len = dict_len(ist, self);
 	keys = dict_keys(ist, self);
 	vals = dict_values(ist, self);
-	dict_values(ist, self);
 
 	res = pr_malloc(3);
 
@@ -1186,15 +1185,24 @@
 	for (i=0; i < (int) len; i++) {
 		char* str1 = as_str(ist, list_item(ist, keys,i));
 		char* str2 = as_str(ist, list_item(ist, vals,i));
-		res = pr_realloc(res, strlen(res)+strlen(str1)+1+strlen(str2)+( i != len-1 ? 3 : 2));
+
+		if (str1 == NULL)
+			str1 = "(null)";
+		if (str2 == NULL)
+			str2 = "(null)";
+
+		res = pr_realloc(res, strlen(res)+strlen(str1)+1+strlen(str2)+( i != len-1 ? 3 : 2)+2);
+
 		strcat(res, str1);
 		strcat(res, ":");
 		strcat(res, str2);
 		if (i != len-1) strcat(res, ", ");
 	}
 	strcat(res, "}");
+
 	res_obj = new_string_obj(res);
 	pr_free(res);
+
 	return res_obj;
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.