-
-
Notifications
You must be signed in to change notification settings - Fork 112
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
No more warning popup when using a math function with a semicolon #1155
Conversation
PR Summary 📝
So, in a nutshell, this PR is all about superior control and enhanced performance. Excellent job to our dev team for making these thoughtful improvements! 🥳 |
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'm approving this as there's down side to it, but I'd like to know what the source of the orginal issue is and why this fixes it, as I can't reproduce the error with MSVC 64bit builds in my locale.
Mmmm, strange that you don't have the same warning... It seems that doing so is deprecated because when the code reaches the 3rd line, szSep is equal to ";" and has a length of 1. When calling
The Qt documentation recommends using |
I checked a slew of builds... old Seamly 32 & 64 bit gcc builds, my current Seamly MSVC 2022 build, a current Seamly MSVC 2014 release... even some Valentina builds... none of them produce the error. The question is.. are you getting the error only with your builds? or with any downloaded Seamly releases too? If it's just your builds it has to be something in your build environment. If it's any build, then it might be your machine or locale... in which case other users may also be affected. To be honest most users are not going to be using the math functions at all. I don't know of any pattern system requires them... they're just there because they were in the orginal muparser lib.
Not sure what you mean when you say 1 is out of range? It looks pretty clear that szSep's 1st char is set to ';', its second char is set to 0 (null). A QString will grow in size if needed. Yes you can set the resize of the string to 2, but that's an efficency thing so as not to allocate more memory than neccessary. So I don't lnow if it's a locale issue, a utf issue, or something in your build configuration that's doing something to the QString. Keep in mind that the qmuparser is a port to Qt by RT of the muparser. So he didn't change any of the odd coding - including all the annoying spaces before and after parenthesis. That being said... a simpler, clearer, and more Qt way:
Could we do this to save memory? QString szSep; Sure... but worrying about this instance is trival... like worrying about how many tool ids we can create before running out. szSep is only going to be inscope for a few millisecs. |
Only with my builds indeed.
I'm not sure about that. The [] operator is only "return[ing] the character at the specified position in the string as a modifiable reference.", I'm not aware of it being able to increase the qstring size. There are other methods to append chars to strings. This operator does not check if the given index is out of range or not, leading to a random behavior that seems to depend on the configuration if a out-of-range index is given.
|
Right... if you are ACCESSING not assigning. szSep[1] = 0; is not accessing anything... it's assigning the 2nd char the value 0. On the other hand char3 = szSep[2} would be invalid as it's trying to access a 3rd char that does not exist in the string as the string length = 2. Well it exists - as a memory address. but it's invalid data.
I modified the tooltip example to illustrate: Where it shows that the length of the string grows as you assign new chars by indexing the array. Which is exactly what the math parser code is doing without needing the resize.
Which is a good thing, but like I said... it's more an issue with your configuration, not the code. What that is I can only speculate, but it would be nice to know. |
I may be wrong, but I think that by writing Qt seems to understand what you're trying to do and is increasing the size of the QString accordingly, but this seems to be deprecated, as mentioned in the warnings:
I get that it's currently working, but it doesn't seem to be a "clean" way of doing it. I can't find any official Qt doc showing this way of appending chars to QStrings. Using the
Since this way of appending a char to a qstring is known to be deprecated and to cause random behaviors, it's partly the code's fault if the behavior depends on the computer's configuration... |
solves #1153