aboutsummaryrefslogtreecommitdiffstats
path: root/src/tparam.c
diff options
context:
space:
mode:
authorStefan Monnier2012-03-25 16:37:21 -0400
committerStefan Monnier2012-03-25 16:37:21 -0400
commit699c782b7668c44d0fa4446331b0590a6d5dac82 (patch)
tree5dcce364741d0761920a3d274b0fc8aba4103d45 /src/tparam.c
parent98fb480ee31bf74cf554044f60f21df16566dd7f (diff)
parente99a9b8bdccadded1f6fae88ee7a2a93dfd4eacf (diff)
downloademacs-pending.tar.gz
emacs-pending.zip
Merge from trunkpending
Diffstat (limited to 'src/tparam.c')
-rw-r--r--src/tparam.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/tparam.c b/src/tparam.c
index 6aae0b97db9..ac21667d65b 100644
--- a/src/tparam.c
+++ b/src/tparam.c
@@ -79,24 +79,25 @@ tparam1 (const char *string, char *outstring, int len,
79 register const char *p = string; 79 register const char *p = string;
80 register char *op = outstring; 80 register char *op = outstring;
81 char *outend; 81 char *outend;
82 int outlen = 0; 82 char *new = 0;
83 ptrdiff_t outlen = 0;
83 84
84 register int tem; 85 register int tem;
85 int *old_argp = argp; /* can move */ 86 int *old_argp = argp; /* can move */
86 int *fixed_argp = argp; /* never moves */ 87 int *fixed_argp = argp; /* never moves */
87 int explicit_param_p = 0; /* set by %p */ 88 int explicit_param_p = 0; /* set by %p */
88 int doleft = 0; 89 ptrdiff_t doleft = 0;
89 int doup = 0; 90 ptrdiff_t doup = 0;
91 ptrdiff_t append_len = 0;
90 92
91 outend = outstring + len; 93 outend = outstring + len;
92 94
93 while (1) 95 while (1)
94 { 96 {
95 /* If the buffer might be too short, make it bigger. */ 97 /* If the buffer might be too short, make it bigger. */
96 if (op + 5 >= outend) 98 while (outend - op - append_len <= 5)
97 { 99 {
98 register char *new; 100 ptrdiff_t offset = op - outstring;
99 int offset = op - outstring;
100 101
101 if (outlen == 0) 102 if (outlen == 0)
102 { 103 {
@@ -106,8 +107,7 @@ tparam1 (const char *string, char *outstring, int len,
106 } 107 }
107 else 108 else
108 { 109 {
109 outlen *= 2; 110 new = xpalloc (outstring, &outlen, 1, -1, 1);
110 new = (char *) xrealloc (outstring, outlen);
111 } 111 }
112 112
113 op = new + offset; 113 op = new + offset;
@@ -167,11 +167,15 @@ tparam1 (const char *string, char *outstring, int len,
167 and this is one of them, increment it. */ 167 and this is one of them, increment it. */
168 while (tem == 0 || tem == '\n' || tem == '\t') 168 while (tem == 0 || tem == '\n' || tem == '\t')
169 { 169 {
170 ptrdiff_t append_len_incr;
170 tem++; 171 tem++;
171 if (argp == old_argp) 172 if (argp == old_argp)
172 doup++, outend -= strlen (up); 173 doup++, append_len_incr = strlen (up);
173 else 174 else
174 doleft++, outend -= strlen (left); 175 doleft++, append_len_incr = strlen (left);
176 if (INT_ADD_OVERFLOW (append_len, append_len_incr))
177 memory_full (SIZE_MAX);
178 append_len += append_len_incr;
175 } 179 }
176 } 180 }
177 *op++ = tem ? tem : 0200; 181 *op++ = tem ? tem : 0200;
@@ -265,16 +269,15 @@ tparam1 (const char *string, char *outstring, int len,
265 269
266#ifdef DEBUG 270#ifdef DEBUG
267 271
268main (argc, argv) 272int
269 int argc; 273main (int argc, char **argv)
270 char **argv;
271{ 274{
272 char buf[50]; 275 char buf[50];
273 int args[3]; 276 int args[3];
274 args[0] = atoi (argv[2]); 277 args[0] = atoi (argv[2]);
275 args[1] = atoi (argv[3]); 278 args[1] = atoi (argv[3]);
276 args[2] = atoi (argv[4]); 279 args[2] = atoi (argv[4]);
277 tparam1 (argv[1], buf, "LEFT", "UP", args); 280 tparam1 (argv[1], buf, 50, "LEFT", "UP", args);
278 printf ("%s\n", buf); 281 printf ("%s\n", buf);
279 return 0; 282 return 0;
280} 283}