1
1
* Add NULL checks and comment

* Remove comment

* Change printf to iperf_err and add brackets to else

* Add test to iperf_err

* Revert iperf_err to printf
Этот коммит содержится в:
swlars 2021-10-04 17:12:30 -07:00 коммит произвёл GitHub
родитель 9149c64b9e
Коммит 24753fd762
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 40 добавлений и 1 удалений

Просмотреть файл

@ -54,6 +54,11 @@
int int
iperf_create_streams(struct iperf_test *test, int sender) iperf_create_streams(struct iperf_test *test, int sender)
{ {
if (NULL == test)
{
iperf_err(NULL, "No test\n");
return -1;
}
int i, s; int i, s;
#if defined(HAVE_TCP_CONGESTION) #if defined(HAVE_TCP_CONGESTION)
int saved_errno; int saved_errno;
@ -158,6 +163,12 @@ create_client_timers(struct iperf_test * test)
{ {
struct iperf_time now; struct iperf_time now;
TimerClientData cd; TimerClientData cd;
if (NULL == test)
{
iperf_err(NULL, "No test\n");
i_errno = IEINITTEST;
return -1;
}
if (iperf_time_now(&now) < 0) { if (iperf_time_now(&now) < 0) {
i_errno = IEINITTEST; i_errno = IEINITTEST;
@ -213,6 +224,11 @@ create_client_omit_timer(struct iperf_test * test)
{ {
struct iperf_time now; struct iperf_time now;
TimerClientData cd; TimerClientData cd;
if (NULL == test)
{
iperf_err(NULL, "No test\n");
return -1;
}
if (test->omit == 0) { if (test->omit == 0) {
test->omit_timer = NULL; test->omit_timer = NULL;
@ -239,6 +255,12 @@ iperf_handle_message_client(struct iperf_test *test)
int rval; int rval;
int32_t err; int32_t err;
if (NULL == test)
{
iperf_err(NULL, "No test\n");
i_errno = IEINITTEST;
return -1;
}
/*!!! Why is this read() and not Nread()? */ /*!!! Why is this read() and not Nread()? */
if ((rval = read(test->ctrl_sck, (char*) &test->state, sizeof(signed char))) <= 0) { if ((rval = read(test->ctrl_sck, (char*) &test->state, sizeof(signed char))) <= 0) {
if (rval == 0) { if (rval == 0) {
@ -334,6 +356,11 @@ iperf_handle_message_client(struct iperf_test *test)
int int
iperf_connect(struct iperf_test *test) iperf_connect(struct iperf_test *test)
{ {
if (NULL == test)
{
iperf_err(NULL, "No test\n");
return -1;
}
FD_ZERO(&test->read_set); FD_ZERO(&test->read_set);
FD_ZERO(&test->write_set); FD_ZERO(&test->write_set);
@ -436,6 +463,11 @@ iperf_connect(struct iperf_test *test)
int int
iperf_client_end(struct iperf_test *test) iperf_client_end(struct iperf_test *test)
{ {
if (NULL == test)
{
iperf_err(NULL, "No test\n");
return -1;
}
struct iperf_stream *sp; struct iperf_stream *sp;
/* Close all stream sockets */ /* Close all stream sockets */
@ -476,6 +508,12 @@ iperf_run_client(struct iperf_test * test)
int64_t timeout_us; int64_t timeout_us;
int64_t rcv_timeout_us; int64_t rcv_timeout_us;
if (NULL == test)
{
iperf_err(NULL, "No test\n");
return -1;
}
if (test->logfile) if (test->logfile)
if (iperf_open_logfile(test) < 0) if (iperf_open_logfile(test) < 0)
return -1; return -1;

Просмотреть файл

@ -59,7 +59,7 @@ iperf_err(struct iperf_test *test, const char *format, ...)
vsnprintf(str, sizeof(str), format, argp); vsnprintf(str, sizeof(str), format, argp);
if (test != NULL && test->json_output && test->json_top != NULL) if (test != NULL && test->json_output && test->json_top != NULL)
cJSON_AddStringToObject(test->json_top, "error", str); cJSON_AddStringToObject(test->json_top, "error", str);
else else {
if (test && test->outfile && test->outfile != stdout) { if (test && test->outfile && test->outfile != stdout) {
if (ct) { if (ct) {
fprintf(test->outfile, "%s", ct); fprintf(test->outfile, "%s", ct);
@ -72,6 +72,7 @@ iperf_err(struct iperf_test *test, const char *format, ...)
} }
fprintf(stderr, "iperf3: %s\n", str); fprintf(stderr, "iperf3: %s\n", str);
} }
}
va_end(argp); va_end(argp);
} }