You need to free the char!
| 1106 | |
| 1107 | // You need to free the char! |
| 1108 | char* OLEDDisplay::utf8ascii(const String &str) { |
| 1109 | uint16_t k = 0; |
| 1110 | uint16_t length = str.length() + 1; |
| 1111 | |
| 1112 | // Copy the string into a char array |
| 1113 | char* s = (char*) malloc(length * sizeof(char)); |
| 1114 | if(!s) { |
| 1115 | DEBUG_OLEDDISPLAY("[OLEDDISPLAY][utf8ascii] Can't allocate another char array. Drop support for UTF-8.\n"); |
| 1116 | return (char*) str.c_str(); |
| 1117 | } |
| 1118 | str.toCharArray(s, length); |
| 1119 | |
| 1120 | length--; |
| 1121 | |
| 1122 | for (uint16_t i=0; i < length; i++) { |
| 1123 | char c = (this->fontTableLookupFunction)(s[i]); |
| 1124 | if (c!=0) { |
| 1125 | s[k++]=c; |
| 1126 | } |
| 1127 | } |
| 1128 | |
| 1129 | s[k]=0; |
| 1130 | |
| 1131 | // This will leak 's' be sure to free it in the calling function. |
| 1132 | return s; |
| 1133 | } |
| 1134 | |
| 1135 | void OLEDDisplay::setFontTableLookupFunction(FontTableLookupFunction function) { |
| 1136 | this->fontTableLookupFunction = function; |
nothing calls this directly
no test coverage detected