Skip to content
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

Potential bug in qcow.c rc_cache_lookup #692

Open
geordieintheshellcode opened this issue Jan 18, 2023 · 0 comments
Open

Potential bug in qcow.c rc_cache_lookup #692

geordieintheshellcode opened this issue Jan 18, 2023 · 0 comments

Comments

@geordieintheshellcode
Copy link

geordieintheshellcode commented Jan 18, 2023

I stumbled across this while looking at a separate issue. I don't understand the context of this code but it looks like there is a bug in qcow.c rc_cache_lookup on this line https://github.com/open-iscsi/tcmu-runner/blob/main/qcow.c#L731. Compiling with clang one gets:

../qcow.c:731:17: error: variable 'i' used in loop condition not modified in loop body [-Werror,-Wfor-loop-analysis]
                                for (j = 0; i < L2_CACHE_SIZE; j++) {

The code in question:

static void *rc_cache_lookup(struct qcow_state *s, uint64_t rc_offset)
{
        int i, j;
        int min_index = 0;
        int min_count = INT_MAX;
        void *rc_table;
        ssize_t read;

        /* rc cache lookup */
        for (i = 0; i < RC_CACHE_SIZE; i++) {
                if (rc_offset == s->rc_cache_offsets[i]) {
                        if (++s->rc_cache_counts[i] == INT_MAX) {
                                for (j = 0; i < RC_CACHE_SIZE; j++) {  /* ../qcow.c:731:17: error: variable 'i' used in loop condition not modified in loop body [-Werror,-Wfor-loop-analysis] */
                                        s->rc_cache_counts[j] >>= 1;
                                }
                        }
                        rc_table = s->rc_cache + (i << s->cluster_bits);
                        return rc_table;
                }
        }
... snipped...

Maybe somebody could double check and I'll open a PR.

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

No branches or pull requests

1 participant