[asterisk-commits] russell: branch 1.6.1 r175831 - in /branches/1.6.1: ./ channels/ include/aste...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Feb 15 15:00:59 CST 2009


Author: russell
Date: Sun Feb 15 15:00:58 2009
New Revision: 175831

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=175831
Log:
Merged revisions 175829 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

........
r175829 | russell | 2009-02-15 14:56:27 -0600 (Sun, 15 Feb 2009) | 14 lines

Fix a number of problems with ast_sched_report().

1) It had numerous coding guidelines violations with regards to formatting.

2) It allocated memory using ast_calloc() that was never freed.

3) It didn't check for failure from the allocation.

4) It used sprintf() and strcat() to build the result, doing zero checking to
   prevent writing past the end of the provided buffer.

The function also lacks API documentation, but that has not been addressed in
this commit.

........

Modified:
    branches/1.6.1/   (props changed)
    branches/1.6.1/channels/chan_sip.c
    branches/1.6.1/include/asterisk/sched.h
    branches/1.6.1/main/sched.c

Propchange: branches/1.6.1/
------------------------------------------------------------------------------
Binary property 'trunk-merged' - no diff available.

Modified: branches/1.6.1/channels/chan_sip.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.6.1/channels/chan_sip.c?view=diff&rev=175831&r1=175830&r2=175831
==============================================================================
--- branches/1.6.1/channels/chan_sip.c (original)
+++ branches/1.6.1/channels/chan_sip.c Sun Feb 15 15:00:58 2009
@@ -13821,7 +13821,7 @@
 
 static char *sip_show_sched(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
-	char cbuf[2256];
+	struct ast_str *cbuf;
 	struct ast_cb_names cbnames = {9, { "retrans_pkt",
                                         "__sip_autodestruct",
                                         "expire_register",
@@ -13851,9 +13851,13 @@
 	case CLI_GENERATE:
 		return NULL;
 	}
+
+	cbuf = ast_str_alloca(2048);
+
 	ast_cli(a->fd, "\n");
-	ast_sched_report(sched, cbuf, sizeof(cbuf), &cbnames);
-	ast_cli(a->fd, "%s", cbuf);
+	ast_sched_report(sched, &cbuf, &cbnames);
+	ast_cli(a->fd, "%s", cbuf->str);
+
 	return CLI_SUCCESS;
 }
 

Modified: branches/1.6.1/include/asterisk/sched.h
URL: http://svn.digium.com/svn-view/asterisk/branches/1.6.1/include/asterisk/sched.h?view=diff&rev=175831&r1=175830&r2=175831
==============================================================================
--- branches/1.6.1/include/asterisk/sched.h (original)
+++ branches/1.6.1/include/asterisk/sched.h Sun Feb 15 15:00:58 2009
@@ -145,13 +145,12 @@
 typedef int (*ast_sched_cb)(const void *data);
 #define AST_SCHED_CB(a) ((ast_sched_cb)(a))
 
-struct ast_cb_names
-{
+struct ast_cb_names {
 	int numassocs;
 	char *list[10];
 	ast_sched_cb cblist[10];
 };
-char *ast_sched_report(struct sched_context *con, char *buf, int bufsiz, struct ast_cb_names *cbnames);
+void ast_sched_report(struct sched_context *con, struct ast_str **buf, struct ast_cb_names *cbnames);
 		
 /*! \brief Adds a scheduled event
  * Schedule an event to take place at some point in the future.  callback

Modified: branches/1.6.1/main/sched.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.6.1/main/sched.c?view=diff&rev=175831&r1=175830&r2=175831
==============================================================================
--- branches/1.6.1/main/sched.c (original)
+++ branches/1.6.1/main/sched.c Sun Feb 15 15:00:58 2009
@@ -386,41 +386,34 @@
 	return 0;
 }
 
-
-char *ast_sched_report(struct sched_context *con, char *buf, int bufsiz, struct ast_cb_names *cbnames)
-{
-	int *countlist,i;
+void ast_sched_report(struct sched_context *con, struct ast_str **buf, struct ast_cb_names *cbnames)
+{
+	int i;
 	struct sched *cur;
-	char buf2[1200];
-	ast_sched_cb xxx = NULL;
-	
-	buf[0] = 0;
-	sprintf(buf, " Highwater = %d\n schedcnt = %d\n", con->highwater, con->schedcnt);
-	countlist = ast_calloc(sizeof(int),cbnames->numassocs+1);
-	
+	int countlist[cbnames->numassocs + 1];
+	
+	ast_str_set(buf, 0, " Highwater = %d\n schedcnt = %d\n", con->highwater, con->schedcnt);
+
 	AST_DLLIST_TRAVERSE(&con->schedq, cur, list) {
 		/* match the callback to the cblist */
-		for (i=0;i<cbnames->numassocs;i++) {
-			if (cur->callback == cbnames->cblist[i])
+		for (i = 0; i < cbnames->numassocs; i++) {
+			if (cur->callback == cbnames->cblist[i]) {
 				break;
-		}
-		if (i < cbnames->numassocs)
+			}
+		}
+		if (i < cbnames->numassocs) {
 			countlist[i]++;
-		else {
-			xxx = cur->callback;
+		} else {
 			countlist[cbnames->numassocs]++;
 		}
 	}
-	for (i=0;i<cbnames->numassocs;i++) {
-		sprintf(buf2,"    %s : %d\n", cbnames->list[i], countlist[i]);
-		strcat(buf, buf2);
-	}
-	sprintf(buf2,"   <unknown:%p> : %d\n", xxx, countlist[cbnames->numassocs]);
-	strcat( buf, buf2);
-	return buf;
-}
-
-
+
+	for (i = 0; i < cbnames->numassocs; i++) {
+		ast_str_append(buf, 0, "    %s : %d\n", cbnames->list[i], countlist[i]);
+	}
+
+	ast_str_append(buf, 0, "   <unknown> : %d\n", countlist[cbnames->numassocs]);
+}
 	
 /*! \brief Dump the contents of the scheduler to LOG_DEBUG */
 void ast_sched_dump(const struct sched_context *con)




More information about the asterisk-commits mailing list