aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeandro Pereira <leandro@hardinfo.org>2010-08-15 18:36:25 -0300
committerLeandro Pereira <leandro@hardinfo.org>2010-08-15 18:36:25 -0300
commit9fda18663f31e67d8c1c50e1c5a1888abceda2a6 (patch)
treea680bd9c701eaec1016d6beb28bf2c79cfc538e0
parent9fe6a457e1d9d01f6645d91805691afd429d0a2c (diff)
Fix potential problems found by clang static analyzer.
-rw-r--r--help-viewer/help-viewer.c3
-rw-r--r--modules/benchmark.c4
-rw-r--r--modules/devices/battery.c5
-rw-r--r--modules/devices/inputdevices.c8
-rw-r--r--modules/devices/spd-decode.c5
-rw-r--r--modules/devices/storage.c12
-rw-r--r--modules/devices/usb.c12
-rw-r--r--modules/devices/x86/processor.c2
-rw-r--r--modules/network/net.c8
-rw-r--r--remote/remote.c2
-rw-r--r--remote/ssh-conn.c4
11 files changed, 34 insertions, 31 deletions
diff --git a/help-viewer/help-viewer.c b/help-viewer/help-viewer.c
index ace6ef37..76f9e3d9 100644
--- a/help-viewer/help-viewer.c
+++ b/help-viewer/help-viewer.c
@@ -341,7 +341,6 @@ help_viewer_new (const gchar *help_dir, const gchar *help_file)
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *toolbar1;
- GtkIconSize tmp_toolbar_icon_size;
GtkWidget *btn_back;
GtkWidget *btn_forward;
GtkWidget *separatortoolitem1;
@@ -384,7 +383,6 @@ help_viewer_new (const gchar *help_dir, const gchar *help_file)
gtk_widget_show (toolbar1);
gtk_box_pack_start (GTK_BOX (hbox), toolbar1, TRUE, TRUE, 0);
gtk_toolbar_set_style (GTK_TOOLBAR (toolbar1), GTK_TOOLBAR_BOTH_HORIZ);
- tmp_toolbar_icon_size = gtk_toolbar_get_icon_size (GTK_TOOLBAR (toolbar1));
btn_back = (GtkWidget*) gtk_tool_button_new_from_stock ("gtk-go-back");
gtk_widget_show (btn_back);
@@ -410,7 +408,6 @@ help_viewer_new (const gchar *help_dir, const gchar *help_file)
gtk_box_pack_end (GTK_BOX (hbox), toolbar2, FALSE, TRUE, 0);
gtk_toolbar_set_style (GTK_TOOLBAR (toolbar2), GTK_TOOLBAR_BOTH_HORIZ);
gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar2), FALSE);
- tmp_toolbar_icon_size = gtk_toolbar_get_icon_size (GTK_TOOLBAR (toolbar2));
toolitem3 = (GtkWidget*) gtk_tool_item_new ();
gtk_widget_show (toolitem3);
diff --git a/modules/benchmark.c b/modules/benchmark.c
index f08c9c6f..23eee038 100644
--- a/modules/benchmark.c
+++ b/modules/benchmark.c
@@ -71,7 +71,7 @@ gpointer benchmark_parallel_for_dispatcher(gpointer data)
{
ParallelBenchTask *pbt = (ParallelBenchTask *)data;
gpointer (*callback)(unsigned int start, unsigned int end, void *data, gint thread_number);
- gpointer return_value;
+ gpointer return_value = NULL;
if ((callback = pbt->callback)) {
DEBUG("this is thread %p; items %d -> %d, data %p", g_thread_self(),
@@ -101,7 +101,7 @@ gdouble benchmark_parallel_for(guint start, guint end,
n_cores = temp ? atoi(temp) : 1;
g_free(temp);
- while (1) {
+ while (n_cores > 0) {
iter_per_core = (end - start) / n_cores;
if (iter_per_core == 0) {
diff --git a/modules/devices/battery.c b/modules/devices/battery.c
index 37416dbb..09c84eeb 100644
--- a/modules/devices/battery.c
+++ b/modules/devices/battery.c
@@ -174,7 +174,10 @@ __scan_battery_acpi(void)
}
if (g_str_equal(present, "yes")) {
- charge_rate = atof(remaining) / atof(capacity);
+ if (remaining && capacity)
+ charge_rate = atof(remaining) / atof(capacity);
+ else
+ charge_rate = 0;
battery_list = h_strdup_cprintf("\n[Battery: %s]\n"
"State=%s (load: %s)\n"
diff --git a/modules/devices/inputdevices.c b/modules/devices/inputdevices.c
index c280e218..31f51fbb 100644
--- a/modules/devices/inputdevices.c
+++ b/modules/devices/inputdevices.c
@@ -46,7 +46,7 @@ __scan_input_devices(void)
FILE *dev;
gchar buffer[128];
gchar *tmp, *name = NULL, *phys = NULL;
- gint bus, vendor, product, version;
+ gint bus = 0, vendor, product, version;
int d = 0, n = 0;
dev = fopen("/proc/bus/input/devices", "r");
@@ -87,7 +87,7 @@ __scan_input_devices(void)
d = 4; //INPUT_UNKNOWN;
break;
case '\n':
- if (strstr(name, "PC Speaker")) {
+ if (name && strstr(name, "PC Speaker")) {
d = 3; // INPUT_PCSPKR
}
@@ -123,12 +123,12 @@ __scan_input_devices(void)
"Version=0x%x\n",
strhash, product, version);
- if (phys[1] != 0) {
+ if (phys && phys[1] != 0) {
strhash = h_strdup_cprintf("Connected to=%s\n",
strhash, phys);
}
- if (strstr(phys,"ir")) {
+ if (phys && strstr(phys, "ir")) {
strhash = h_strdup_cprintf("InfraRed port=yes\n",
strhash);
}
diff --git a/modules/devices/spd-decode.c b/modules/devices/spd-decode.c
index 2a72725b..bb22c1b7 100644
--- a/modules/devices/spd-decode.c
+++ b/modules/devices/spd-decode.c
@@ -633,7 +633,7 @@ static int parity(int value)
static void decode_sdr_module_size(unsigned char *bytes, int *size)
{
- int i, k;
+ int i, k = 0;
i = (bytes[3] & 0x0f) + (bytes[4] & 0x0f) - 17;
if (bytes[5] <= 8 && bytes[17] <= 8) {
@@ -1154,7 +1154,7 @@ static void decode_module_manufacturer(unsigned char *bytes,
do {
ai++;
- } while ((--len && (first = *bytes++ == 0x7f)));
+ } while ((--len && (*bytes++ == 0x7f)));
first = *--bytes;
if (ai == 0) {
@@ -1288,6 +1288,7 @@ static gchar *decode_dimms(GSList *dimm_list, gboolean use_sysfs)
break;
default:
DEBUG("Unsupported EEPROM type: %s\n", ram_types[ram_type]);
+ continue;
}
read_spd(spd_path, 64, 64, use_sysfs, bytes);
diff --git a/modules/devices/storage.c b/modules/devices/storage.c
index 23ab1de2..a9dfd665 100644
--- a/modules/devices/storage.c
+++ b/modules/devices/storage.c
@@ -36,10 +36,10 @@ __scan_scsi_devices(void)
FILE *proc_scsi;
gchar buffer[256], *buf;
gint n = 0;
- gint scsi_controller;
- gint scsi_channel;
- gint scsi_id;
- gint scsi_lun;
+ gint scsi_controller = 0;
+ gint scsi_channel = 0;
+ gint scsi_id = 0 ;
+ gint scsi_lun = 0;
gchar *vendor = NULL, *revision = NULL, *model = NULL;
gchar *scsi_storage_list;
@@ -96,7 +96,7 @@ __scan_scsi_devices(void)
};
int i;
- if (strstr(model, "Flash Disk")) {
+ if (model && strstr(model, "Flash Disk")) {
type = "Flash Disk";
icon = "usbfldisk";
} else {
@@ -146,6 +146,8 @@ __scan_scsi_devices(void)
g_free(model);
g_free(revision);
g_free(vendor);
+
+ scsi_controller = scsi_channel = scsi_id = scsi_lun = 0;
}
}
fclose(proc_scsi);
diff --git a/modules/devices/usb.c b/modules/devices/usb.c
index 39914dd0..f58476eb 100644
--- a/modules/devices/usb.c
+++ b/modules/devices/usb.c
@@ -138,7 +138,7 @@ gboolean __scan_usb_procfs(void)
FILE *dev;
gchar buffer[128];
gchar *tmp, *manuf = NULL, *product = NULL, *mxpwr;
- gint bus, level, port, classid, trash;
+ gint bus, level, port = 0, classid = 0, trash;
gint vendor, prodid;
gfloat ver, rev, speed;
int n = 0;
@@ -183,7 +183,7 @@ gboolean __scan_usb_procfs(void)
tmp = g_strdup_printf("USB%d", ++n);
- if (*product == '\0') {
+ if (product && *product == '\0') {
g_free(product);
if (classid == 9) {
product = g_strdup_printf("USB %.2f Hub", ver);
@@ -195,7 +195,6 @@ gboolean __scan_usb_procfs(void)
}
}
-
if (classid == 9) { /* hub */
usb_list = h_strdup_cprintf("[%s#%d]\n",
usb_list, product, n);
@@ -241,6 +240,7 @@ gboolean __scan_usb_procfs(void)
g_free(product);
manuf = g_strdup("");
product = g_strdup("");
+ port = classid = 0;
}
}
@@ -252,7 +252,7 @@ gboolean __scan_usb_procfs(void)
void __scan_usb_lsusb_add_device(char *buffer, FILE *lsusb, int usb_device_number)
{
gint bus, device, vendor_id, product_id;
- gchar *product, *vendor, *max_power, *tmp, *strhash;
+ gchar *product = NULL, *vendor = NULL, *max_power, *tmp, *strhash;
sscanf(buffer, "Bus %d Device %d: ID %x:%x",
&bus, &device, &vendor_id, &product_id);
@@ -271,7 +271,7 @@ void __scan_usb_lsusb_add_device(char *buffer, FILE *lsusb, int usb_device_numbe
}
tmp = g_strdup_printf("USB%d", usb_device_number);
- usb_list = h_strdup_cprintf("$%s$%s=\n", usb_list, tmp, product);
+ usb_list = h_strdup_cprintf("$%s$%s=\n", usb_list, tmp, product ? product : "Unknown");
strhash = g_strdup_printf("[Device Information]\n"
"Product=%s\n"
@@ -284,7 +284,7 @@ void __scan_usb_lsusb_add_device(char *buffer, FILE *lsusb, int usb_device_numbe
"Product ID=0x%x\n"
"Bus=%d\n",
product,
- vendor,
+ vendor ? vendor : "Unknown",
max_power,
0.0f /* FIXME */,
0 /* FIXME */,
diff --git a/modules/devices/x86/processor.c b/modules/devices/x86/processor.c
index 0aa385ae..e70d1374 100644
--- a/modules/devices/x86/processor.c
+++ b/modules/devices/x86/processor.c
@@ -239,7 +239,7 @@ GSList *processor_scan(void)
__cache_obtain_info(processor, processor_number++);
}
- if (tmp[0] && tmp[1]) {
+ if (processor && tmp[0] && tmp[1]) {
tmp[0] = g_strstrip(tmp[0]);
tmp[1] = g_strstrip(tmp[1]);
diff --git a/modules/network/net.c b/modules/network/net.c
index c0432522..65282b4a 100644
--- a/modules/network/net.c
+++ b/modules/network/net.c
@@ -121,21 +121,21 @@ void get_wireless_info(int fd, NetInfo *netinfo)
wi_req.u.essid.length = IW_ESSID_MAX_SIZE + 1;
wi_req.u.essid.flags = 0;
- if ((r = ioctl(fd, SIOCGIWESSID, &wi_req) < 0)) {
+ if (ioctl(fd, SIOCGIWESSID, &wi_req) < 0) {
strcpy(netinfo->wi_essid, "");
} else {
netinfo->wi_essid[wi_req.u.essid.length] = '\0';
}
/* obtain bit rate */
- if ((r = ioctl(fd, SIOCGIWRATE, &wi_req) < 0)) {
+ if (ioctl(fd, SIOCGIWRATE, &wi_req) < 0) {
netinfo->wi_rate = 0;
} else {
netinfo->wi_rate = wi_req.u.bitrate.value;
}
/* obtain operation mode */
- if ((r = ioctl(fd, SIOCGIWMODE, &wi_req) < 0)) {
+ if (ioctl(fd, SIOCGIWMODE, &wi_req) < 0) {
netinfo->wi_mode = 0;
} else {
if (wi_req.u.mode >= 0 && wi_req.u.mode < 6) {
@@ -147,7 +147,7 @@ void get_wireless_info(int fd, NetInfo *netinfo)
#if WIRELESS_EXT >= 10
/* obtain txpower */
- if ((r = ioctl(fd, SIOCGIWTXPOW, &wi_req) < 0)) {
+ if (ioctl(fd, SIOCGIWTXPOW, &wi_req) < 0) {
netinfo->wi_has_txpower = FALSE;
} else {
netinfo->wi_has_txpower = TRUE;
diff --git a/remote/remote.c b/remote/remote.c
index d266735d..f2d0f9c2 100644
--- a/remote/remote.c
+++ b/remote/remote.c
@@ -898,7 +898,7 @@ static HostDialog *host_dialog_new(GtkWidget * parent,
if (mode == HOST_DIALOG_MODE_EDIT) {
btn_save = gtk_button_new_from_stock(GTK_STOCK_SAVE);
- } else if (mode == HOST_DIALOG_MODE_CONNECT) {
+ } else {
btn_save = gtk_button_new_from_stock(GTK_STOCK_CONNECT);
}
diff --git a/remote/ssh-conn.c b/remote/ssh-conn.c
index 7f099d35..af8a6fab 100644
--- a/remote/ssh-conn.c
+++ b/remote/ssh-conn.c
@@ -149,7 +149,7 @@ SSHConnResponse ssh_new(SoupURI * uri,
char **argv, *askpass_path = NULL;
GString *cmd_line;
SSHConnResponse response;
- SSHConn *connection;
+ SSHConn *connection = NULL;
gchar buffer[512];
if (!conn_return) {
@@ -282,7 +282,7 @@ SSHConnResponse ssh_new(SoupURI * uri,
}
if (response != SSH_CONN_OK) {
- if (connection->uri) {
+ if (connection && connection->uri) {
soup_uri_free(connection->uri);
}