This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Issue with sub-object __builtin_object_size
- From: "Ulrich Weigand" <uweigand at de dot ibm dot com>
- To: jason at redhat dot com (Jason Merrill)
- Cc: jakub at redhat dot com, gcc at gcc dot gnu dot org
- Date: Mon, 15 Sep 2014 17:55:55 +0200 (CEST)
- Subject: Re: Issue with sub-object __builtin_object_size
- Authentication-results: sourceware.org; auth=none
Jason Merrill wrote:
> On 09/15/2014 11:21 AM, Ulrich Weigand wrote:
> > Jakub Jelinek wrote:
> >> On Tue, Jun 10, 2014 at 07:37:50PM +0200, Ulrich Weigand wrote:
> >>> the following C++ test case:
> >>>
> >>> struct pollfd
> >>> {
> >>> int fd;
> >>> short int events;
> >>> short int revents;
> >>> };
> >>>
> >>> struct Pollfd : public pollfd { };
> >>>
> >>> struct Pollfd myfd[10];
> >>>
> >>> int test (void)
> >>> {
> >>> return __builtin_object_size ((struct pollfd *)myfd, 1);
> >>> }
> >>>
> >>> ends up returning 8 from the "test" routine, not 80.
>
> This example strikes me as strange. Why do you expect the size of a
> pointer to the base class subobject to give a meaningful answer, any
> more than taking the address of a data member?
Well, it's a test case simplified from a real-world example. To quote
the original mail at the start of this thread:
>In the real-world application this test case was extracted from,
>this causes a call:
>
> poll(myfd, count, 0); // 1 < count < 10
>
>to fail with a "Buffer overflow detected" message at run-time
>when building with _FORTIFY_SOURCE = 2 against glibc. [ Here,
>there is no explicit cast, but it is implied by the prototype
>of the "poll" routine. ]
>
>(Note that in the real-world application, the derived struct Pollfd
>has some member functions to construct and pretty-print the structure,
>but has no additional data members.)
(https://gcc.gnu.org/ml/gcc/2014-06/msg00116.html)
Thanks,
Ulrich
--
Dr. Ulrich Weigand
GNU/Linux compilers and toolchain
Ulrich.Weigand@de.ibm.com