-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Notifications: replace newlines in label-copy instead of const char* title directly #976
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
Notifications: replace newlines in label-copy instead of const char* title directly #976
Conversation
|
In this case, it's not clear if we use the strchr() function from the C library ( According to CLion, strchr() comes from string.h, which is the C version that does not define a However, even if we are using the C version, we still modify the content of the string I guess the intent of the code was to avoid the copy and the memory overhead of std::string (with potential dynamic allocation). I'm wondering : is there any other solution that would respect the constness that does not need a std::string temporary variable? |
|
Found a solution: Also removed an unused struct in |
5870cb5 to
9fe2a27
Compare
|
Did you check that it actually works? The text buffer is edited, but LVGL is not aware of that change. According to the code of |
|
It worked in the simulator, but I'll add the |
5b5cc8c to
15d781b
Compare
|
Did you check with notification title that contains a \n character? |
|
The newline is only replaced in the title (the |
InfiniTimeOrg/InfiniTime#976 splits SystemMonitor.h into a h and cpp file. Add the cpp file to the infinisim target.
…title The variable `title` is defined as `const char*`, which means, that `strchr()` returns a `const char*` as well according to https://www.cplusplus.com/reference/cstring/strchr/ But in the same line the return value is assigned to a non-const `char*`, which shouldn't be allowed (error with `-pedantic`). Because the `lv_label` creates an internal copy of the title sting, just modify that one instead and replace newline in the copied string.
15d781b to
675af69
Compare
|
rebased on current |
InfiniTimeOrg/InfiniTime#976 splits SystemMonitor.h into a h and cpp file. Add the cpp file to the infinisim target.
InfiniTimeOrg/InfiniTime#976 splits SystemMonitor.h into a h and cpp file. Add the cpp file to the infinisim target.


The variable
titleis defined asconst char*, which means, thatstrchr()returns aconst char*as well according tohttps://www.cplusplus.com/reference/cstring/strchr/
But in the same line the return value is assigned to a non-const
char*, which shouldn't be allowed (error with-pedantic).To prevent manual memory management just use
std::stringto copy theprovided title and replace newlines in the copied string.