aboutsummaryrefslogtreecommitdiffstats
path: root/src/tparam.c
diff options
context:
space:
mode:
authorPaul Eggert2011-08-04 19:15:35 -0700
committerPaul Eggert2011-08-04 19:15:35 -0700
commit0065d05491ce5981ea20896bb26d21dcd31e6769 (patch)
tree13240167319d4a99ab5eacae4a883258eb2d28de /src/tparam.c
parent18ab493650d648ab8dca651ea2698861f926e895 (diff)
downloademacs-0065d05491ce5981ea20896bb26d21dcd31e6769.tar.gz
emacs-0065d05491ce5981ea20896bb26d21dcd31e6769.zip
Adjust in response to jan.h.d's comments.
See, for example <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=9196#26>.
Diffstat (limited to 'src/tparam.c')
-rw-r--r--src/tparam.c17
1 files changed, 4 insertions, 13 deletions
diff --git a/src/tparam.c b/src/tparam.c
index 06cec873153..ac21667d65b 100644
--- a/src/tparam.c
+++ b/src/tparam.c
@@ -101,18 +101,13 @@ tparam1 (const char *string, char *outstring, int len,
101 101
102 if (outlen == 0) 102 if (outlen == 0)
103 { 103 {
104 if (min (PTRDIFF_MAX, SIZE_MAX) - 40 < len)
105 goto out_of_memory;
106 outlen = len + 40; 104 outlen = len + 40;
107 new = (char *) xmalloc (outlen); 105 new = (char *) xmalloc (outlen);
108 memcpy (new, outstring, offset); 106 memcpy (new, outstring, offset);
109 } 107 }
110 else 108 else
111 { 109 {
112 if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < outlen) 110 new = xpalloc (outstring, &outlen, 1, -1, 1);
113 goto out_of_memory;
114 outlen *= 2;
115 new = (char *) xrealloc (outstring, outlen);
116 } 111 }
117 112
118 op = new + offset; 113 op = new + offset;
@@ -178,12 +173,8 @@ tparam1 (const char *string, char *outstring, int len,
178 doup++, append_len_incr = strlen (up); 173 doup++, append_len_incr = strlen (up);
179 else 174 else
180 doleft++, append_len_incr = strlen (left); 175 doleft++, append_len_incr = strlen (left);
181 if (PTRDIFF_MAX - append_len < append_len_incr) 176 if (INT_ADD_OVERFLOW (append_len, append_len_incr))
182 { 177 memory_full (SIZE_MAX);
183 out_of_memory:
184 xfree (new);
185 memory_full (SIZE_MAX);
186 }
187 append_len += append_len_incr; 178 append_len += append_len_incr;
188 } 179 }
189 } 180 }
@@ -286,7 +277,7 @@ main (int argc, char **argv)
286 args[0] = atoi (argv[2]); 277 args[0] = atoi (argv[2]);
287 args[1] = atoi (argv[3]); 278 args[1] = atoi (argv[3]);
288 args[2] = atoi (argv[4]); 279 args[2] = atoi (argv[4]);
289 tparam1 (argv[1], buf, "LEFT", "UP", args); 280 tparam1 (argv[1], buf, 50, "LEFT", "UP", args);
290 printf ("%s\n", buf); 281 printf ("%s\n", buf);
291 return 0; 282 return 0;
292} 283}