src/swapon.c: initiate p to NULL
authorSun Ke <sunke32@huawei.com>
Mon, 1 Feb 2021 07:57:05 +0000 (15:57 +0800)
committerEryu Guan <guaneryu@gmail.com>
Sun, 7 Feb 2021 14:44:23 +0000 (22:44 +0800)
commitf961a4b9fe8762731749addbe471773ef2e4f6e5
tree2b5dea4360ab662d43134d434ebdf6a60c611171
parent8e3d3c5815da4d178eea4fb8c59217a81c94a2c4
src/swapon.c: initiate p to NULL

when run make, show:
swapon.c:135:3: warning: 'p' may be used uninitialized in this function
[-Wmaybe-uninitialized]
   memcpy(p, buf, BUF_SIZE);
      ^~~~~~~~~~~~~~~~~~~~~~~~

This's a fake uninitialized warning.
gcc think the 'p' can be used uninitialized at here when verb is
TEST_MWRITE_BEFORE_AND_MWRITE_AFTER:
    case TEST_MWRITE_BEFORE_AND_MWRITE_AFTER:
memcpy(p, buf, BUF_SIZE);
break;

But, if verb is TEST_MWRITE_BEFORE_AND_MWRITE_AFTER, the 'p' will be
initialized by:
    switch (verb) {
    case TEST_MWRITE_BEFORE_AND_MWRITE_AFTER:
    case TEST_MWRITE_BEFORE:
p = mmap(NULL, BUF_SIZE, PROT_WRITE | PROT_READ, MAP_SHARED,

Silent the warning by initializing p to NULL anyway.

Signed-off-by: Sun Ke <sunke32@huawei.com>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
src/swapon.c