Permalink
Browse files

test, bench: replace strlen() with sizeof()

  • Loading branch information...
1 parent 0a05b31 commit f5b6374948447c6ee5cf399d6b50a1e4d8a11723 @bnoordhuis bnoordhuis committed Dec 14, 2012
Showing with 6 additions and 11 deletions.
  1. +1 −3 test/benchmark-ping-pongs.c
  2. +3 −3 test/run-tests.c
  3. +2 −5 test/test-ping-pong.c
@@ -24,7 +24,6 @@
#include <stdlib.h>
#include <stdio.h>
-#include <string.h> /* strlen */
/* Run the benchmark for this many ms */
#define TIME 5000
@@ -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)) {
View
@@ -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);
View
@@ -24,7 +24,6 @@
#include <stdlib.h>
#include <stdio.h>
-#include <string.h> /* strlen */
static int completed_pingers = 0;
@@ -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");
}

0 comments on commit f5b6374

Please sign in to comment.