[stunnel-users] [PATCH] Fix undefined aliasing in libwrap.c

Ludolf Holzheid lholzheid at bihl-wiedemann.de
Sat May 2 17:43:28 CEST 2009


On Sat, 2009-05-02 14:44:02 +0200, Michal Trojnara wrote:
> Miloslav Trmac wrote:
> >The attached patch changes the code not to access a part of a  
> >char[...] array using an int *, which is undefined in ISO C.
> 
> Casting pointers is undefined?  On some architectures it could make  
> sense due to data alignment issues, but I really didn't know that.   
> Where did you find it?

I suppose Miloslav didn't want to say 'undefined', but 'leads to
undefined behavior'.

In fact, accessing objects at addresses not suitable aligned leads to
strange effects on some machines (e.g. ARM9 or C165), but this fact is
not even mentioned in IEC9899:1999 (a.k.a. C99).

Even worse C99 _defines_ void* to "have the same representation and
alignment requirements as a pointer to a character type", which is not
suitable the vast majority of the objects one could have pointers
for. A nightmare for static code checkers ...

Ludolf

-- 

---------------------------------------------------------------
Ludolf Holzheid             Tel:    +49 621 339960
Bihl+Wiedemann GmbH         Fax:    +49 621 3392239
Floßwörthstraße 41          e-mail: lholzheid at bihl-wiedemann.de
D-68199 Mannheim, Germany
---------------------------------------------------------------




More information about the stunnel-users mailing list