Skip to content

break statement does not break from loop #6966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
eleehiga opened this issue Jun 23, 2022 · 2 comments · Fixed by #6967
Closed

break statement does not break from loop #6966

eleehiga opened this issue Jun 23, 2022 · 2 comments · Fixed by #6967

Comments

@eleehiga
Copy link

For the following code:

#include <errno.h>
#include <limits.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

void strtod(char *str, char **ptr) {
  *ptr = str;
}

void test(char *s) {
        int i = 0;
        char *parse_end, *string_end;
        string_end = s + strlen(s);
        while(s < string_end) {
        strtod(s, &parse_end);
        if(parse_end == s) {
                i = -1;
                break;
        }
        }
        assert(i == -1);
}

void test_harness() {
        test("t");
}

Running the command cbmc test.c --function test_harness will infinitely repeat a line like Unwinding loop test.0 iteration 580 file test.c line 16 function test thread 0. I thought that this would go to the break statement but it appears that it does not. As when I comment out the while and break statement in the code above the assertion will hold that the variable i has changed from 0 to -1 and therefore that means that parse_end == s will be true for this code. Therefore, can you guys please help me understand why the break statement is not breaking the loop?

tautschnig added a commit to tautschnig/cbmc that referenced this issue Jun 24, 2022
The back-end assumes that each string is a singleton and, therefore,
taking the address of a particular string constant will always result in
the same value. The simplifier can use this information.

Fixes: diffblue#6966
@tautschnig
Copy link
Collaborator

It seems algebraic simplification did not consider the case of string constants when doing pointer comparison. Fixed in #6967. (Running this example with --unwind 2 --unwinding-assertions always produced the correct result.)

@eleehiga
Copy link
Author

@tautschnig and @kroening Thank you guys for making this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants