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

Properly set infoLog length #27

Closed
wants to merge 1 commit into from
Closed

Properly set infoLog length #27

wants to merge 1 commit into from

Conversation

vankessel
Copy link

@vankessel vankessel commented Feb 25, 2020

gl::GetShaderInfoLog will fill the first half of the infoLog buffer with valid utf8 data, but the second half of the buffer could be anything. This leads to str::from_utf8(&infoLog).unwrap() sometimes working and sometimes panicking depending on what is in that region of memory when infoLog is allocated.

Can close #16 when this is merged.

@vankessel vankessel requested a review from bwasty February 25, 2020 00:31
@@ -66,7 +66,7 @@ pub fn main_1_2_1() {

// check for shader compile errors
let mut success = gl::FALSE as GLint;
let mut infoLog = Vec::with_capacity(512);
let mut infoLog = vec![0; 512];
infoLog.set_len(512 - 1); // subtract 1 to skip the trailing null character
Copy link
Owner

Choose a reason for hiding this comment

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

I guess this line is made obsolete by the change?

Copy link
Author

@vankessel vankessel Feb 25, 2020

Choose a reason for hiding this comment

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

Removing this line would include the null terminator which works just as fine (Edit: In most cases the string is going to be much less than 512 characters so there will almost always be many trailing null terminators. So yes this line is basically unnecessary). Your comment got me thinking though, I modified the PR to set the length the proper way by sending a mutable pointer to gl::GetShaderInfoLog to obtain the length of the string data copied to the infoLog buffer.

@vankessel vankessel changed the title Zero out message buffers Properly set infoLog length Feb 25, 2020
@vankessel
Copy link
Author

How's it look? @bwasty

@vankessel vankessel closed this Aug 9, 2020
@vankessel vankessel deleted the fix-invalid-utf8-buffer branch August 9, 2020 23:47
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.

Return string from GetShaderInfoLog may contain garbage?
2 participants