Skip to content

Commit

Permalink
test, bench: replace strlen() with sizeof()
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Dec 14, 2012
1 parent 0a05b31 commit f5b6374
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
4 changes: 1 addition & 3 deletions test/benchmark-ping-pongs.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

#include <stdlib.h>
#include <stdio.h>
#include <string.h> /* strlen */

/* Run the benchmark for this many ms */
#define TIME 5000
Expand Down Expand Up @@ -103,8 +102,7 @@ static void pinger_write_ping(pinger_t* pinger) {
uv_write_t* req;
uv_buf_t buf;

buf.base = (char*)&PING;
buf.len = strlen(PING);
buf = uv_buf_init(PING, sizeof(PING) - 1);

req = malloc(sizeof *req);
if (uv_write(req, (uv_stream_t*) &pinger->tcp, &buf, 1, pinger_write_cb)) {
Expand Down
6 changes: 3 additions & 3 deletions test/run-tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,16 @@ static int maybe_run_test(int argc, char **argv) {
}

if (strcmp(argv[1], "spawn_helper5") == 0) {
const char* out = "fourth stdio!\n\0";
const char out[] = "fourth stdio!\n";
#ifdef _WIN32
DWORD bytes;
WriteFile((HANDLE) _get_osfhandle(3), out, strlen(out), &bytes, NULL);
WriteFile((HANDLE) _get_osfhandle(3), out, sizeof(out) - 1, &bytes, NULL);
#else
{
ssize_t r;

do
r = write(3, out, strlen(out));
r = write(3, out, sizeof(out) - 1);
while (r == -1 && errno == EINTR);

fsync(3);
Expand Down
7 changes: 2 additions & 5 deletions test/test-ping-pong.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

#include <stdlib.h>
#include <stdio.h>
#include <string.h> /* strlen */

static int completed_pingers = 0;

Expand Down Expand Up @@ -77,11 +76,9 @@ static void pinger_write_ping(pinger_t* pinger) {
uv_write_t *req;
uv_buf_t buf;

buf.base = (char*)&PING;
buf.len = strlen(PING);

req = malloc(sizeof(uv_write_t));
buf = uv_buf_init(PING, sizeof(PING) - 1);

req = malloc(sizeof(*req));
if (uv_write(req, (uv_stream_t*)&pinger->stream.tcp, &buf, 1, pinger_after_write)) {
FATAL("uv_write failed");
}
Expand Down

0 comments on commit f5b6374

Please sign in to comment.