On Tue 23 Jun 2015 01:10:39 AM CEST, Eric Blake <ebl...@redhat.com> wrote:

> +#define GEN_NODE_NAME_PREFIX    "__qemu##"
> +#define GEN_NODE_NAME_MAX_LEN   (sizeof(GEN_NODE_NAME_PREFIX) + 8 + 8)
>  static void bdrv_assign_node_name(BlockDriverState *bs,
>                                    const char *node_name,
>                                    Error **errp)
>  {
> +    char gen_node_name[GEN_NODE_NAME_MAX_LEN];
> +    static uint32_t counter; /* simple counter to guarantee uniqueness */

Any reason why you use uint32_t instead of just unsigned ?

> -    if (!id_wellformed(node_name)) {
> +        int len;
> +        snprintf(gen_node_name, GEN_NODE_NAME_MAX_LEN,
> +                 "%s%08x", GEN_NODE_NAME_PREFIX, counter++);
> +        len = strlen(gen_node_name);

No need to use strlen() here, snprintf() already returns the number of
characters written.

> +        while (len < GEN_NODE_NAME_MAX_LEN - 1) {
> +            gen_node_name[len++] = g_random_int_range('A', 'Z');
> +        }

I think this doesn't include the 'Z', the upper bound of the interval is
open.

Berto

Reply via email to