mqtt3_db_message_timeout_check just initialize new_state out of loop

Bug #1324411 reported by chenzhenianqing on 2014-05-29
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Fix Released

Bug Description

hi ,

in mqtt3_db_message_timeout_check, we just init new_state once before the function , bug changeed && used in the loop,

it may be no bugs in reality, bug the code should better init new_state = mosq_ms_invalid; in the for、while loop.
 maybe we need init it in the while loop .

int mqtt3_db_message_timeout_check(struct mosquitto_db *db, unsigned int timeout)
        int i;
        time_t threshold;
        enum mosquitto_msg_state new_state = mosq_ms_invalid;
        struct mosquitto *context;
        struct mosquitto_client_msg *msg;

        threshold = mosquitto_time() - timeout;

        for(i=0; i<db->context_count; i++){
                context = db->contexts[i];
                if(!context) continue;

                msg = context->msgs;

//add this line to init it every time.
new_state = mosq_ms_invalid;

                        if(msg->timestamp < threshold && msg->state != mosq_ms_queued){
                                        case mosq_ms_wait_for_puback:
                                                new_state = mosq_ms_publish_qos1;
                                        case mosq_ms_wait_for_pubrec:
                                                new_state = mosq_ms_publish_qos2;
                                        case mosq_ms_wait_for_pubrel:
                                                new_state = mosq_ms_send_pubrec;
                                        case mosq_ms_wait_for_pubcomp:
                                                new_state = mosq_ms_resend_pubrel;
                                if(new_state != mosq_ms_invalid){
                                        msg->timestamp = mosquitto_time();
                                        msg->state = new_state;
                                        msg->dup = true;
                        msg = msg->next;

        return MOSQ_ERR_SUCCESS;

Roger Light (roger.light) wrote :

I agree, this doesn't look quite right but in practice probably didn't affect anything.

I've commited a change that fixes it.

Changed in mosquitto:
milestone: none → 1.4
status: New → Fix Committed
chenzhenianqing (hw-henry2008) wrote :

many thanks

Changed in mosquitto:
milestone: 1.4 → 1.3.2
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers