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
Fixed OpenGL version string being parsed incorrectly on some platforms #1390
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The string length should be checked in each if
, right now you're accessing unchecked elements of the version
array, which is UB.
A final else
is missing after all the chained if
s, leaving the version number to an undefined state. Maybe we could set it to 1.1 before testing the version, so that we don't have to write else
blocks.
|
I was talking about what happens inside the blocks: m_settings.majorVersion = version[13] - '0';
m_settings.minorVersion = version[15] - '0'; strlen(version) should be > 15 in this case. |
I guess you don't want to have to assume that the OpenGL implementation is standard compliant? 😁 |
What standard? We are "parsing" strings we know nothing about 😀 |
ed8bb8f
to
3cccc10
Compare
Fixed. |
Looks very robust now 😆 What about a helper function to avoid all these repetitions? bool parseVersionString(const char* prefix, unsigned int versionPosition, unsigned int &major, unsigned int &minor); |
Naaah... an extra function just to move out 4 if statements? 😨 |
It would makes things more readable and shorter. 👍 Maybe even one if statement:
with some better formatting, ofc. |
3cccc10
to
607aa46
Compare
Fixed. |
Is there a reason to use strncmp with the last argument being strlen of one string? If it stops at the first encountered \0 anyway, maybe we can just use strcmp? |
Using |
src/SFML/Window/GlContext.cpp
Outdated
std::size_t versionPosition = std::strlen(prefix); | ||
|
||
if ((std::strlen(version) >= (versionPosition + 3)) && | ||
!std::strncmp(version, prefix, std::strlen(prefix)) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the third parameter could be replaced with versionPosition
, but it's a minor detail.
607aa46
to
235d95e
Compare
Fixed. |
Does it now look okay, @LaurentGomila? |
235d95e
to
1f51630
Compare
Yes, it is. Just for the sake of arguing, it would replace And of course we should quickly test this new implementation on OpenGL ES platforms to validate it. |
@kingnobody8 or @JonnyPtn Can you try the code? Need more of an actual test than review. 🙂 |
1f51630
to
58b844b
Compare
@LaurentGomila Fixed. |
Looks good to me! tested on iPhone 8 |
if (!parseVersionString(version, "OpenGL ES-CL ", m_settings.majorVersion, m_settings.minorVersion) && | ||
!parseVersionString(version, "OpenGL ES-CM ", m_settings.majorVersion, m_settings.minorVersion) && | ||
!parseVersionString(version, "OpenGL ES ", m_settings.majorVersion, m_settings.minorVersion) && | ||
!parseVersionString(version, "", m_settings.majorVersion, m_settings.minorVersion)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the minor remark, but logical ors || make more sense here, don't they?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so - it's checking that none of the parse attempts work, not that any of them didn't work
Looks good. Tested on Windows, Android, Mac, and iOS, all successfully. |
58b844b
to
a106573
Compare
Fixes #1249.