[Asterisk-Dev] strdupa not common

Thorsten Lockert tholo at sigmasoft.com
Wed Apr 23 10:02:42 MST 2003


strdupa() is not at all common -- this diff changes it to a
combination of alloca and strcpy

Index: indications.c
===================================================================
RCS file: /usr/cvsroot/asterisk/indications.c,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 indications.c
--- indications.c	16 Mar 2003 22:37:29 -0000	1.1.1.2
+++ indications.c	23 Apr 2003 16:49:41 -0000
@@ -140,11 +140,12 @@
 
 int ast_playtones_start(struct ast_channel *chan, int vol, const char *playlst, int interruptible)
 {
-	char *s, *data = strdupa(playlst); /* cute */
+	char *s, *data = alloca(strlen(playlst)+1); /* cute */
 	struct playtones_def d = { vol, -1, 0, 1, NULL};
 	char *stringp=NULL;
 	if (!data)
 		return -1;
+	strcpy(data,playlst);
 	if (vol < 1)
 		d.vol = 8192;
 
Index: channels/chan_modem.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_modem.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 chan_modem.c
--- channels/chan_modem.c	12 Feb 2003 13:59:14 -0000	1.1.1.1
+++ channels/chan_modem.c	23 Apr 2003 16:49:46 -0000
@@ -808,12 +808,13 @@
 	char *piece;
 	int start, finish,x;
 	unsigned int group = 0;
-	char *copy = strdupa(s);
+	char *copy = alloca(strlen(s) + 1);
 	char *stringp=NULL;
 	if (!copy) {
 		ast_log(LOG_ERROR, "Out of memory\n");
 		return 0;
 	}
+	strcpy(copy, s);
 	stringp=copy;
 	piece = strsep(&stringp, ",");
 	while(piece) {
Index: res/res_indications.c
===================================================================
RCS file: /usr/cvsroot/asterisk/res/res_indications.c,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 res_indications.c
--- res/res_indications.c	16 Mar 2003 22:37:31 -0000	1.1.1.2
+++ res/res_indications.c	23 Apr 2003 17:00:50 -0000
@@ -248,7 +248,8 @@
 			if (!strcasecmp(v->name, "description")) {
 				strncpy(tones->description, v->value, sizeof(tones->description)-1);
 			} else if (!strcasecmp(v->name,"ringcadance")) {
-				char *ring,*rings = strdupa(v->value);
+				char *ring,*rings = alloca(strlen(v->value) + 1);
+				strcpy(rings, v->value);
 				c = rings;
 				ring = strsep(&c,",");
 				while (ring) {
@@ -270,7 +271,8 @@
 					ring = strsep(&c,",");
 				}
 			} else if (!strcasecmp(v->name,"alias")) {
-				char *countries = strdupa(v->value);
+				char *countries = alloca(strlen(v->value) + 1);
+				strcpy(countries, v->value);
 				c = countries;
 				country = strsep(&c,",");
 				while (country) {
Index: res/res_parking.c
===================================================================
RCS file: /usr/cvsroot/asterisk/res/res_parking.c,v
retrieving revision 1.2
diff -u -r1.2 res_parking.c
--- res/res_parking.c	9 Apr 2003 04:00:43 -0000	1.2
+++ res/res_parking.c	23 Apr 2003 17:00:52 -0000
@@ -611,11 +611,12 @@
 	char *c=NULL;
 	int start=0, finish=0,x;
 	unsigned int group = 0;
-	copy = strdupa(s);
+	copy = alloca(strlen(s) + 1);
 	if (!copy) {
 		ast_log(LOG_ERROR, "Out of memory\n");
 		return 0;
 	}
+	strcpy(copy, s);
 	c = copy;
 	
 	while((piece = strsep(&c, ","))) {
--
Thorsten Lockert      | tholo at sigmasoft.com | Universe, n.:
2121 N. Lakeshore Dr. | tholo at openbsd.org   |         The problem.
Chapel Hill, NC 27514 |                     |



More information about the asterisk-dev mailing list