Page MenuHomeFreeBSD

Remove unneeded NULL check in amd64's trap_fatal()

Authored by dim on May 31 2015, 4:39 PM.



Clang 3.7.0 (trunk) gives this warning about amd64's trap_fatal():

sys/amd64/amd64/trap.c:846:42: error: address of array '(__curthread())->td_name' will always evaluate to 'true' [-Werror,-Wpointer-bool-conversion]
                    (u_long)curproc->p_pid, curthread->td_name ?
                                            ~~~~~~~~~~~^~~~~~~ ~

Since td_name is an array member of struct thread, it can never be NULL,
so the check can be removed.

Note that I'm assuming curthread itself will never be NULL at this
point. If that is a possibility, the check could be changed into:

curthread ? curthread->td_name : ""

or something similar.

Test Plan

Build, boot, and possibly trigger a trap_fatal() on purpose.

Diff Detail

rS FreeBSD src repository - subversion
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

dim retitled this revision from to Remove unneeded NULL check in amd64's trap_fatal().
dim updated this object.
dim edited the test plan for this revision. (Show Details)
dim added reviewers: kib, emaste.

This looks fine.

While you are changing the printf(), you may as well remove the cast of p_pid to u_long, and 'l' format modifier. The pid_t is int32_t on all arches, and amd64 definitely does not need the cast.

Also, I do not believe that we can get curproc == NULL.

dim edited edge metadata.

Ah yes, curproc is defined as:

#define curproc         (curthread->td_proc)

so I removed the if statement, and folded the two printf() calls together.

kib edited edge metadata.
This revision is now accepted and ready to land.Jun 1 2015, 6:38 AM
This revision was automatically updated to reflect the committed changes.