diff options
author | Pedro Alves <palves@redhat.com> | 2013-03-11 12:22:20 +0000 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2013-03-11 12:22:20 +0000 |
commit | 39086a0e1346572fac07542ede2a1ef153308a2a (patch) | |
tree | 55287581f85b93530d40c06578f98c07ba535cac /gdb/charset.c | |
parent | 905851752e89f4fa2cc13e6df0f2dbd22c82f623 (diff) | |
download | gdb-39086a0e1346572fac07542ede2a1ef153308a2a.zip gdb-39086a0e1346572fac07542ede2a1ef153308a2a.tar.gz gdb-39086a0e1346572fac07542ede2a1ef153308a2a.tar.bz2 |
Avoid invalid pointer to pointer conversions.
Casts between 'char **' <-> 'unsigned char **' and 'char **' <-> const
char **' are actually invalid:
http://gcc.gnu.org/ml/gcc-help/2013-03/msg00118.html
In a nutshell, char (and variants) can alias anything, but pointers to
chars get no special treatment (cf. C99/N1256, 6.5/7).
Turns out older gcc's actually warn/complain on these constructs,
though newer one's don't:
http://sourceware.org/ml/gdb-patches/2013-03/msg00429.html
http://sourceware.org/ml/gdb-patches/2013-03/msg00430.html
This patch fixes the cases I added last week. It also fixes one other
preexisting case in charset.c, though it seems even older gccs don't
complain of char * <-> const char * aliasing.
Tested on x86_64 Fedora 17.
gdb/
2013-03-11 Pedro Alves <palves@redhat.com>
* charset.c (convert_between_encodings): Don't cast between
different pointer to pointer types. Instead, make the 'inp' local
be of the type iconv expects.
(wchar_iterate): Don't cast between different pointer to pointer
types. Instead, use new pointer local of the type iconv expects.
* target.c (target_read_stralloc, target_fileio_read_stralloc):
Add new local of type char pointer, and use it to get a
char/string view of the byte buffer, instead of casting between
pointer to pointer types.
Diffstat (limited to 'gdb/charset.c')
-rw-r--r-- | gdb/charset.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/gdb/charset.c b/gdb/charset.c index 4cd6f20..5835fd4 100644 --- a/gdb/charset.c +++ b/gdb/charset.c @@ -474,7 +474,7 @@ convert_between_encodings (const char *from, const char *to, iconv_t desc; struct cleanup *cleanups; size_t inleft; - char *inp; + ICONV_CONST char *inp; unsigned int space_request; /* Often, the host and target charsets will be the same. */ @@ -490,7 +490,7 @@ convert_between_encodings (const char *from, const char *to, cleanups = make_cleanup (cleanup_iconv, &desc); inleft = num_bytes; - inp = (char *) bytes; + inp = (ICONV_CONST char *) bytes; space_request = num_bytes; @@ -506,7 +506,7 @@ convert_between_encodings (const char *from, const char *to, outp = obstack_base (output) + old_size; outleft = space_request; - r = iconv (desc, (ICONV_CONST char **) &inp, &inleft, &outp, &outleft); + r = iconv (desc, &inp, &inleft, &outp, &outleft); /* Now make sure that the object on the obstack only includes bytes we have converted. */ @@ -640,14 +640,15 @@ wchar_iterate (struct wchar_iterator *iter, out_request = 1; while (iter->bytes > 0) { + ICONV_CONST char *inptr = (ICONV_CONST char *) iter->input; char *outptr = (char *) &iter->out[0]; const gdb_byte *orig_inptr = iter->input; size_t orig_in = iter->bytes; size_t out_avail = out_request * sizeof (gdb_wchar_t); size_t num; - size_t r = iconv (iter->desc, - (ICONV_CONST char **) &iter->input, - &iter->bytes, &outptr, &out_avail); + size_t r = iconv (iter->desc, &inptr, &iter->bytes, &outptr, &out_avail); + + iter->input = (gdb_byte *) inptr; if (r == (size_t) -1) { |