Re: AW: AW: Feature request for "friendship" of pointers in "C"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

there is an easy test, if Stefan is right and I'm wrong.

1. cast an INVALID Pointer to "aObj"
2. call "method_base(&aObj->obj,...)"

-> if stefan is right than "method_base" is called with an INVALID aObj as Pointer
-> if I am right than your software will CRASH :-)

that is the reason why I require the "frienddef".


mfg AO



On 03.02.20 09:16, aotto wrote:
Hi,

Can someone confirm that *aObj->obj does NOT create any extray "code" and does NOT do any POINTER resolution? -> if so than "gcc" already uses the "friend" logic I require :-)

→ I don't think that "gcc" do this already

Hi, the following scenario has a "definition hole" in the "C" language

code example:

-------------------------
struct base {
   ...
};

struct A {
   struct base obj;
   ...
} aObj;

struct B {
   struct base obj;
   ...
} bObj;

void method_base (struct base * hdl, ...);

method_base(&aObj, ...)
method_base(&bObj, ...)
------------------------


-----Ursprüngliche Nachricht-----
Von: aotto <aotto1968@xxxxxxxxxxx>
Gesendet: Montag, 3. Februar 2020 09:02
An: Stefan Franke <stefan@xxxxxxxxx>
Betreff: Re: AW: Feature request for "friendship" of pointers in "C"

This is not the same!

1. usually the aObj is a Pointer:
     -> &aObj.obj => &(aObj->obj)
2. this DOUBLE indirect access creates definitely a CRASH if
     aObj is invalid or freed
3. I use a internal a Pointer typecheck… where I can detect if
     "my" pointer is valid or freed… but a "&(aObj->obj)" you
     don't survive.

mfg

* Please reply at the bottom.

Ad 1: there is no need for '(' ')' if it's a pointer

    &aObj->obj


Ad 2: this is not a double indirect access, the resulting address is the same as aObj as long obj is the first element of your struct, only the type changes

   (void *)aObj == (void*)&aObj->obj

Ad 3: since the address is the same, your check will work.

Your issues aren't related to gcc - you might consider improving your C skills.

Cheers

Stefan




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux