| 135 | |
| 136 | /* Helper functions for re_string_allocate, and re_string_construct. */ |
| 137 | |
| 138 | static reg_errcode_t |
| 139 | internal_function |
| 140 | re_string_realloc_buffers (re_string_t *pstr, int new_buf_len) |
| 141 | { |
| 142 | #ifdef RE_ENABLE_I18N |
| 143 | if (pstr->mb_cur_max > 1) |
| 144 | { |
| 145 | wint_t *new_wcs; |
| 146 | |
| 147 | /* Avoid overflow in realloc. */ |
| 148 | const size_t max_object_size = MAX (sizeof (wint_t), sizeof (int)); |
| 149 | if (BE (SIZE_MAX / max_object_size < new_buf_len, 0)) |
| 150 | return REG_ESPACE; |
| 151 | |
| 152 | new_wcs = re_realloc (pstr->wcs, wint_t, new_buf_len); |
| 153 | if (BE (new_wcs == NULL, 0)) |
| 154 | return REG_ESPACE; |
| 155 | pstr->wcs = new_wcs; |
| 156 | if (pstr->offsets != NULL) |
| 157 | { |
| 158 | int *new_offsets = re_realloc (pstr->offsets, int, new_buf_len); |
| 159 | if (BE (new_offsets == NULL, 0)) |
| 160 | return REG_ESPACE; |
| 161 | pstr->offsets = new_offsets; |
| 162 | } |
| 163 | } |
| 164 | #endif /* RE_ENABLE_I18N */ |
| 165 | if (pstr->mbs_allocated) |
| 166 | { |
| 167 | unsigned char *new_mbs = re_realloc (pstr->mbs, unsigned char, |
| 168 | new_buf_len); |
| 169 | if (BE (new_mbs == NULL, 0)) |
| 170 | return REG_ESPACE; |
| 171 | pstr->mbs = new_mbs; |
| 172 | } |
| 173 | pstr->bufs_len = new_buf_len; |
| 174 | return REG_NOERROR; |
| 175 | } |
| 176 | |
| 177 |
no test coverage detected