summaryrefslogtreecommitdiff
blob: 68f706aaa2f6c52d694f009a5ae1057b038eb326 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
--- latex2rtf-1.9.15.orig/definitions.c
+++ latex2rtf-1.9.15/definitions.c
@@ -110,7 +110,8 @@
 **************************************************************************/
 {
 	int i=0,param;
-	char * args[9], *dmacro, *macro_piece, *next_piece, *expanded, buffer[1024], *cs;
+	char * args[9], *dmacro, *macro_piece, *next_piece, *expanded, *buffer = NULL, *cs;
+	int max_len = 0;
 
 	if (params<=0) 
 		return strdup(macro);
@@ -118,18 +119,28 @@
 	if (opt_param) {
 		args[i++] = getBracketParam();
 		if (!args[0]) args[0] = strdup(opt_param);
+		max_len += strlen(args[i-1]);
 	}
 
 	for (; i<params; i++) {
 		args[i] = getBraceParam();
+		max_len += strlen(args[i]);
 		diagnostics(3, "argument #%d <%s>", i+1, args[i]);
 	}
+
 	
-	*buffer='\0';
-	expanded = buffer;
 	dmacro = strdup(macro);
 	macro_piece = dmacro;
+	max_len += strlen(macro_piece);
+
+	diagnostics(3, "max_len in expandmacro = %d\n", max_len);
+	if(max_len > 0) {
+		buffer = (char*)malloc(sizeof(char) * max_len);
+		memset(buffer,'\0',max_len);
+	}
 	
+	expanded = buffer;
+
 	/* convert "\csname" to "\" */
 	while ((cs=strstr(dmacro, "\\csname")) != NULL) strcpy(cs+1,cs+7);
 		
@@ -176,6 +187,7 @@
 		if (args[i]) free(args[i]);
 
 	if (dmacro) free(dmacro);
+	if (buffer) free(buffer);
 
 	diagnostics(3, "expandmacro expanded=<%s>", buffer);
 	return strdup(buffer);