[Freeswitch-svn] [commit] r5020 - freeswitch/trunk/src/mod/applications/mod_commands

Freeswitch SVN anthm at freeswitch.org
Thu Apr 26 11:02:46 EDT 2007


Author: anthm
Date: Thu Apr 26 11:02:46 2007
New Revision: 5020

Modified:
   freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c

Log:
fix potential NULL fiasco

Modified: freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c	Thu Apr 26 11:02:46 2007
@@ -849,8 +849,15 @@
 	switch_xml_set_attr_d(row, "row_id", id);
 
 	for(x = 0; x < argc; x++) {
-		if ((field = switch_xml_add_child_d(row, columnNames[x], f_off++))) {
-			switch_xml_set_txt_d(field, argv[x]);
+		char *name = columnNames[x];
+		char *val = switch_str_nil(argv[x]);
+
+		if (!name) {
+			name = "undefined";
+		}
+
+		if ((field = switch_xml_add_child_d(row, name, f_off++))) {
+			switch_xml_set_txt_d(field, val);
 		} else {
 			return -1;
 		}
@@ -873,11 +880,18 @@
 		}
 
 		for (x = 0; x < argc; x++) {
+			char *name = columnNames[x];
+
+
+			if (!name) {
+				name = "undefined";
+			}
+
 			if (holder->http) {
 				holder->stream->write_function(holder->stream, "<td>");
-				holder->stream->write_function(holder->stream, "<b>%s</b>%s", columnNames[x], x == (argc - 1) ? "</td></tr>\n" : "</td><td>");
+				holder->stream->write_function(holder->stream, "<b>%s</b>%s", name, x == (argc - 1) ? "</td></tr>\n" : "</td><td>");
 			} else {
-				holder->stream->write_function(holder->stream, "%s%s", columnNames[x], x == (argc - 1) ? "\n" : holder->delim);
+				holder->stream->write_function(holder->stream, "%s%s", name, x == (argc - 1) ? "\n" : holder->delim);
 			}
 		}
 	}
@@ -887,11 +901,13 @@
 	}
 
 	for (x = 0; x < argc; x++) {
+		char *val = switch_str_nil(argv[x]);
+
 		if (holder->http) {
 			holder->stream->write_function(holder->stream, "<td>");
-			holder->stream->write_function(holder->stream, "%s%s", argv[x] ? argv[x] : "", x == (argc - 1) ? "</td></tr>\n" : "</td><td>");
+			holder->stream->write_function(holder->stream, "%s%s", val, x == (argc - 1) ? "</td></tr>\n" : "</td><td>");
 		} else {
-			holder->stream->write_function(holder->stream, "%s%s", argv[x] ? argv[x] : "", x == (argc - 1) ? "\n" : holder->delim);
+			holder->stream->write_function(holder->stream, "%s%s", val, x == (argc - 1) ? "\n" : holder->delim);
 		}
 	}
 
@@ -997,6 +1013,7 @@
 		}
 	} else if (!strcasecmp(as, "xml")) {
 		switch_core_db_exec(db, sql, show_as_xml_callback, &holder, &errmsg);
+
 		if (holder.xml) {
 			char count[50];
 			char *xmlstr;



More information about the Freeswitch-svn mailing list