Skip to content

Definition of ssize_t is wrong #39

@snej

Description

@snej

sockpp has its own declaration of ssize_t in platform.h, but on non-Windows systems it defines it as int. This is wrong on 64-bit OSs that use 32-bit ints, which includes all Apple platforms. (Dunno about Linux or BSD.) This leads to compile errors if a source file ends up including both platform.h and the OS's declaration. That aside, there are potentially actual integer overflow bugs if dealing with sizes > 4GB.

#ifndef _SSIZE_T_DEFINED
#define _SSIZE_T_DEFINED
#undef ssize_t
#ifdef _WIN64
using ssize_t = int64_t;
#else
using ssize_t = int;
#endif // _WIN64
#endif // _SSIZE_T_DEFINED

You shouldn't need to declare this at all. Instead:

  • On a POSIX-compliant OS, #include <sys/types.h>.
  • On Windows, #include <BaseTsd.h> and then using ssize_t = SSIZE_T;.

(Also, it's kind of icky that the types declared in platform.h are all in the global namespace. Could they be put in the sockpp namespace like the rest of the API?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions