In Amanda, I have stumbled upon this function:

----
int
search_fstab(
     char *             name,
     generic_fsent_t *  fsent,
     int                check_dev)
{
#ifdef IGNORE_FSTAB
  /* There is no real mount table so this will always fail and
 *    * we are using GNU tar so we can just return here.
 *       */
  (void)name;           /* Quiet unused parameter warning */
  (void)fsent;          /* Quiet unused parameter warning */
  (void)check_dev;      /* Quiet unused parameter warning */
  return 0;
#else
/*
 * Things, but of no importance to the matter at hand
 */
#endif /* !IGNORE_FSTAB */
}
----

I have reduced the file to this:

----
int
search_fstab(char *name, generic_fsent_t *fsent, int check_dev)
{
  (void)name;           /* Quiet unused parameter warning */
  (void)fsent;          /* Quiet unused parameter warning */
  (void)check_dev;      /* Quiet unused parameter warning */
  return 0;
}
----

and tried this patch, with the intent to find and report such
di{rty,sgusting} hacks - not to mention that this same "(void)" hack
is even embedded in some macros:

----
@r@
identifier f, dummy;
type t;
position p1, p2;
@@

f(...,
t dummy@p1)
{
...
  (void) dummy@p2;
...
}

@script:python@
p1 << r.p1;
p2 << r.p2;
@@

print "UGLY HACK: see %s and %s, file %s, this should just go away" %
(p1[0].line, p2[0].line, p1[0].file)
----

But... No match. I know my SmPL file is incorrect. For instance, in
its current form, t defines a type and not a pointer to a type. How do
I abstract that away?

Out of desperation, in order to have a match, I reduced the C sample to that:

---
int
search_fstab(int check_dev)
{
  (void) check_dev;     /* Quiet unused parameter warning */
  return 0;
}
---

And tried applying that:

---
@r@
identifier f, dummy;
position p1, p2;
type t;
@@

f(t dummy@p1)
{
...
  (void) dummy@p2;
...
}

@script:python@
p1 << r.p1;
p2 << r.p2;
@@

print "UGLY HACK: see %s and %s, file %s, this should just go away" %
(p1[0].line, p2[0].line, p1[0].file)
---

Still no go! However, I do have a match with that:

----
@r@
identifier f, dummy;
position p1, p2;
@@

f(int dummy@p1)
{
...
  (void) dummy@p2;
...
}

@script:python@
p1 << r.p1;
p2 << r.p2;
@@

print "UGLY HACK: see %s and %s, file %s, this should just go away" %
(p1[0].line, p2[0].line, p1[0].file)
----

That is a pretty specific case... So, what do I get wrong? In order:

* how can I abstract the type away from single argument functions?
* and then, how can I generalize to all arguments of a function, not
only single argument functions?

-- 
Francis Galiegue, [email protected]
"It seems obvious [...] that at least some 'business intelligence'
tools invest so much intelligence on the business side that they have
nothing left for generating SQL queries" (Stéphane Faroult, in "The
Art of SQL", ISBN 0-596-00894-5)
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to