HAL_ChibiOS: Get the number of characters in strlen

This commit is contained in:
murata 2019-01-09 05:20:02 +09:00 committed by Andrew Tridgell
parent 2e1e99eafc
commit 6bb11b5cc8

View File

@ -201,12 +201,14 @@ static bool string_contains(const char *haystack, const char *needle)
*/
static void string_substitute(const char *str, char *str2)
{
const char *board = "%BOARD%";
const char *serial = "%SERIAL%";
uint8_t new_len = strlen(str);
if (string_contains(str, "%BOARD%")) {
new_len += strlen(HAL_BOARD_NAME) - 7;
if (string_contains(str, board)) {
new_len += strlen(HAL_BOARD_NAME) - strlen(board);
}
if (string_contains(str, "%SERIAL%")) {
new_len += 24 - 8;
if (string_contains(str, serial)) {
new_len += 24 - strlen(serial);
}
if (new_len+1 > USB_DESC_MAX_STRLEN) {
strcpy(str2, str);
@ -216,13 +218,13 @@ static void string_substitute(const char *str, char *str2)
while (*str) {
char c = *str;
if (c == '%') {
if (strncmp(str, "%BOARD%", 7) == 0) {
if (strncmp(str, board, strlen(board)) == 0) {
memcpy(p, HAL_BOARD_NAME, strlen(HAL_BOARD_NAME));
str += 7;
p += strlen(HAL_BOARD_NAME);
continue;
}
if (strncmp(str, "%SERIAL%", 8) == 0) {
if (strncmp(str, serial, strlen(serial)) == 0) {
const char *hex = "0123456789ABCDEF";
const uint8_t *cpu_id = (const uint8_t *)UDID_START;
uint8_t i;