basic: replace size_multiply_overflow() with MUL_ASSIGN_SAFE where applicable

This commit is contained in:
Mike Yuan
2024-09-20 21:39:15 +02:00
parent 175de2c28e
commit 34fb408f8b
3 changed files with 23 additions and 25 deletions

View File

@@ -201,18 +201,17 @@ int strextendf_with_separator(char **x, const char *separator, const char *forma
char* strrep(const char *s, unsigned n);
#define strrepa(s, n) \
({ \
const char *_sss_ = (s); \
size_t _nnn_ = (n), _len_ = strlen(_sss_); \
assert(!size_multiply_overflow(_len_, _nnn_)); \
_len_ *= _nnn_; \
char *_d_, *_p_; \
_p_ = _d_ = newa(char, _len_ + 1); \
for (size_t _i_ = 0; _i_ < _nnn_; _i_++) \
_p_ = stpcpy(_p_, _sss_); \
*_p_ = 0; \
_d_; \
#define strrepa(s, n) \
({ \
const char *_sss_ = (s); \
size_t _nnn_ = (n), _len_ = strlen(_sss_); \
assert_se(MUL_ASSIGN_SAFE(&_len_, _nnn_)); \
char *_d_, *_p_; \
_p_ = _d_ = newa(char, _len_ + 1); \
for (size_t _i_ = 0; _i_ < _nnn_; _i_++) \
_p_ = stpcpy(_p_, _sss_); \
*_p_ = 0; \
_d_; \
})
int split_pair(const char *s, const char *sep, char **l, char **r);