[Libguestfs] [PATCH common 2/4] options: Generate cryptsetup mapnames beginning with "crypt..." not "luks..."

Pino Toscano ptoscano at redhat.com
Mon Jul 27 17:01:08 UTC 2020


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20200727/1fb1d5b5/attachment.sig>


More information about the Libguestfs mailing list