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.