diff --git a/atf-c/detail/fs.c b/atf-c/detail/fs.c index 5ff7648c..2a584428 100644 --- a/atf-c/detail/fs.c +++ b/atf-c/detail/fs.c @@ -175,16 +175,12 @@ atf_error_t copy_contents(const atf_fs_path_t *p, char **buf) { atf_error_t err; - char *str; - str = (char *)malloc(atf_dynstr_length(&p->m_data) + 1); - if (str == NULL) + *buf = strdup(atf_fs_path_cstring(p)); + if (*buf == NULL) err = atf_no_memory_error(); - else { - strcpy(str, atf_dynstr_cstring(&p->m_data)); - *buf = str; + else err = atf_no_error(); - } return err; } @@ -795,10 +791,8 @@ atf_fs_mkdtemp(atf_fs_path_t *p) atf_error_t err; char *buf; - if (!check_umask(S_IRWXU, S_IRWXU)) { - err = invalid_umask_error(p, atf_fs_stat_dir_type, current_umask()); - goto out; - } + if (!check_umask(S_IRWXU, S_IRWXU)) + return invalid_umask_error(p, atf_fs_stat_dir_type, current_umask()); err = copy_contents(p, &buf); if (atf_is_error(err)) @@ -806,14 +800,13 @@ atf_fs_mkdtemp(atf_fs_path_t *p) err = do_mkdtemp(buf); if (atf_is_error(err)) - goto out_buf; + goto out; replace_contents(p, buf); INV(!atf_is_error(err)); -out_buf: - free(buf); out: + free(buf); return err; } @@ -824,10 +817,8 @@ atf_fs_mkstemp(atf_fs_path_t *p, int *fdout) char *buf; int fd; - if (!check_umask(S_IRWXU, S_IRWXU)) { - err = invalid_umask_error(p, atf_fs_stat_reg_type, current_umask()); - goto out; - } + if (!check_umask(S_IRWXU, S_IRWXU)) + return invalid_umask_error(p, atf_fs_stat_reg_type, current_umask()); err = copy_contents(p, &buf); if (atf_is_error(err)) @@ -835,15 +826,14 @@ atf_fs_mkstemp(atf_fs_path_t *p, int *fdout) err = do_mkstemp(buf, &fd); if (atf_is_error(err)) - goto out_buf; + goto out; replace_contents(p, buf); *fdout = fd; INV(!atf_is_error(err)); -out_buf: - free(buf); out: + free(buf); return err; } diff --git a/atf-c/detail/process.c b/atf-c/detail/process.c index 2bc8294c..c19e27e4 100644 --- a/atf-c/detail/process.c +++ b/atf-c/detail/process.c @@ -67,6 +67,8 @@ stream_prepare_init(stream_prepare_t *sp, const atf_process_stream_t *sb) const int type = atf_process_stream_type(sb); sp->m_sb = sb; + sp->m_pipefds[0] = -1; + sp->m_pipefds[1] = -1; sp->m_pipefds_ok = false; if (type == atf_process_stream_type_capture) { @@ -239,14 +241,12 @@ atf_process_status_coredump(const atf_process_status_t *s) * --------------------------------------------------------------------- */ static -atf_error_t +void atf_process_child_init(atf_process_child_t *c) { c->m_pid = 0; c->m_stdout = -1; c->m_stderr = -1; - - return atf_no_error(); } static @@ -381,25 +381,17 @@ parent_connect(const stream_prepare_t *sp, int *fd) } static -atf_error_t +void do_parent(atf_process_child_t *c, const pid_t pid, const stream_prepare_t *outsp, const stream_prepare_t *errsp) { - atf_error_t err; - - err = atf_process_child_init(c); - if (atf_is_error(err)) - goto out; c->m_pid = pid; parent_connect(outsp, &c->m_stdout); parent_connect(errsp, &c->m_stderr); - -out: - return err; } static @@ -475,7 +467,7 @@ fork_with_streams(atf_process_child_t *c, abort(); err = atf_no_error(); } else { - err = do_parent(c, pid, &outsp, &errsp); + do_parent(c, pid, &outsp, &errsp); if (atf_is_error(err)) goto err_errpipe; } @@ -522,6 +514,8 @@ atf_process_fork(atf_process_child_t *c, atf_process_stream_t inherit_outsb, inherit_errsb; const atf_process_stream_t *real_outsb, *real_errsb; + atf_process_child_init(c); + real_outsb = NULL; /* Shut up GCC warning. */ err = init_stream_w_default(outsb, &inherit_outsb, &real_outsb); if (atf_is_error(err)) @@ -659,7 +653,7 @@ atf_process_exec_list(atf_process_status_t *s, err = atf_process_exec_array(s, prog, argv2, outsb, errsb, prehook); - free(argv2); out: + free(argv2); return err; } diff --git a/atf-c/detail/sanity_test.c b/atf-c/detail/sanity_test.c index a986c32a..7d4e3905 100644 --- a/atf-c/detail/sanity_test.c +++ b/atf-c/detail/sanity_test.c @@ -85,6 +85,8 @@ do_test_child(void *v) exit(EXIT_SUCCESS); } +#define MAX_LINES 3 + static void do_test(enum type t, bool cond) @@ -92,7 +94,7 @@ do_test(enum type t, bool cond) atf_process_child_t child; atf_process_status_t status; int nlines; - char *lines[3]; + char *lines[MAX_LINES] = { 0 }; { atf_process_stream_t outsb, errsb; @@ -106,16 +108,17 @@ do_test(enum type t, bool cond) } nlines = 0; - while (nlines < 3 && (lines[nlines] = + while (nlines < MAX_LINES && (lines[nlines] = atf_utils_readline(atf_process_child_stderr(&child))) != NULL) nlines++; - ATF_REQUIRE(nlines == 0 || nlines == 3); RE(atf_process_child_wait(&child, &status)); if (!cond) { + ATF_REQUIRE(nlines == MAX_LINES); ATF_REQUIRE(atf_process_status_signaled(&status)); ATF_REQUIRE(atf_process_status_termsig(&status) == SIGABRT); } else { + ATF_REQUIRE(nlines == 0); ATF_REQUIRE(atf_process_status_exited(&status)); ATF_REQUIRE(atf_process_status_exitstatus(&status) == EXIT_SUCCESS); } diff --git a/atf-c/detail/tp_main.c b/atf-c/detail/tp_main.c index 8236d6af..bf124cfb 100644 --- a/atf-c/detail/tp_main.c +++ b/atf-c/detail/tp_main.c @@ -198,8 +198,10 @@ params_fini(struct params *p) atf_map_fini(&p->m_config); atf_fs_path_fini(&p->m_resfile); atf_fs_path_fini(&p->m_srcdir); - if (p->m_tcname != NULL) + if (p->m_tcname != NULL) { free(p->m_tcname); + p->m_tcname = NULL; + } } static @@ -290,17 +292,13 @@ static atf_error_t handle_tcarg(const char *tcarg, char **tcname, enum tc_part *tcpart) { - atf_error_t err; - - err = atf_no_error(); + char *delim; *tcname = strdup(tcarg); - if (*tcname == NULL) { - err = atf_no_memory_error(); - goto out; - } + if (*tcname == NULL) + return atf_no_memory_error(); - char *delim = strchr(*tcname, ':'); + delim = strchr(*tcname, ':'); if (delim != NULL) { *delim = '\0'; @@ -310,13 +308,11 @@ handle_tcarg(const char *tcarg, char **tcname, enum tc_part *tcpart) } else if (strcmp(delim, "cleanup") == 0) { *tcpart = CLEANUP; } else { - err = usage_error("Invalid test case part `%s'", delim); - goto out; + return usage_error("Invalid test case part `%s'", delim); } } -out: - return err; + return atf_no_error(); } static @@ -327,9 +323,7 @@ process_params(int argc, char **argv, struct params *p) int ch; int old_opterr; - err = params_init(p, argv[0]); - if (atf_is_error(err)) - goto out; + err = atf_no_error(); old_opterr = opterr; opterr = 0; @@ -387,10 +381,6 @@ process_params(int argc, char **argv, struct params *p) } } - if (atf_is_error(err)) - params_fini(p); - -out: return err; } @@ -484,12 +474,8 @@ run_tc(const atf_tp_t *tp, struct params *p, int *exitcode) { atf_error_t err; - err = atf_no_error(); - - if (!atf_tp_has_tc(tp, p->m_tcname)) { - err = usage_error("Unknown test case `%s'", p->m_tcname); - goto out; - } + if (!atf_tp_has_tc(tp, p->m_tcname)) + return usage_error("Unknown test case `%s'", p->m_tcname); if (!atf_env_has("__RUNNING_INSIDE_ATF_RUN") || strcmp(atf_env_get( "__RUNNING_INSIDE_ATF_RUN"), "internal-yes-value") != 0) @@ -529,7 +515,6 @@ run_tc(const atf_tp_t *tp, struct params *p, int *exitcode) } INV(!atf_is_error(err)); -out: return err; } @@ -544,10 +529,14 @@ controlled_main(int argc, char **argv, atf_tp_t tp; char **raw_config; - err = process_params(argc, argv, &p); + err = params_init(&p, argv[0]); if (atf_is_error(err)) goto out; + err = process_params(argc, argv, &p); + if (atf_is_error(err)) + goto out_p; + err = handle_srcdir(&p); if (atf_is_error(err)) goto out_p;