-
Notifications
You must be signed in to change notification settings - Fork 47
Source updates + string bugfix #34
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
Conversation
These should be immutable. Fixes deprecated conversion warnings from string constant to 'char*'
This doesn't work and causes the ESP to crash, as the character array is cleared once the function exits.
This is immutable, so the built-in C-string function works fine.
Simpler, matches the style of other private members, and avoids confusion in the constructor
This is always required and shouldn't ever need to be replaced, so this is better suited as a reference.
Previously this was a mix of 2 space, 4 space, and tab indentation. This standardizes everything using tabs for indentation and spaces for alignment.
The idea behind the String constructor is as you suspected to maintain backwards compatibility, but maybe it was not tested! I would like to keep it so if its causing a crash it should be fixed to work. Have raised an issue for it #35 Moving to const char makes sense to remove compiler warnings What is the advantage of moving from a pointer to a reference? I'm not asking that combatively, I genuinely would like to know! The first library I wrote was based off someone else code that used the pointer and it worked fine so I never saw the need for changing it! I need to provide a common solution for formatting, I should have clang format installed on my VCode instance now, but I might not have had it at the time of last working on this library |
See issue witnessmenow#35 and discussion of replacement in witnessmenow#34.
There's nothing strictly 'wrong' about doing it one way or another, but references provide several small advantages over pointers (most of them meta). For one a reference cannot be unbound (made null), so you don't have to perform And because you're not working with memory you don't have to dereference the symbol. You can treat the reference like the original symbol, which means no dereference operators ( Rule of thumb as I learned it: use references when you can, pointers when you have to 👍. I hope that helps.
Let me know if you have a different style preference, if you're busy I'd be happy to make the changes myself. |
About the The current version I just pushed (b7186ed) is simple but contains a fatal flaw: because it uses a pointer to the heap, if the user ever modifies the original As I see it there are four possible solutions:
That is, using the pointer to the
This technically breaks backwards compatibility with the
That is, create a
Similar to solution 3, this would copy the passed string into a character array stored on the heap, and then free the memory if/when the library object is destroyed. No dependency on the Personally I don't think the |
Still immutable, and more efficient than making a temporary copy
Per Brian's insistance on keeping the String version of the constructor (witnessmenow#34), this needs to be stored as a String (or otherwise as a copy on the heap) to prevent issues where the user mutates or destroys the original object the C-string pointer was referencing.
e1640de
to
00ffc8c
Compare
I've pushed a few additional changes to improve the Lastly, I've changed the internal storage of the API key to use a |
Thanks @dmadison , sorry about the delay in merging |
No worries, life happens 🙂 |
This fixes the warnings + bugs related to strings being passed as
char*
instead ofconst char*
. It also removes the underscore prefix for the API key, switches the storedclient
from a pointer to a reference, and standardizes the whitespace with tabs for indentation and spaces for alignment.Nothing in here should change the public behavior or break the public API with the possible exception of the removed
String
version of the constructor. Although I'm fairly sure that isn't used since it crashes the ESP.