Skip to content

Commit

Permalink
test_async_driver.cc: fix NEGATIVE_RETURNS
Browse files Browse the repository at this point in the history
Fix for:

CID 1254374 (#1 of 1): Argument cannot be negative (NEGATIVE_RETURNS)
1. negative_return_fn: Function socket(2, SOCK_STREAM, 0) returns a
   negative number.
2. var_assign: Assigning: signed variable connect_sd = socket.
3. negative_returns: connect_sd is passed to a parameter that cannot
   be negative.

Signed-off-by: Danny Al-Gaaf <[email protected]>
  • Loading branch information
dalgaaf committed Mar 17, 2015
1 parent b4cfe73 commit e221463
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/test/msgr/test_async_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,26 +138,29 @@ TEST_P(EventDriverTest, PipeTest) {
void* echoclient(void *arg)
{
intptr_t port = (intptr_t)arg;
int connect_sd = ::socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in sa;
sa.sin_family = AF_INET;
sa.sin_port = htons(port);
char addr[] = "127.0.0.1";
int r = inet_aton(addr, &sa.sin_addr);
r = connect(connect_sd, (struct sockaddr*)&sa, sizeof(sa));
int t = 0;

do {
char c[] = "banner";
r = write(connect_sd, c, sizeof(c));
char d[100];
r = read(connect_sd, d, sizeof(d));
if (r == 0)
break;
if (t++ == 30)
break;
} while (1);
::close(connect_sd);
int connect_sd = ::socket(AF_INET, SOCK_STREAM, 0);
if (connect_sd >= 0) {
r = connect(connect_sd, (struct sockaddr*)&sa, sizeof(sa));
int t = 0;

do {
char c[] = "banner";
r = write(connect_sd, c, sizeof(c));
char d[100];
r = read(connect_sd, d, sizeof(d));
if (r == 0)
break;
if (t++ == 30)
break;
} while (1);
::close(connect_sd);
}
return 0;
}

Expand Down

0 comments on commit e221463

Please sign in to comment.