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)
Wed, Feb 28, 8:38 PM
Unknown Object (File)
Wed, Feb 28, 8:38 PM
Unknown Object (File)
Feb 23 2024, 6:14 AM
Unknown Object (File)
Feb 1 2024, 6:41 AM
Unknown Object (File)
Feb 1 2024, 2:18 AM
Unknown Object (File)
Dec 20 2023, 12:26 AM
Unknown Object (File)
Dec 7 2023, 11:28 AM
Unknown Object (File)
Nov 15 2023, 10:59 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.