Skip to content

Commit

Permalink
engines: separate declaration and assignment
Browse files Browse the repository at this point in the history
Separate the declaraction and assignment for some variables.

This is a prep patch for a Coccinelle script that converts
mallloc+memset(,0,) to calloc.

Part of this patch was created using the Coccinelle script below.

@@
identifier x;
expression y;
statement s;
type T;
@@

-T x = malloc(y);
+T x;
+x = malloc(y);
(
if (!x) s
|
if (x == NULL) s
|
)
memset(x, 0, y);

Signed-off-by: Vincent Fu <[email protected]>
  • Loading branch information
vincentkfu committed Apr 20, 2023
1 parent a7b7cb5 commit a93259c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion engines/null.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ static void null_cleanup(struct null_data *nd)

static struct null_data *null_init(struct thread_data *td)
{
struct null_data *nd = malloc(sizeof(*nd));
struct null_data *nd;
nd = malloc(sizeof(*nd));

memset(nd, 0, sizeof(*nd));

Expand Down
3 changes: 2 additions & 1 deletion engines/posixaio.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ static void fio_posixaio_cleanup(struct thread_data *td)

static int fio_posixaio_init(struct thread_data *td)
{
struct posixaio_data *pd = malloc(sizeof(*pd));
struct posixaio_data *pd;
pd = malloc(sizeof(*pd));

memset(pd, 0, sizeof(*pd));
pd->aio_events = malloc(td->o.iodepth * sizeof(struct io_u *));
Expand Down
3 changes: 2 additions & 1 deletion engines/solarisaio.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ static void fio_solarisaio_init_sigio(void)
static int fio_solarisaio_init(struct thread_data *td)
{
unsigned int max_depth;
struct solarisaio_data *sd = malloc(sizeof(*sd));
struct solarisaio_data *sd;
sd = malloc(sizeof(*sd));
memset(sd, 0, sizeof(*sd));

max_depth = td->o.iodepth;
Expand Down

0 comments on commit a93259c

Please sign in to comment.