On Monday, 30 March 2020 16:58:47 CEST Richard W.M. Jones wrote:
- for (; device[i] != '\0' && len >= 1; ++i) { - if (c_isalnum (device[i])) { - *mapname++ = device[i]; - len--; - } + if (asprintf (&ret, "crypt%s", &device[i]) == -1) + error (EXIT_FAILURE, errno, "asprintf"); + + for (i = 5; i < strlen (ret); ++i) { + if (!c_isalnum (ret[i])) + memmove (&ret[i], &ret[i+1], strlen (&ret[i])); }
I'd say that this can be simplified even more: instead of first copying the string (asprintf) and then remove all the unwanted characters by shifting the characters after (with memmove), simply allocate a string of the maximum length needed and then copy the wanted characters. ... that is, use the old approach. -- Pino Toscano