This patch assumes that iconv doesn't actually modify the
input buffer, even though it is declared as char *.
---
lib/hivex-internal.h | 6 +++---
lib/utf16.c | 9 +++++----
2 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/lib/hivex-internal.h b/lib/hivex-internal.h
index 7a548c0..6bc8638 100644
--- a/lib/hivex-internal.h
+++ b/lib/hivex-internal.h
@@ -268,9 +268,9 @@ extern size_t * _hivex_return_offset_list (offset_list *list);
extern void _hivex_print_offset_list (offset_list *list, FILE *fp);
/* utf16.c */
-extern char* _hivex_recode (char *input_encoding,
- const char *input, size_t input_len,
- char *output_encoding, size_t *output_len);
+extern char * _hivex_recode (const char *input_encoding,
+ const char *input, size_t input_len,
+ const char *output_encoding, size_t *output_len);
#define _hivex_windows_utf16_to_utf8(_input, _len) \
_hivex_recode ("UTF-16LE", _input, _len, "UTF-8", NULL)
#define _hivex_windows_latin1_to_utf8(_input, _len) \
diff --git a/lib/utf16.c b/lib/utf16.c
index 437613b..3641580 100644
--- a/lib/utf16.c
+++ b/lib/utf16.c
@@ -30,8 +30,8 @@
#include "hivex-internal.h"
char *
-_hivex_recode (char *input_encoding, const char *input, size_t input_len,
- char *output_encoding, size_t *output_len)
+_hivex_recode (const char *input_encoding, const char *input, size_t input_len,
+ const char *output_encoding, size_t *output_len)
{
iconv_t ic = iconv_open (output_encoding, input_encoding);
if (ic == (iconv_t) -1)
@@ -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) {
if (errno == E2BIG) {
int err = errno;
--
1.8.4.2