diff --git a/m-string.h b/m-string.h index dca7aff4..efa494f7 100644 --- a/m-string.h +++ b/m-string.h @@ -37,13 +37,20 @@ /********************************** INTERNAL ************************************/ +/* If within the tests, perform additional checks */ +#ifdef STRING_WITHIN_TEST +# define STRINGI_ASSUME(n) M_ASSUME(n) +#else +# define STRINGI_ASSUME(n) (void) 0 +#endif + // This macro defines the contract of a string. // Note: A ==> B is represented as not(A) or B // Note: use of strlen can slow down a lot the program in some cases. #define STRING_CONTRACT(v) do { \ M_ASSUME (v != NULL); \ M_ASSUME (v->ptr != NULL || (v->size == 0 && v->alloc == 0)); \ - M_ASSUME (v->ptr == NULL || strlen(v->ptr) == v->size); \ + STRINGI_ASSUME (v->ptr == NULL || v->size == strlen(v->ptr)); \ M_ASSUME (v->ptr == NULL || v->ptr[v->size] == 0); \ M_ASSUME (v->ptr == NULL || v->size < v->alloc); \ } while (0) diff --git a/tests/test-mstring.c b/tests/test-mstring.c index a911c313..90345797 100644 --- a/tests/test-mstring.c +++ b/tests/test-mstring.c @@ -21,6 +21,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#define STRING_WITHIN_TEST #include "m-string.h" int main(void)