Null checks (#1216)
* 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
Этот коммит содержится в:
родитель
9149c64b9e
Коммит
24753fd762
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user