Opened 12 years ago

Closed 12 years ago

#4859 closed Bugs (fixed)

boost/asio/detail/impl/socket_ops.ipp:122 produces "expression is always true" compile error on MS Visual Studio 2008

Reported by: Kris Nobes <kris.nobes@…> Owned by: chris_kohlhoff
Milestone: To Be Determined Component: asio
Version: Boost Release Branch Severity: Problem
Keywords: Cc:

Description

In boost/asio/detail/impl/socket_ops.ipp from boost_1_45_0_beta1 built with Microsoft Visual C++ compiler 2008, the following error is produced:

boost/asio/detail/impl/socket_ops.ipp(122): error C4296: '>=' : expression is always true

This is associated with the following block of code:

    // Try to complete the operation without blocking.
    socket_type new_socket = socket_ops::accept(s, addr, addrlen, ec);

    // Check if operation succeeded.
    if (new_socket >= 0)
      return new_socket;

socket_type is defined in socket_types.hpp, which on Windows is:

typedef SOCKET socket_type;

SOCKET is defined in winsock.h/winsock2.h as:

typedef UINT_PTR        SOCKET;

It would seem that new_socket should be compared to invalid_socket (defined in socket_types.hpp, line 86), which is the same test performed elsewhere in this file. The patch attached will produce this change but I'd like confirmation that the problem and solution are valid.

Also in:

  • branches/release/boost/asio/detail/impl/socket_ops.ipp @ 66173
  • trunk/boost/asio/detail/impl/socket_ops.ipp @ 66611

Attachments (1)

check_against_invalid_socket.patch (423 bytes ) - added by Kris Nobes <kris.nobes@…> 12 years ago.

Download all attachments as: .zip

Change History (3)

by Kris Nobes <kris.nobes@…>, 12 years ago

comment:1 by chris_kohlhoff, 12 years ago

(In [66620]) Merge from trunk. ........

r66613 | chris_kohlhoff | 2010-11-17 00:16:45 +1100 (Wed, 17 Nov 2010) | 2 lines

Fixed a Windows-specific problem where failures from accept() are incorrectly treated as successes. Refs #4859.

........

comment:2 by chris_kohlhoff, 12 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.