h2o / picotls

TLS 1.3 implementation in C (master supports RFC8446 as well as draft-26, -27, -28)
527 stars 140 forks source link

Fix use of bitfield unsupported by Windows compilers #508

Closed huitema closed 6 months ago

huitema commented 6 months ago

The current definition of "ticket context" in picotls.h uses an unsupported construct:

        uint8_t is_set : 1;

This creates a fatal error when picotls.h is included in applications compiled in Visual Studio, like in this run of picoquic:

     4>c:\projects\picotls\include\picotls.h(989): error C2220: warning treated as error - no 'object' file generated [C:\projects\picoquic\picohttp\picohttp.vcxproj]
     4>c:\projects\picotls\include\picotls.h(989): warning C4214: nonstandard extension used: bit field types other than int [C:\projects\picoquic\picohttp\picohttp.vcxproj]

Changing to:

    /**
     * (optional) session ID Context to segment resumption
     */
    struct {
        uint8_t bytes[PTLS_SHA256_DIGEST_SIZE];
#ifdef _WINDOWS
        unsigned int is_set : 1;
#else
        uint8_t is_set : 1;
#endif
    } ticket_context;

Note that on Windows compilers, "unsigned int is_set : 1;" occupies a single byte, so there is no cost to that typing.

I also needed to remove a stray character that somehow made it into mbedtls.c.

huitema commented 6 months ago

@kazuho I have accepted your changes. I considered that too, but I was wondering whether there was some good reason for the uint8_t. Will merge the PR once the CI tests have passed.