Add more assertions.
This commit is contained in:
1 parent
984b8e7da0
commit
030510613c
1 file changed
+3
@@ -157,6 +157,7 @@ string_empty_p(const string_t v)
|
|||||||
static inline void
|
static inline void
|
||||||
stringi_fit2size (string_t v, size_t size)
|
stringi_fit2size (string_t v, size_t size)
|
||||||
{
|
{
|
||||||
|
assert (size > 0);
|
||||||
// Note: this function may be called in context where the contract
|
// Note: this function may be called in context where the contract
|
||||||
// is not fullfilled.
|
// is not fullfilled.
|
||||||
if (size > v->alloc) {
|
if (size > v->alloc) {
|
||||||
@@ -178,6 +179,7 @@ stringi_fit2size (string_t v, size_t size)
|
|||||||
v->ptr = ptr;
|
v->ptr = ptr;
|
||||||
v->alloc = alloc;
|
v->alloc = alloc;
|
||||||
}
|
}
|
||||||
|
assert(v->ptr != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
@@ -553,6 +555,7 @@ string_replace_str (string_t v, const char str1[], const char str2[], size_t sta
|
|||||||
if (i != STRING_FAILURE) {
|
if (i != STRING_FAILURE) {
|
||||||
size_t str1_l = strlen(str1);
|
size_t str1_l = strlen(str1);
|
||||||
size_t str2_l = strlen(str2);
|
size_t str2_l = strlen(str2);
|
||||||
|
assert(v->size + 1 + str2_l > str1_l);
|
||||||
stringi_fit2size (v, v->size + str2_l - str1_l + 1);
|
stringi_fit2size (v, v->size + str2_l - str1_l + 1);
|
||||||
if (str1_l != str2_l)
|
if (str1_l != str2_l)
|
||||||
memmove(&v->ptr[i+str2_l], &v->ptr[i+str1_l], v->size - i - str1_l + 1);
|
memmove(&v->ptr[i+str2_l], &v->ptr[i+str1_l], v->size - i - str1_l + 1);
|
||||||
|
|||||||
Reference in new issue
Block a user