[Libwebsockets] Correct way to initialize connect_info and context_info

andy at warmcat.com andy at warmcat.com
Tue Mar 24 05:16:53 CET 2020



On March 24, 2020 1:35:34 AM UTC, Brice Hamon <brice at ydotm.com> wrote:
>I think you are confused between the structure and a pointer to that
>structure.
>The sizeof (*m_context_info) will return the size of the pointer, and
>not the size of the structure you want to initialize.

In C anyway, if the type of that was a pointer, memset(p, 0, sizeof *p) will do the right thing.  Lws uses that pattern a lot when memsetting or memcpying since it shows up bugs with the sizeof type mismatching the pointed-to type, you'd have to use different vars in the two places in one line then to break it, which is much easier to see than a var and a sizeof type that looks credible as your eyes slide over it but can silently mismatch.

-Andy


More information about the Libwebsockets mailing list