Project

General

Profile

Bug #6139

help gcc figure out variable initialization

Added by Josef Sipek about 5 years ago.

Status:
New
Priority:
Low
Assignee:
Category:
cmd - userland programs
Start date:
2015-08-18
Due date:
% Done:

80%

Estimated time:
Difficulty:
Medium
Tags:
needs-triage
Gerrit CR:

Description

Changing the i386_XARCH variable to -xarch=pentium_pro causes gcc warn about a couple of files. This bug is not about the xarch change, I'm simply documenting how I got gcc to to produce these warnings.

usr/src/lib/auditd_plugins/binfile/binfile.c:

The beginning of loadauditlist() checks that the argument minfreestr is not NULL. If it is NULL, the function returns an error. After the check for NULL, the minfreestr variable is not changed until the check for NULL on line 352. Therefore, this check is redundant and can be removed.

usr/src/common/iscsit/iscsit_common.c:

portalArray is initialized to NULL. At the end of the if statement ending on line 828, portalArray will be non-NULL since memory is allocated on line 808 and if the allocation failed the function returns on line 813. Therefore, the condition on line 830 can only be true if the condition on line 806 is true. Therefore the condition can be simplified and moved inside the previous if statement. The condition on line 836 is true if and only if the condition on line 806 was true, and therefore it can be eliminated and the contents of the if-statement can be moved into the if statement starting on line 806.

usr/src/cmd/modload/plcysubr.c:

gcc doesn't manage to figure out that min will be initialized whenever delrange is true and therefore the two uses of it will be fine. A slight reordering of code results in min always being initialized.

usr/src/lib/libhotplug/common/libhotplug.c:

The check on line 451 ensures that node is non-NULL. Therefore the for loop on line 466 will iterate at least once. gcc doesn't seem to detect that between that and the fact that eventually the loop will terminate which will lead to root getting set in the last iteration. Therefore, after the loop, root will always be initialized. A slight reorganization makes gcc understand that root will always be initialized to some value after the loop.

Also available in: Atom PDF