Remove unneeded code with notnull.cocci script

The notnull.cocci script from Coccinelle finds places where you check if a
variable is NULL, but it's known not to be NULL. The check can be safely
removed. For example, this code would be caught by notnull:

if (!var) return;
if (var && var->fld) { ... }

It's needless to check again if var is not NULL because if it's in fact NULL,
it would have returned on the previous "if". This commit removes all the
trivial places where this pattern happens. Another patch will be generated for
the more complex cases.


SVN revision: 50241
This commit is contained in:
Lucas De Marchi 2010-07-14 02:05:47 +00:00
parent cdaa13122d
commit b2a826a680
3 changed files with 9 additions and 18 deletions

View File

@ -676,8 +676,7 @@ __imlib_TrimLoaderList(char **list, int *num)
if (list[i])
free(list[i]);
}
if (list)
free(list);
free(list);
*num = size;
return ret;
}

View File

@ -279,8 +279,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
if (!progress(im, per, 0, pl, im->w, l))
{
if (idata)
free(idata);
free(idata);
fclose(f);
return 2;
}
@ -372,8 +371,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
if (!progress(im, per, 0, pl, im->w, l))
{
if (idata)
free(idata);
free(idata);
fclose(f);
return 2;
}
@ -465,8 +463,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
if (!progress(im, per, 0, pl, im->w, l))
{
if (data)
free(data);
free(data);
fclose(f);
return 2;
}
@ -533,8 +530,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
if (!progress(im, per, 0, pl, im->w, l))
{
if (data)
free(data);
free(data);
fclose(f);
return 2;
}
@ -591,8 +587,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
if (!progress(im, per, 0, pl, im->w, l))
{
if (data)
free(data);
free(data);
fclose(f);
return 2;
}
@ -660,8 +655,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
if (!progress(im, per, 0, pl, im->w, l))
{
if (data)
free(data);
free(data);
fclose(f);
return 2;
}

View File

@ -156,8 +156,7 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
l = y - pl;
if (!progress(im, per, 0, (y - l), im->w, l))
{
if (buf)
free(buf);
free(buf);
fclose(f);
return 2;
}
@ -173,8 +172,7 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
/* write the image data */
fwrite(buf, 1, im->w * im->h * ((im->flags & F_HAS_ALPHA) ? 4 : 3), f);
if (buf)
free(buf);
free(buf);
fclose(f);
return 1;
}