Page MenuHomeFreeBSD

Remove unneeded NULL check in amd64's trap_fatal()
ClosedPublic

Authored by dim on May 31 2015, 4:39 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Nov 28, 10:49 AM
Unknown Object (File)
Nov 1 2024, 1:49 PM
Unknown Object (File)
Oct 4 2024, 4:43 PM
Unknown Object (File)
Oct 2 2024, 7:58 AM
Unknown Object (File)
Oct 2 2024, 5:00 AM
Unknown Object (File)
Sep 28 2024, 2:31 AM
Unknown Object (File)
Sep 19 2024, 4:52 AM
Unknown Object (File)
Sep 17 2024, 7:16 PM
Subscribers

Details

Summary

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

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
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.