[Libguestfs] [PATCH 2/2] lib: utf16: Fix const-correctness issues in _hivex_recode function.

Pino Toscano ptoscano at redhat.com
Mon Jan 6 10:31:18 UTC 2014


On Tuesday 31 December 2013 14:27:11 Richard W.M. Jones wrote:
> This patch assumes that iconv doesn't actually modify the
> input buffer, even though it is declared as char *.
> ---
> [...]
> @@ -51,10 +51,11 @@ _hivex_recode (char *input_encoding, const char
> *input, size_t input_len, errno = err;
>      return NULL;
>    }
> -  char *inp = input;
> +  const char *inp = input;
>    char *outp = out;
> 
> -  size_t r = iconv (ic, &inp, &inlen, &outp, &outlen);
> +  /* Surely iconv doesn't really modify the input buffer? XXX */
> +  size_t r = iconv (ic, (char **) &inp, &inlen, &outp, &outlen);
>    if (r == (size_t) -1) {

This (the constness of the input argument) is the difference between the 
iconv implementation provided in GNU libc and the other ones, even 
though it reflects POSIX [1].

The iconv.m4 module in gnulib checks for this too, and AC_DEFINE's 
ICONV_CONST as "const" (or empty) depending on the actual prototype of 
iconv(3).

[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/iconv.html

-- 
Pino Toscano




More information about the Libguestfs mailing list