Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

t/op/taint.t: Avert uninitialized value warning #18116

Merged
merged 2 commits into from Sep 16, 2020

Conversation

jkeenan
Copy link
Contributor

@jkeenan jkeenan commented Sep 8, 2020

In the test of shmread, if $id is undefined after the attempted
assignment by shmget(), we get the "# shmget failed" warning and, since
nothing has been read into $rcvd, that variable remains undefined. If
$rcvd is undefined it will never be string-equal to $sent, which
means the 'skip' condition will be exercised.

Commit 5624951 made this file run with warnings enabled, so now the
lack of assignment to $rcvd generates an uninitialized value warning
(observed in smoke-test reports on FreeBSD). This patch accounts for
non-definition of $rcvd and prevents that warning from being emitted.

In the test of shmread, if $id is undefined after the attempted
assignment by shmget(), we get the "# shmget failed" warning and, since
nothing has been read into $rcvd, that variable remains undefined.  If
$rcvd is undefined it will never be string-equal to $sent, which
means the 'skip' condition will be exercised.

Commit 5624951 made this file run with warnings enabled, so now the
lack of assignment to $rcvd generates an uninitialized value warning
(observed in smoke-test reports on FreeBSD).  This patch accounts for
non-definition of $rcvd and prevents that warning from being emitted.
@jkeenan jkeenan requested a review from atoomic September 8, 2020 01:10
@Leont
Copy link
Contributor

Leont commented Sep 8, 2020

Isn't it easier to default $rcvd to an empty string?

t/op/taint.t Outdated
@@ -1565,7 +1565,7 @@ SKIP: {
}

skip "SysV shared memory operation failed", 1 unless
$rcvd eq $sent;
($rcvd // '') eq $sent;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is correct, better read IMO like unless defined $rcvd && $rcvd eq $sent
setting $rcvd to an empty string will solve some issues but not all and is not a good solution

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is correct, better read IMO like unless defined $rcvd && $rcvd eq $sent
setting $rcvd to an empty string will solve some issues but not all and is not a good solution

Updated.

@atoomic
Copy link
Member

atoomic commented Sep 14, 2020

as $rcvd can be updated by reference after init, I would avoid initializing it to an empty string

@atoomic atoomic merged commit 6ef4979 into blead Sep 16, 2020
@rjbs rjbs deleted the jkeenan/taint-rcvd-uninit-20200907 branch May 8, 2021 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants