On Tue 05 Jul 2016 12:49:59 PM CEST, "Daniel P. Berrange" <berra...@redhat.com> 
wrote:
> +    cs = g_checksum_new(qcrypto_hash_alg_map[alg]);
> +
> +    for (i = 0; i < niov; i++) {
> +        g_checksum_update(cs, iov[i].iov_base, iov[i].iov_len);
> +    }

Not too important, but you could do this after checking the hash length
and the buffer size. You don't need to create or feed the GChecksum
first for those, and that way you would also get rid of the 'goto
error'.

Either way,

Reviewed-by: Alberto Garcia <be...@igalia.com>

> +    ret = g_checksum_type_get_length(qcrypto_hash_alg_map[alg]);
> +    if (ret < 0) {
> +        error_setg(errp, "%s",
> +                   "Unable to get hash length");
> +        goto error;
> +    }
> +    if (*resultlen == 0) {
> +        *resultlen = ret;
> +        *result = g_new0(uint8_t, *resultlen);
> +    } else if (*resultlen != ret) {
> +        error_setg(errp,
> +                   "Result buffer size %zu is smaller than hash %d",
> +                   *resultlen, ret);
> +        goto error;
> +    }
> +
> +    g_checksum_get_digest(cs, *result, resultlen);
> +
> +    g_checksum_free(cs);
> +    return 0;
> +
> + error:
> +    g_checksum_free(cs);
> +    return -1;
> +}

Berto

Reply via email to