Apply badzero.cocci, badnull.cocci and badnull2.cocci

Since badzero.cocci depends on coccinelle knowledge about a variable being a pointer
and about a function returning a pointer, maybe there are false negatives.



SVN revision: 51092
This commit is contained in:
Lucas De Marchi 2010-08-13 17:04:13 +00:00
parent 6d588aa309
commit 9c2a943418
19 changed files with 88 additions and 94 deletions

View File

@ -849,7 +849,7 @@ Epplet_window_destroy(Window newwin)
Epplet_window win;
win = Epplet_window_get_from_Window(newwin);
if (win == NULL)
if (!win)
return;
Epplet_unregister_window(win);
@ -909,13 +909,10 @@ Epplet_window_push_context(Window newwin)
Epplet_window win;
win = Epplet_window_get_from_Window(newwin);
if (win == NULL)
if (!win)
return;
if (((window_stack
=
realloc(window_stack,
sizeof(Epplet_window) * (window_stack_pos + 1))) == NULL))
if ((!(window_stack = realloc(window_stack, sizeof(Epplet_window) * (window_stack_pos + 1)))))
exit(1);
window_stack[window_stack_pos] = win;
window_stack_pos++;
@ -929,10 +926,7 @@ Epplet_window_pop_context(void)
window_stack_pos--;
ret = window_stack[window_stack_pos];
if (((window_stack
=
realloc(window_stack,
sizeof(Epplet_window) * (window_stack_pos))) == NULL))
if ((!(window_stack = realloc(window_stack, sizeof(Epplet_window) * (window_stack_pos)))))
exit(1);
/* Window stack pos == 0 corresponds to the main epplet window */
if (window_stack_pos < 1)
@ -2289,7 +2283,7 @@ Epplet_change_textbox(Epplet_gadget eg, char *new_contents)
if (g->contents == new_contents)
return;
else if (g->contents != NULL)
else if (g->contents)
free(g->contents);
if ((s = strchr(new_contents, '\n')))
@ -2336,7 +2330,7 @@ Epplet_draw_textbox(Epplet_gadget eg)
GC gc;
GADGET_CONFIRM_TYPE(eg, E_TEXTBOX);
if ((g = (GadTextBox *) eg) == NULL)
if (!(g = (GadTextBox *)eg))
return;
if (g->hilited)
@ -2656,7 +2650,7 @@ Epplet_textbox_handle_keyevent(XEvent * ev, Epplet_gadget gadget)
}
else
{
if (g->contents != NULL)
if (g->contents)
{
g->contents =
(char *)realloc(g->contents, (strlen(g->contents) + len + 1));
@ -4294,7 +4288,7 @@ Epplet_event(Epplet_gadget gadget, XEvent * ev)
g = (GadTextBox *) gadget;
if (g->contents == NULL)
if (!g->contents)
break;
XTranslateCoordinates(disp, g->win, root, 0, 0, &tmp_x, &tmp_y,
@ -4681,7 +4675,7 @@ Epplet_background_properties(char vertical, Window newwin)
Epplet_window win;
win = Epplet_window_get_from_Window(newwin);
if (win == NULL)
if (!win)
return;
if (win->bg_pmap)
@ -5746,7 +5740,7 @@ Epplet_load_config_file(const char *file)
memset(config_dict, 0, sizeof(ConfigDict));
config_dict->entries = malloc(sizeof(ConfigItem));
if ((f = fopen(file, "r")) == NULL)
if (!(f = fopen(file, "r")))
return;
for (; fgets(s, sizeof(s), f);)
{

View File

@ -296,7 +296,7 @@ fmtstr(char *value, int ljust, int len, int zpad, int precision)
int padlen, strlen, i, c; /* amount to pad */
zpad = 0;
if (value == NULL)
if (!value)
{
value = "<NULL>";
}
@ -464,7 +464,7 @@ dostr(char *str)
static void
dopr_outch(int c)
{
if (end == NULL || output < end)
if (!end || output < end)
{
*output++ = c;
}

View File

@ -122,7 +122,7 @@ mailcheck_cb(void *data)
{
XBell(Epplet_get_display(), 0);
}
else if (sound != NULL)
else if (sound)
{
Epplet_run_command(sound);
}
@ -469,9 +469,9 @@ main(int argc, char **argv)
argc, argv, 0);
Epplet_load_config();
process_conf();
if (folder_path == NULL)
if (!folder_path)
{
if ((folder_path = getenv("MAIL")) != NULL)
if ((folder_path = getenv("MAIL")))
{
Epplet_modify_config("mailbox", folder_path);
folder_path = Epplet_query_config("mailbox");

View File

@ -80,9 +80,9 @@ timer_cb(void *data)
unsigned long in_blks = 0, out_blks = 0;
static unsigned long last_in = 0, last_out = 0, in_delta = 0, out_delta = 0;
if ((fp = fopen("/proc/diskstats", "r")) == NULL)
if (!(fp = fopen("/proc/diskstats", "r")))
{
if ((fp = fopen("/proc/stat", "r")) == NULL)
if (!(fp = fopen("/proc/stat", "r")))
{
D(("Failed to open /proc/stat -- %s\n", strerror(errno)));
return;

View File

@ -280,7 +280,7 @@ parse_answers(char *path)
unsigned long len;
fp = fopen(path, "r");
if (fp == NULL)
if (!fp)
{
return 0;
}
@ -351,7 +351,7 @@ parse_config(void)
}
s = Epplet_query_config("delay");
if (s != NULL)
if (s)
{
delay = atof(s);
}

View File

@ -77,7 +77,7 @@ timer_cb(void *data)
#else
FILE *fp;
if ((fp = fopen("/proc/meminfo", "r")) == NULL)
if (!(fp = fopen("/proc/meminfo", "r")))
{
D(("Failed to open /proc/meminfo -- %s\n", strerror(errno)));
return;
@ -278,7 +278,7 @@ main(int argc, char **argv)
FILE *fp;
char version[8], buff[1024];
if ((fp = fopen("/proc/version", "r")) == NULL)
if (!(fp = fopen("/proc/version", "r")))
{
D(("Failed to open /proc/version -- %s\nWill assume not 2.6 kernel",
strerror(errno)));

View File

@ -937,7 +937,7 @@ AddMountPoint(char *device, char *path)
type = type->next;
}
if (tail_tile->image == NULL)
if (!tail_tile->image)
{
s = Epplet_query_config("DEFAULT");
@ -1008,7 +1008,7 @@ AddMountPointType(char *key, char *image)
if (types)
{
if ((types->key == NULL) && (types->image == NULL))
if ((!types->key) && (!types->image))
{
if (key)
types->key = strdup(key);
@ -1244,7 +1244,7 @@ ParseFstab(void)
char *info[4];
int i;
if ((f = fopen(FSTAB, "r")) == NULL)
if (!(f = fopen(FSTAB, "r")))
return 0;
*s = 0;
for (; fgets(s, sizeof(s), f);)
@ -1293,7 +1293,7 @@ ParseProcMounts(void)
char *token = NULL, *device = NULL, *path = NULL;
Tile *tile;
if ((f = fopen(PROCMOUNTS, "r")) == NULL)
if (!(f = fopen(PROCMOUNTS, "r")))
return 0;
*s = 0;
for (; fgets(s, sizeof(s), f);)
@ -1349,7 +1349,7 @@ ParseEtcMtab(void)
char *token = NULL, *device = NULL, *path = NULL;
Tile *tile;
if ((f = fopen(ETCMTAB, "r")) == NULL)
if (!(f = fopen(ETCMTAB, "r")))
return 0;
*s = 0;
for (; fgets(s, sizeof(s), f);)
@ -1417,7 +1417,7 @@ VisitMountPoints(void)
if (dir)
{
num_entries = 0;
for (num_entries = 0; (dp = readdir(dir)) != NULL;
for (num_entries = 0; (dp = readdir(dir));
num_entries++);
if (num_entries > 2)
{

View File

@ -246,7 +246,7 @@ cb_close(void *data)
cx = (GLXContext *) data;
Epplet_unremember();
Esync();
if (cx != NULL)
if (cx)
Epplet_unbind_GL(*cx);
exit(0);
}
@ -465,7 +465,7 @@ main(int argc, char **argv)
/* This could also be done as:
* cx = Epplet_bind_double_GL(da, 1, 1, 1, 0, 0, 8, 0, 0, 0, 0, 0); */
if (cx == NULL)
if (!cx)
cb_close(NULL);
/* To properly center the viewport, -2, -2 isntead of 0, 0 must be used.
@ -485,7 +485,7 @@ main(int argc, char **argv)
/* Lets load teh texture */
Esnprintf(buf, sizeof(buf), "%s/cube_texture.RGB", Epplet_data_dir());
if ((textureFile = fopen(buf, "rb")) == NULL)
if (!(textureFile = fopen(buf, "rb")))
{
printf("Failed to load the cube texture file!\n");
}

View File

@ -158,7 +158,7 @@ add_log(char *button_string, char *entry_string)
{
char *tmp;
if (button_string != NULL)
if (button_string)
{
tmp = strdup(button_string);
if (strlen(tmp) > LABEL_CHAR)
@ -172,7 +172,7 @@ add_log(char *button_string, char *entry_string)
Epplet_change_popbutton_label(pb_log_small, tmp);
free(tmp);
}
if (entry_string != NULL)
if (entry_string)
{
Epplet_add_popup_entry(p_log, entry_string, NULL, NULL, NULL);
if (log_entries >= LOG_LEN)

View File

@ -123,7 +123,7 @@ bg_system(char *command)
/* Set reaper so we don't get zombies */
signal(SIGCHLD, (void (*)(int))pinger_reaper);
if (command == NULL || *command == '\0')
if (!command || *command == '\0')
{
return 1;
}
@ -252,7 +252,7 @@ add_log(char *button_string, char *entry_string)
{
char *tmp;
if (button_string != NULL)
if (button_string)
{
tmp = strdup(button_string);
if (strlen(tmp) > LABEL_CHAR)
@ -266,7 +266,7 @@ add_log(char *button_string, char *entry_string)
Epplet_change_popbutton_label(pb_log_small, tmp);
free(tmp);
}
if (entry_string != NULL)
if (entry_string)
{
Epplet_add_popup_entry(p_log, entry_string, NULL, NULL, NULL);
if (log_entries >= LOG_LEN)
@ -294,12 +294,12 @@ set_host(char *new_host)
{
char *c_p, *last_p;
if (new_host == NULL || *new_host == '\0')
if (!new_host || *new_host == '\0')
{
return (0);
}
if (host != NULL)
if (host)
{
free(host);
}
@ -313,7 +313,7 @@ set_host(char *new_host)
}
}
if ((host = strdup(new_host)) == NULL)
if (!(host = strdup(new_host)))
{
perror("set_host: strdup");
return (-1);
@ -332,7 +332,7 @@ set_pause(char *new_pause)
char *c_p;
char *last_p;
if (new_pause == NULL || *new_pause == '\0')
if (!new_pause || *new_pause == '\0')
{
return (0);
}
@ -504,13 +504,13 @@ main(int argc, char **argv)
b_help = Epplet_create_button(NULL, NULL,
82, 2, 0, 0, "HELP", win, NULL, cb_help, NULL);
if ((result = (char *)malloc(BUF_LEN)) == NULL)
if (!(result = (char *)malloc(BUF_LEN)))
{
perror("main: malloc result");
return (-1);
}
*result = '\0';
if ((new_result = (char *)malloc(BUF_LEN)) == NULL)
if (!(new_result = (char *)malloc(BUF_LEN)))
{
perror("main: malloc new_result");
return (-1);

View File

@ -27,7 +27,7 @@ open_pty()
if (-1 == (master = getpt()))
return -1;
if (-1 == grantpt(master) || -1 == unlockpt(master)
|| NULL == (slave = ptsname(master)))
|| !(slave = ptsname(master)))
{
close(master);
return -1;
@ -160,7 +160,7 @@ ftp_recv()
for (p = line; p && *p; p = n)
{
/* split into lines */
if (NULL != (n = strchr(p, '\n')) || NULL != (n = strchr(p, '\r')))
if ((n = strchr(p, '\n')) || (n = strchr(p, '\r')))
*(n++) = 0;
else
n = NULL;
@ -168,18 +168,18 @@ ftp_recv()
fprintf(stderr, "<< %s\n", p);
/* prompt? */
if (NULL != strstr(p, "ftp>"))
if (strstr(p, "ftp>"))
{
done = 1;
}
/* line dropped ? */
if (NULL != strstr(p, "closed connection"))
if (strstr(p, "closed connection"))
{
fprintf(stderr, "ftp: lost connection\n");
ftp_connected = 0;
}
if (NULL != strstr(p, "Not connected"))
if (strstr(p, "Not connected"))
{
if (ftp_connected)
fprintf(stderr, "ftp: lost connection\n");

View File

@ -105,7 +105,7 @@ dirscan(char *dir, unsigned long *num)
return ((char **)NULL);
}
/* count # of entries in dir (worst case) */
for (dirlen = 0; (dp = readdir(dirp)) != NULL; dirlen++);
for (dirlen = 0; (dp = readdir(dirp)); dirlen++);
D((" -> Got %d entries.\n", dirlen));
if (!dirlen)
{
@ -122,7 +122,7 @@ dirscan(char *dir, unsigned long *num)
return ((char **)NULL);
}
rewinddir(dirp);
for (i = 0; (dp = readdir(dirp)) != NULL;)
for (i = 0; (dp = readdir(dirp));)
{
if ((strcmp(dp->d_name, ".")) && (strcmp(dp->d_name, "..")))
{
@ -229,7 +229,7 @@ set_background(int tiled, int keep_aspect)
reply = Epplet_wait_for_ipc();
if (!reply)
return;
if ((ptr = strchr(reply, ':')) != NULL)
if ((ptr = strchr(reply, ':')))
{
current_desk = atoi(++ptr);
}
@ -278,8 +278,8 @@ change_image(void *data)
/* Test-load each image to make sure it's a valid image file. */
for (;
((filenames[idx] == NULL)
|| ((im = imlib_load_image(filenames[idx])) == NULL));)
((!filenames[idx])
|| (!(im = imlib_load_image(filenames[idx]))));)
{
/* It isn't, so NULL out its name. */
filenames[idx] = NULL;
@ -666,7 +666,7 @@ parse_config(void)
char buff[1024], *s;
path = Epplet_query_config("image_dir");
if (path == NULL)
if (!path)
{
Esnprintf(buff, sizeof(buff), "%s/backgrounds", Epplet_e16_user_dir());
path = strdup(buff);
@ -677,7 +677,7 @@ parse_config(void)
path = strdup(path);
}
s = Epplet_query_config("delay");
if (s != NULL)
if (s)
{
delay = atof(s);
}

View File

@ -71,7 +71,7 @@ timer_cb(void *data)
FILE *fp;
if ((fp = fopen("/proc/uptime", "r")) == NULL)
if (!(fp = fopen("/proc/uptime", "r")))
{
D(("Failed to open /proc/uptime -- %s\n", strerror(errno)));
return;

View File

@ -557,7 +557,7 @@ parse_config(void)
char *tmp, buff[1024];
int new_w, new_h;
if (Epplet_query_config("button_0") == NULL)
if (!Epplet_query_config("button_0"))
{
Esnprintf(buff, sizeof(buff), "%s/default.cfg", Epplet_data_dir());
Epplet_load_config_file(buff);

View File

@ -388,7 +388,7 @@ get_url_from_file_list(char *file, int position)
D(("In get_url_from_file_list\n"));
if ((fp = fopen(file, "r")) == NULL)
if (!(fp = fopen(file, "r")))
{
fprintf(stderr, "Unable to open file -->%s<-- for reading\n", file);
return "Error opening url file!";
@ -427,7 +427,7 @@ display_url_from_file(char *url)
{
char *validurl;
if ((validurl = validate_url(url)) == NULL)
if (!(validurl = validate_url(url)))
return;
/* Perform new url command (eg play a sound) */
@ -498,19 +498,19 @@ validate_url(char *url)
/* First, try searching for http://, in case there is a lot of text,
* with an embedded url somewhere inside... */
p = strstr(ret, "http://");
if (p != NULL)
if (p)
ret = p;
else
{
/* Ok. No "http://", maybe a "www." ? */
p = strstr(ret, "http://");
if (p != NULL)
if (p)
ret = p;
}
/* Kill at end of line */
p = strchr(ret, '\n');
if (p != NULL)
if (p)
*p = '\0';
/* Skip first spaces */
@ -521,7 +521,7 @@ validate_url(char *url)
/* Kill at next space */
p = strchr(ret, ' ');
if (p != NULL)
if (p)
*p = '\0';
/* If just www.blah, add the http:// to avoid confusing nutscrape */
@ -551,7 +551,7 @@ save_url(char *url)
{
FILE *fp;
if ((fp = fopen(opt.url_save_file, "a")) != NULL)
if ((fp = fopen(opt.url_save_file, "a")))
{
fprintf(fp, "%s\n", url);
fclose(fp);
@ -663,7 +663,7 @@ handle_url(char *url, char *type)
char *sys = NULL;
int len = 0;
if (url == NULL)
if (!url)
return;
D(("In handle_url: url -->%s<--\n", url));
@ -721,7 +721,7 @@ cb_shoot(void *data)
D(("In cb_shoot: url -->%s<--\n", url));
if ((validurl = validate_url(url)) == NULL)
if (!(validurl = validate_url(url)))
return;
D(("In cb_shoot: valid url -->%s<--\n", validurl));

View File

@ -56,11 +56,11 @@ get_load_average(double *one, double *five, double *fifteen)
kstat_t *ks;
kstat_named_t *d1, *d5, *d15;
if ((kc = kstat_open()) == NULL)
if (!(kc = kstat_open()))
{
SET_AND_RETURN(0, 0, 0);
}
if ((ks = kstat_lookup(kc, "unix", 0, "system_misc")) == NULL)
if (!(ks = kstat_lookup(kc, "unix", 0, "system_misc")))
{
SET_AND_RETURN(0, 0, 0);
}
@ -86,7 +86,7 @@ get_load_average(double *one, double *five, double *fifteen)
char buff[64];
double a, b, c;
if ((fp = fopen("/proc/loadavg", "rt")) == NULL)
if (!(fp = fopen("/proc/loadavg", "rt")))
{
SET_AND_RETURN(0, 0, 0);
}
@ -105,7 +105,7 @@ get_load_average(double *one, double *five, double *fifteen)
char buff[128], *p;
double a, b, c;
if ((pp = popen("uptime", "r")) == NULL)
if (!(pp = popen("uptime", "r")))
{
SET_AND_RETURN(0, 0, 0);
}

View File

@ -173,7 +173,7 @@ read_rfc822_line(FILE * f, char *line, size_t * linelen)
for (; 1;)
{
if (fgets(buf, *linelen - offset, f) == NULL || /* end of file or */
if (!fgets(buf, *linelen - offset, f) || /* end of file or */
(ISSPACE(*line) && !offset))
{ /* end of headers */
*line = 0;
@ -292,7 +292,7 @@ is_from(const char *s, char *path, size_t pathlen)
}
else
{
if ((p = strchr(s, ' ')) == NULL)
if (!(p = strchr(s, ' ')))
return 0;
}
if (path)
@ -393,7 +393,7 @@ parse_mime_header(FILE * fp)
int status = FALSE;
int is_new = FALSE;
if (buffer == NULL)
if (!buffer)
buffer = (char *)malloc(buflen);
while (*(buffer = read_rfc822_line(fp, buffer, &buflen)) != 0)
@ -464,7 +464,7 @@ mbox_folder_count(char *path, int force)
D(("mbox_folder_count(%s, %d) called.\n", NONULL(path), force));
if (path == NULL)
if (!path)
return 0;
if (stat(path, &s) != 0)
@ -497,7 +497,7 @@ mbox_folder_count(char *path, int force)
return 1;
}
}
if ((fp = fopen(path, "r")) == NULL)
if (!(fp = fopen(path, "r")))
{
D((" -> Mailbox cannot be opened for reading.\n"));
return 0;
@ -517,7 +517,7 @@ mbox_folder_count(char *path, int force)
file_size = s.st_size;
parse_mime_header(fp);
while (fgets(buffer, sizeof(buffer), fp) != 0)
while (fgets(buffer, sizeof(buffer), fp))
{
if (is_from(buffer, garbage, sizeof(garbage)))
{
@ -558,7 +558,7 @@ maildir_count_dir(char *dir)
return ULONG_MAX;
}
while ((dent = readdir(dp)) != NULL)
while ((dent = readdir(dp)))
count++;
/* Discard . and .. - maybe we should check each file name as we read them?
@ -583,7 +583,7 @@ maildir_folder_count(char *path, int force)
D(("maildir_folder_count(%s, %d) called.\n", NONULL(path), force));
if (path == NULL)
if (!path)
return 0;
if (stat(path, &s) != 0)

View File

@ -60,7 +60,7 @@ net_get_devices(unsigned long *count)
#ifdef linux
fp = fopen("/proc/net/dev", "r");
if (fp == NULL)
if (!fp)
{
return ((char **)NULL);
}
@ -109,27 +109,27 @@ net_get_bytes_inout(const char *device, double *in_bytes, double *out_bytes)
NULL, dev[64], in_str[64], out_str[64];
#endif
if (device == NULL)
if (!device)
{
return (EFAULT);
}
#ifdef __sun__
kc = kstat_open();
if (kc == NULL)
if (!kc)
{
return (EACCES);
}
ksp = kstat_lookup(kc, 0, -1, device);
if (ksp == NULL)
if (!ksp)
{
return (ENODEV);
}
kstat_read(kc, ksp, &kned);
if (in_bytes != NULL)
if (in_bytes)
{
*in_bytes = (double)kned[0].value.ul;
}
if (out_bytes != NULL)
if (out_bytes)
{
*out_bytes = (double)kned[2].value.ul;
}
@ -137,7 +137,7 @@ net_get_bytes_inout(const char *device, double *in_bytes, double *out_bytes)
return 0;
#elif defined(linux)
fp = fopen("/proc/net/dev", "r");
if (fp == NULL)
if (!fp)
{
return (ENOENT);
}
@ -160,11 +160,11 @@ net_get_bytes_inout(const char *device, double *in_bytes, double *out_bytes)
if (!strcmp(dev, device))
{
match = 1;
if (in_bytes != NULL)
if (in_bytes)
{
*in_bytes = atof(in_str);
}
if (out_bytes != NULL)
if (out_bytes)
{
*out_bytes = atof(out_str);
}
@ -175,11 +175,11 @@ net_get_bytes_inout(const char *device, double *in_bytes, double *out_bytes)
return ((match) ? (0) : (ENODEV));
#else
/* Unsupported platform. */
if (in_bytes != NULL)
if (in_bytes)
{
*in_bytes = -1.0;
}
if (out_bytes != NULL)
if (out_bytes)
{
*out_bytes = -1.0;
}

View File

@ -30,7 +30,7 @@ _Strjoin(const char *separator, ...)
int len;
int separator_len;
if (separator == NULL)
if (!separator)
separator = "";
separator_len = strlen(separator);