Boost logo

Boost :

Subject: Re: [boost] [beast] Formal review
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2017-07-12 09:07:15


On 07/12/17 11:19, Groke, Paul via Boost wrote:
>
> I didn't follow the discussion close enough so I might be mistaken, but isn't this a function that takes a char* as input (from user code)?
> If that is so, using size_ts to read the chars could be an aliasing violation. Namely if the user thinks that he can pass e.g. a pointer to an int array, because the function takes a char pointer, and char may alias...
> Then he'd have one part of the application access a memory location with size_t, which was written by another part of the application using int.

That would be a problem, yes. Although the use case when a UTF-8 string
is represented with an array of ints seems unlikely to me.

I think the best solution would be to mark size_t with
__attribute__((__may_alias__)) and use it instead of plain size_t.

   #if defined(__GNUC__)
   #define BEAST_MAY_ALIAS __attribute__((__may_alias__))
   #else
   #define BEAST_MAY_ALIAS
   #endif

   typedef std::size_t BEAST_MAY_ALIAS pack_t;
   const pack_t* p = reinterpret_cast< const pack_t* >(string);


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk