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

#3181 printf double vsnprintf() fix, malloc, va_end #3184

Merged
merged 6 commits into from
Sep 8, 2019

Conversation

knifter
Copy link
Contributor

@knifter knifter commented Sep 6, 2019

These are the changes mentioned in #3181

}
len = vsnprintf(temp, len+1, format, arg);
write((uint8_t*)temp, len);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just thought of something, This print function is used for many different subsystems. I think some of them may actually have cases where write() can fail. instead of returning the number of characters to be written, actually return the true number.

int actualLen = write((uint8_t*)temp,len);
...
return actualLen;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ill add/fix that

free(temp);
}
return len;
return write((uint8_t*)temp, len);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't do it this way, the buffer has already been freed, free() will overwrite the content of temp with the delete chain links.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops... absolutely right, a sec

Copy link
Contributor

@stickbreaker stickbreaker Sep 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could:

if(temp != loc_buf){
     len = write((uint8_t*)temp,len);  
     free(temp);
}
else len=write((uint8_t*)temp,len);
return len;

Copy link
Contributor Author

@knifter knifter Sep 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also want to write(temp) if temp == loc_buf
e: right, too soon. But see commit

@stickbreaker
Copy link
Contributor

@knifter Found one more at line 162:

size_t Print::print(struct tm * timeinfo, const char * format)
{
    const char * f = format;
    if(!f){
        f = "%c";
    }
    char buf[64];
    size_t written = strftime(buf, 64, f, timeinfo);
    print(buf);
    return written;
}

Instead of return written; change it to return print(buf);
That is the only other function that was not returning actual characters written.

Thanks for doing this. Every little bit helps!

@me-no-dev
Copy link
Member

@stickbreaker that is unrelated though :)

@me-no-dev me-no-dev merged commit 717ca79 into espressif:master Sep 8, 2019
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

Successfully merging this pull request may close these issues.

3 participants