Search

ParaSoft

HOME
PRODUCTS
SUPPORT
ABOUT
WHAT'S NEW
EVENTS


Insure++

Quick facts

Add-on Modules:
   -INUSE
   -TCA

Comparisons

Technical Papers

Support & Manuals

FAQs

Recent Reviews

User Testimonials

Press Releases


Insure tool to debug c++





Insure++ Reference - BAD_PARM



BAD_PARM

Mismatch in argument type

This error is generated when an argument to a function or subroutine does not match the type specified in an earlier declaration or an interface file.

Insure++ distinguishes several types of mismatch which have different levels of severity as follows:

sign Types differ only by sign, e.g., int vs. unsigned int.
compatible Fundamental types are different but they happen to have
the same representation on the particular hardware in use,
e.g., int vs. long on machines where both are 32-bits.
incompatible Fundamental types are different, e.g. int vs. float.
union Forces a declared union argument to match only a
similar union as an actual argument. If this is
suppressed, you may pass any of the individual union
elements to the routine, rather than the union type, or
pass a union to a routine which expects one of the
union-elements as an argument.
other An error was detected that is not simply a mismatched
argument type, such as passing the wrong number of
arguments to a function.
pointer This is not an error class, but a keyword used to
suppress messages about mismatched pointer types, such
as int * vs. char *. See Repair.

Error messages are classified according to this scheme and can be selectively enabled or disabled as described in the "Repair" section.

Problem #1

The following shows an error in which an incorrect argument is passed to the function foo.


	1: 	/*
	2:	 * File: badparm1.c
	3:	 */
	4:	void foo(str)
	5:		char *str;
	6:	{
	7:		return;
	8:	}
	9:	
	10:	main()
	11:	{
	12:		int *iptr;
	13:
	14:		foo(iptr); bug
	15:		return (0);
	16:	}

This type of mismatch is detected during compilation.

Diagnosis (during compilation)


1.	[badparm1.c:14] **BAD_PARM(incompatible)**
2.		Wrong type passed to foo (argument 1: str)
		Expected char *, found int *.
	>>		foo(iptr)


  1. Source lines at which problems were detected.
  2. Description of the problem and the arguments that are incorrect.

Problem #2

Another simple problem occurs when arguments are passed to functions in the wrong order, as in the following example.


	1: 	/*
	2:	 * File: badparm2.c
	3:	 */
	4:	long foo(f, l)
	5:		double f;
	6:		long l;
	7:	{
	8:		return f+l;
	9:	}
	10:
	11:	main()
	12:	{
	13:		long ret = foo(32L, 32.0); bug
	14:
	15:		printf("%ld\n", ret);
	16:		return 0;
	17:	}

Diagnosis (during compilation)


1.	[badparm2.c:13] **BAD_PARM(incompatible)**
2.		Wrong type passed to foo (argument 1: f)
		Expected double, found long.
	>>		long ret = foo(32L, 32.0);
	
	[badparm2.c:13] **BAD_PARM(incompatible)**
		Wrong type passed to foo (argument 2: l).
		Expected long, found double.
	>>		long ret = foo(32L, 32.0);


  1. Source lines at which problems were detected.
  2. Description of the problem and the arguments that are incorrect.

Problem #3

The following example illustrates the BAD_PARM (union) error category. The functions func1 and func2 expect to be passed a union and a pointer to an integer, respectively. The code in the main routine then invokes the two functions both properly and by passing the incorrect types.

Note that this code will probably work on most systems due to the internal alignment of the various data types. Relying on this behavior is, however, non-portable.


	1: 	/*
	2:	 * File: badparm3.c
	3:	 */
	4:	union data {
	5:		int i;
	6:		double d;
	7:	};
	8:
	9:	void func1(ptr)
	10:		union data *ptr;
	11:	{
	12:		ptr-> = 1;
	13:	}
	14:	
	15:	void func2(p)
	16:		int *p;
        17:	{
	18:		*p = 1;
	19:	}
	20:
	21:	main()
	22:	{
	23:		int t;
	24:		union data u;
	25:
	26:		func1(&u);
	27:		func1(&t);	/* BAD_PARM */ bug
	28:		func2(&u);	/* BAD_PARM */ bug
	29:		func2(&t); 	
	30:	}

Diagnosis (during compilation)


1.	[badparm3.c:27] **BAD_PARM(union)**
2.		Wrong type passed to func1 (argument 1: ptr)
		Expected union data *, found int *.
	>>		func1(&t);	/* BAD_PARM */

3.	[badparm3.c:28] **BAD_PARM(union)**
4.		Wrong type passwd to func2 (argument 1: p)
		Expected int *, found union data *.
	>>		func2(&u)	/* BAD_PARM */

  1. Source lines at which problems were detected.
  2. Description of the problem and the arguments that are incorrect.

Repair

Most of these problems are simple to correct based on the information given.

For example, problem #1 can be corrected by simply changing the incorrect line of code as follows

	badparm1.c, line 6:if(strchr("testing", 's'))

The other problems can be similarly corrected.

If your application generates error messages that you wish to ignore, you can add the option

	insure++.suppress BAD_PARM

to your .psrc file.

This directive suppresses all BAD_PARM messages. If you wish to be more selective and suppress only a certain type of error, you can use the syntax

	insure++.suppress BAD_PARM(class1, class2, ...)

where the arguments are one or more of the identifiers for the various categories of error described on BAD_PARM. Similarly, you can enable suppressed error messages with the unsuppress command.

Thus, you could enable warnings about conflicts between types int and long (on systems where they are the same number of bytes) using the option

	insure++.unsuppress BAD_PARM(compatible)

In addition to the keywords described on BAD_PARM, you can also use the type pointer to suppress all messages about different pointer types.

For example, many programs declare functions with the argument type char *, which are then called with pointers to various other data types. The ANSI standard recommends that you use type void * in such circumstances, since this is allowed to match any pointer type. If, for some reason, you cannot do this, you can suppress messages from Insure++ about incompatible pointer types with the option

	insure++.suppress BAD_PARM(pointer)

< BAD_INTERFACE > COPY_BAD_RANGE
Tools to debug c++ and java
(888) 305-0041 info@parasoft.com Copyright © 1996-2001 ParaSoft