Skip to content

Commit

Permalink
11407 powertop: NULL pointer errors
Browse files Browse the repository at this point in the history
Reviewed by: Andy Fiddaman <andy@omniosce.org>
Approved by: Dan McDonald <danmcd@joyent.com>
  • Loading branch information
tsoome committed Jul 26, 2019
1 parent e9610e3 commit f795e60
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
30 changes: 15 additions & 15 deletions usr/src/cmd/powertop/common/events.c
Expand Up @@ -49,15 +49,15 @@ static event_info_t *event;
static int
pt_events_walk(const dtrace_aggdata_t *data, void *arg)
{
dtrace_aggdesc_t *aggdesc = data->dtada_desc;
dtrace_recdesc_t *rec1, *rec2, *rec3;
dtrace_syminfo_t dts;
GElf_Sym sym;
dtrace_aggdesc_t *aggdesc = data->dtada_desc;
dtrace_recdesc_t *rec1, *rec2, *rec3;
dtrace_syminfo_t dts;
GElf_Sym sym;
uint64_t offender_addr;
uint64_t n = 0;
int32_t *instance, *offender_cpu;
int i;
char *offense_name;
uint64_t n = 0;
int32_t *instance, *offender_cpu;
int i;
char *offense_name;

if (g_top_events >= EVENT_NUM_MAX)
return (0);
Expand Down Expand Up @@ -107,7 +107,7 @@ pt_events_walk(const dtrace_aggdata_t *data, void *arg)
* We have the address of the kernel callout.
* Try to resolve it into a meaningful symbol
*/
if (offender_addr != NULL && dtrace_lookup_by_addr(dtp,
if (offender_addr != 0 && dtrace_lookup_by_addr(dtp,
offender_addr, &sym, &dts) == 0) {
(void) snprintf((char *)(event->offense_name),
EVENT_NAME_MAX, "%s`%s", dts.dts_object,
Expand Down Expand Up @@ -151,7 +151,7 @@ pt_events_walk(const dtrace_aggdata_t *data, void *arg)
/*
* Try to resolve the address of the cross call function.
*/
if (offender_addr != NULL && dtrace_lookup_by_addr(dtp,
if (offender_addr != 0 && dtrace_lookup_by_addr(dtp,
offender_addr, &sym, &dts) == 0) {
(void) snprintf((char *)(event->offense_name),
EVENT_NAME_MAX, "<xcalls> %s`%s",
Expand Down Expand Up @@ -190,7 +190,7 @@ pt_events_walk(const dtrace_aggdata_t *data, void *arg)
/*
* Try to resolve the address of the cross call function.
*/
if (offender_addr != NULL && dtrace_lookup_by_addr(dtp,
if (offender_addr != 0 && dtrace_lookup_by_addr(dtp,
offender_addr, &sym, &dts) == 0) {
(void) snprintf((char *)(event->offense_name),
EVENT_NAME_MAX, "<xcalls> %s`%s (CPU %d)",
Expand Down Expand Up @@ -226,10 +226,10 @@ pt_events_walk(const dtrace_aggdata_t *data, void *arg)
int
pt_events_stat_prepare(void)
{
dtrace_prog_t *prog;
dtrace_proginfo_t info;
dtrace_optval_t statustime;
int err;
dtrace_prog_t *prog;
dtrace_proginfo_t info;
dtrace_optval_t statustime;
int err;
char *prog_ptr;

event = g_event_info;
Expand Down
12 changes: 6 additions & 6 deletions usr/src/cmd/powertop/common/powertop.c
Expand Up @@ -52,13 +52,13 @@
* These are ordered by type, grouped by usage.
*/
int g_bit_depth;
int g_total_events, g_top_events;
int g_total_events, g_top_events;
int g_npstates, g_max_cstate, g_longest_cstate;
uint_t g_features;
uint_t g_ncpus;
uint_t g_ncpus_observed;

processorid_t *g_cpu_table;
processorid_t *g_cpu_table;

double g_interval_length;
hrtime_t g_total_c_time;
Expand All @@ -67,7 +67,7 @@ uchar_t g_op_mode;
boolean_t g_gui;
uint_t g_observed_cpu;

event_info_t g_event_info[EVENT_NUM_MAX];
event_info_t g_event_info[EVENT_NUM_MAX];
state_info_t g_cstate_info[NSTATES];
freq_state_info_t g_pstate_info[NSTATES];
cpu_power_info_t *g_cpu_power_states;
Expand All @@ -94,7 +94,7 @@ int
main(int argc, char **argv)
{
double interval, interval_usr;
hrtime_t interval_start;
hrtime_t interval_start;
int index2 = 0, c, dump_count = 0;
char *endptr, key;
boolean_t root_user = B_FALSE;
Expand Down Expand Up @@ -147,7 +147,7 @@ main(int argc, char **argv)
g_gui = B_FALSE;
dump_count = (int)strtod(optarg, &endptr);

if (dump_count <= 0 || *endptr != NULL) {
if (dump_count <= 0 || *endptr != '\0') {
pt_usage();
exit(EXIT_USAGE);
}
Expand All @@ -163,7 +163,7 @@ main(int argc, char **argv)
interval = interval_usr = (double)strtod(optarg,
&endptr);

if (*endptr != NULL || interval < 1 ||
if (*endptr != '\0' || interval < 1 ||
interval > INTERVAL_MAX) {
pt_usage();
exit(EXIT_USAGE);
Expand Down
2 changes: 1 addition & 1 deletion usr/src/cmd/powertop/common/suggestions.c
Expand Up @@ -268,6 +268,6 @@ void
pt_sugg_as_root(void)
{
pt_sugg_add("Suggestion: run as root to get suggestions"
" for reducing system power consumption", 40, NULL, NULL,
" for reducing system power consumption", 40, 0, NULL,
NULL);
}

0 comments on commit f795e60

Please sign in to comment.