Richard W.M. Jones
2013-Dec-31 14:27 UTC
[Libguestfs] [PATCH 1/2] lib: write: Remove unused variable.
---
lib/write.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/lib/write.c b/lib/write.c
index 8c4dd8e..384c6b2 100644
--- a/lib/write.c
+++ b/lib/write.c
@@ -954,7 +954,6 @@ hivex_node_set_values (hive_h *h, hive_node_h node,
for (i = 0; i < nr_values; ++i) {
/* Allocate vk record to store this (key, value) pair. */
static const char vk_id[2] = { 'v', 'k' };
- size_t name_len = strlen (values[i].key);
size_t recoded_name_len;
int use_utf16;
char* recoded_name = _hivex_encode_string (values[i].key,
&recoded_name_len,
--
1.8.4.2
Richard W.M. Jones
2013-Dec-31 14:27 UTC
[Libguestfs] [PATCH 2/2] lib: utf16: Fix const-correctness issues in _hivex_recode function.
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
Pino Toscano
2014-Jan-06 10:31 UTC
Re: [Libguestfs] [PATCH 2/2] lib: utf16: Fix const-correctness issues in _hivex_recode function.
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
Maybe Matching Threads
- [PATCH 1/3] lib: Further generalize iconv wrapper function.
- Re: [PATCH] Add a cache for iconv_t handles to hive_t
- [PATCH] Add a cache for iconv_t handles to hive_t
- [PATCH] Add a cache for iconv_t handles to hive_t
- [PATCH 1/2] lib: write: Remove unused variable.