[asterisk-commits] branch 1.2 r28966 - /branches/1.2/apps/app_sms.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri May 19 19:31:30 MST 2006


Author: russell
Date: Fri May 19 21:31:30 2006
New Revision: 28966

URL: http://svn.digium.com/view/asterisk?rev=28966&view=rev
Log:
fix a case where code made assumptions about how memory for variables is
allocatted on the stack - this patch is slightly different than the one
that went in for the trunk

Modified:
    branches/1.2/apps/app_sms.c

Modified: branches/1.2/apps/app_sms.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/apps/app_sms.c?rev=28966&r1=28965&r2=28966&view=diff
==============================================================================
--- branches/1.2/apps/app_sms.c (original)
+++ branches/1.2/apps/app_sms.c Fri May 19 21:31:30 2006
@@ -1178,25 +1178,24 @@
 static int sms_generate (struct ast_channel *chan, void *data, int len, int samples)
 {
 	struct ast_frame f = { 0 };
-	unsigned char waste[AST_FRIENDLY_OFFSET];
+#define MAXSAMPLES 800
 #ifdef OUTALAW
-	unsigned char buf[800];
+	unsigned char *buf;
 #else
-	signed short buf[800];
+	short *buf;
 #endif
+#define SAMPLE2LEN sizeof(*buf)
 	sms_t *h = data;
 	int i;
 
-	if (len > sizeof (buf)) {
-		ast_log (LOG_WARNING, "Only doing %d bytes (%d bytes requested)\n", (int)(sizeof (buf) / sizeof (signed short)), len);
-		len = sizeof (buf);
-#ifdef OUTALAW
-		samples = len;
-#else
-		samples = len / 2;
-#endif
-	}
-	waste[0] = 0;					 /* make compiler happy */
+	if (samples > MAXSAMPLES) {
+		ast_log (LOG_WARNING, "Only doing %d samples (%d requested)\n",
+			 MAXSAMPLES, samples);
+		samples = MAXSAMPLES;
+	}
+	len = samples * SAMPLE2LEN + AST_FRIENDLY_OFFSET;
+	buf = alloca(len);
+
 	f.frametype = AST_FRAME_VOICE;
 #ifdef OUTALAW
 	f.subclass = AST_FORMAT_ALAW;
@@ -1206,8 +1205,7 @@
 	f.datalen = samples * 2;
 #endif
 	f.offset = AST_FRIENDLY_OFFSET;
-	f.mallocd = 0;
-	f.data = buf;
+	f.data = buf + AST_FRIENDLY_OFFSET;
 	f.samples = samples;
 	f.src = "app_sms";
 	/* create a buffer containing the digital sms pattern */



More information about the asterisk-commits mailing list