comparison src/editfns.c @ 57725:c0675c413aa3

(Fformat): Allocate discarded table with SAFE_ALLOCA. Only allocate info and discarded tables once. Fix SAFE_FREE calls.
author Kim F. Storm <storm@cua.dk>
date Tue, 26 Oct 2004 22:37:34 +0000
parents c0f2bdd90b5d
children dd9868eeca9e 3a5b83e18d41
comparison
equal deleted inserted replaced
57724:80393689541a 57725:c0675c413aa3
2773 tt = SDATA (table); 2773 tt = SDATA (table);
2774 } 2774 }
2775 2775
2776 pos = XINT (start); 2776 pos = XINT (start);
2777 pos_byte = CHAR_TO_BYTE (pos); 2777 pos_byte = CHAR_TO_BYTE (pos);
2778 end_pos = XINT (end); 2778 end_pos = XINT (end);
2779 modify_region (current_buffer, pos, XINT (end)); 2779 modify_region (current_buffer, pos, XINT (end));
2780 2780
2781 cnt = 0; 2781 cnt = 0;
2782 for (; pos < end_pos; ) 2782 for (; pos < end_pos; )
2783 { 2783 {
3266 USE_SAFE_ALLOCA; 3266 USE_SAFE_ALLOCA;
3267 3267
3268 /* discarded[I] is 1 if byte I of the format 3268 /* discarded[I] is 1 if byte I of the format
3269 string was not copied into the output. 3269 string was not copied into the output.
3270 It is 2 if byte I was not the first byte of its character. */ 3270 It is 2 if byte I was not the first byte of its character. */
3271 char *discarded; 3271 char *discarded = 0;
3272 3272
3273 /* Each element records, for one argument, 3273 /* Each element records, for one argument,
3274 the start and end bytepos in the output string, 3274 the start and end bytepos in the output string,
3275 and whether the argument is a string with intervals. 3275 and whether the argument is a string with intervals.
3276 info[0] is unused. Unused elements have -1 for start. */ 3276 info[0] is unused. Unused elements have -1 for start. */
3317 3317
3318 /* Allocate the info and discarded tables. */ 3318 /* Allocate the info and discarded tables. */
3319 { 3319 {
3320 int nbytes = (nargs+1) * sizeof *info; 3320 int nbytes = (nargs+1) * sizeof *info;
3321 int i; 3321 int i;
3322 info = (struct info *) alloca (nbytes); 3322 if (!info)
3323 info = (struct info *) alloca (nbytes);
3323 bzero (info, nbytes); 3324 bzero (info, nbytes);
3324 for (i = 0; i <= nargs; i++) 3325 for (i = 0; i <= nargs; i++)
3325 info[i].start = -1; 3326 info[i].start = -1;
3326 discarded = (char *) alloca (SBYTES (args[0])); 3327 if (!discarded)
3328 SAFE_ALLOCA (discarded, char *, SBYTES (args[0]));
3327 bzero (discarded, SBYTES (args[0])); 3329 bzero (discarded, SBYTES (args[0]));
3328 } 3330 }
3329 3331
3330 /* Add to TOTAL enough space to hold the converted arguments. */ 3332 /* Add to TOTAL enough space to hold the converted arguments. */
3331 3333
3682 if (maybe_combine_byte) 3684 if (maybe_combine_byte)
3683 nchars = multibyte_chars_in_text (buf, p - buf); 3685 nchars = multibyte_chars_in_text (buf, p - buf);
3684 val = make_specified_string (buf, nchars, p - buf, multibyte); 3686 val = make_specified_string (buf, nchars, p - buf, multibyte);
3685 3687
3686 /* If we allocated BUF with malloc, free it too. */ 3688 /* If we allocated BUF with malloc, free it too. */
3687 SAFE_FREE (total); 3689 SAFE_FREE ();
3688 3690
3689 /* If the format string has text properties, or any of the string 3691 /* If the format string has text properties, or any of the string
3690 arguments has text properties, set up text properties of the 3692 arguments has text properties, set up text properties of the
3691 result string. */ 3693 result string. */
3692 3694
4054 start2_addr = BYTE_POS_ADDR (start2_byte); 4056 start2_addr = BYTE_POS_ADDR (start2_byte);
4055 4057
4056 bcopy (start2_addr, temp, len2_byte); 4058 bcopy (start2_addr, temp, len2_byte);
4057 bcopy (start1_addr, start1_addr + len2_byte, len1_byte); 4059 bcopy (start1_addr, start1_addr + len2_byte, len1_byte);
4058 bcopy (temp, start1_addr, len2_byte); 4060 bcopy (temp, start1_addr, len2_byte);
4059 SAFE_FREE (len2_byte); 4061 SAFE_FREE ();
4060 } 4062 }
4061 else 4063 else
4062 /* First region not smaller than second. */ 4064 /* First region not smaller than second. */
4063 { 4065 {
4064 USE_SAFE_ALLOCA; 4066 USE_SAFE_ALLOCA;
4067 start1_addr = BYTE_POS_ADDR (start1_byte); 4069 start1_addr = BYTE_POS_ADDR (start1_byte);
4068 start2_addr = BYTE_POS_ADDR (start2_byte); 4070 start2_addr = BYTE_POS_ADDR (start2_byte);
4069 bcopy (start1_addr, temp, len1_byte); 4071 bcopy (start1_addr, temp, len1_byte);
4070 bcopy (start2_addr, start1_addr, len2_byte); 4072 bcopy (start2_addr, start1_addr, len2_byte);
4071 bcopy (temp, start1_addr + len2_byte, len1_byte); 4073 bcopy (temp, start1_addr + len2_byte, len1_byte);
4072 SAFE_FREE (len1_byte); 4074 SAFE_FREE ();
4073 } 4075 }
4074 graft_intervals_into_buffer (tmp_interval1, start1 + len2, 4076 graft_intervals_into_buffer (tmp_interval1, start1 + len2,
4075 len1, current_buffer, 0); 4077 len1, current_buffer, 0);
4076 graft_intervals_into_buffer (tmp_interval2, start1, 4078 graft_intervals_into_buffer (tmp_interval2, start1,
4077 len2, current_buffer, 0); 4079 len2, current_buffer, 0);
4103 start1_addr = BYTE_POS_ADDR (start1_byte); 4105 start1_addr = BYTE_POS_ADDR (start1_byte);
4104 start2_addr = BYTE_POS_ADDR (start2_byte); 4106 start2_addr = BYTE_POS_ADDR (start2_byte);
4105 bcopy (start1_addr, temp, len1_byte); 4107 bcopy (start1_addr, temp, len1_byte);
4106 bcopy (start2_addr, start1_addr, len2_byte); 4108 bcopy (start2_addr, start1_addr, len2_byte);
4107 bcopy (temp, start2_addr, len1_byte); 4109 bcopy (temp, start2_addr, len1_byte);
4108 SAFE_FREE (len1_byte); 4110 SAFE_FREE ();
4109 4111
4110 graft_intervals_into_buffer (tmp_interval1, start2, 4112 graft_intervals_into_buffer (tmp_interval1, start2,
4111 len1, current_buffer, 0); 4113 len1, current_buffer, 0);
4112 graft_intervals_into_buffer (tmp_interval2, start1, 4114 graft_intervals_into_buffer (tmp_interval2, start1,
4113 len2, current_buffer, 0); 4115 len2, current_buffer, 0);
4132 start2_addr = BYTE_POS_ADDR (start2_byte); 4134 start2_addr = BYTE_POS_ADDR (start2_byte);
4133 bcopy (start2_addr, temp, len2_byte); 4135 bcopy (start2_addr, temp, len2_byte);
4134 bcopy (start1_addr, start1_addr + len_mid + len2_byte, len1_byte); 4136 bcopy (start1_addr, start1_addr + len_mid + len2_byte, len1_byte);
4135 safe_bcopy (start1_addr + len1_byte, start1_addr + len2_byte, len_mid); 4137 safe_bcopy (start1_addr + len1_byte, start1_addr + len2_byte, len_mid);
4136 bcopy (temp, start1_addr, len2_byte); 4138 bcopy (temp, start1_addr, len2_byte);
4137 SAFE_FREE (len2_byte); 4139 SAFE_FREE ();
4138 4140
4139 graft_intervals_into_buffer (tmp_interval1, end2 - len1, 4141 graft_intervals_into_buffer (tmp_interval1, end2 - len1,
4140 len1, current_buffer, 0); 4142 len1, current_buffer, 0);
4141 graft_intervals_into_buffer (tmp_interval_mid, start1 + len2, 4143 graft_intervals_into_buffer (tmp_interval_mid, start1 + len2,
4142 len_mid, current_buffer, 0); 4144 len_mid, current_buffer, 0);
4163 start2_addr = BYTE_POS_ADDR (start2_byte); 4165 start2_addr = BYTE_POS_ADDR (start2_byte);
4164 bcopy (start1_addr, temp, len1_byte); 4166 bcopy (start1_addr, temp, len1_byte);
4165 bcopy (start2_addr, start1_addr, len2_byte); 4167 bcopy (start2_addr, start1_addr, len2_byte);
4166 bcopy (start1_addr + len1_byte, start1_addr + len2_byte, len_mid); 4168 bcopy (start1_addr + len1_byte, start1_addr + len2_byte, len_mid);
4167 bcopy (temp, start1_addr + len2_byte + len_mid, len1_byte); 4169 bcopy (temp, start1_addr + len2_byte + len_mid, len1_byte);
4168 SAFE_FREE (len1_byte); 4170 SAFE_FREE ();
4169 4171
4170 graft_intervals_into_buffer (tmp_interval1, end2 - len1, 4172 graft_intervals_into_buffer (tmp_interval1, end2 - len1,
4171 len1, current_buffer, 0); 4173 len1, current_buffer, 0);
4172 graft_intervals_into_buffer (tmp_interval_mid, start1 + len2, 4174 graft_intervals_into_buffer (tmp_interval_mid, start1 + len2,
4173 len_mid, current_buffer, 0); 4175 len_mid, current_buffer, 0);