This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [patch 4/6] Prepare linux_find_memory_regions_full & co. for move
- From: Pedro Alves <palves at redhat dot com>
- To: Aleksandar Ristovski <aristovski at qnx dot com>
- Cc: Jan Kratochvil <jan dot kratochvil at redhat dot com>, "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>
- Date: Thu, 28 Mar 2013 21:41:10 +0000
- Subject: Re: [patch 4/6] Prepare linux_find_memory_regions_full & co. for move
- References: <51278984 dot 3070208 at qnx dot com> <20130310210820 dot GE21130 at host2 dot jankratochvil dot net> <514C56CB dot 4070207 at qnx dot com> <20130326165242 dot GA12291 at host2 dot jankratochvil dot net> <515353C4 dot 2050203 at qnx dot com> <20130328202805 dot GB9375 at host2 dot jankratochvil dot net> <5154AE75 dot 4050103 at qnx dot com>
On 03/28/2013 08:56 PM, Aleksandar Ristovski wrote:
>>>
>>> +static char *
>>> +read_stralloc (const char *filename, read_stralloc_func_ftype *func)
>>> {
>>> - gdb_byte *buffer;
>>> - char *bufstr;
>>> + char *buffer;
>>
>> Why you make this change? That is unrelated to this patchset, it is a recent
>> modification by Pedro.
>
>
> [AR] I apologize to Pedro - the code as I put it seems more natural, a few less lines and such. But I can remove it, it is not essential.
Please don't revert that.
> fad14e531 (Pedro Alves 2013-03-11 12:22:16 +0000 3546) gdb_byte *buffer;
> fad14e531 (Pedro Alves 2013-03-11 12:22:16 +0000 3547) char *bufstr;
$ git show fad14e531
commit fad14e531b1fa96211beac28557d7fb5d42a8b80
Author: Pedro Alves <palves@redhat.com>
Date: Mon Mar 11 12:22:16 2013 +0000
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.
--
Pedro Alves