[splint-discuss] (How) does the 'unsignedintegraltype' annotation
work?
Ludolf Holzheid
lholzheid at bihl-wiedemann.de
Mon Jul 10 16:09:16 EDT 2006
On Thu, 2006-06-29 15:59:45 +0200, I wrote:
> [..]
> the 'unsignedintegraltype' annotation does not work as I expect:
> [..]
Splint didn't complain about the assignment of negative integer
constants and integer constants without the 'u' suffix to variables
with /*@unsignedintegraltype@*/ annotated type, because I was
missing the -numliteral flag.
However, with -numliteral, splint complains about _all_ assignments of
constants to /*@unsignedintegraltype@*/ variables. The attached patch
changes splint to the behavior I initially expected:
uint8_t u8a;
int8_t i8a;
u8a = 1; // warning
u8a = 1u; // no warning
u8a = 1l; // warning
u8a = 1lu; // no warning
u8a = -1; // warning
i8a = 1; // no warning
i8a = 1u; // warning
i8a = 1l; // no warning
i8a = 1lu; // warning
i8a = -1; // no warning
Is the changed behavior reasonable?
Could anyone review the patch (or be responsive in other way)?
Ludolf
--
---------------------------------------------------------------
Ludolf Holzheid Tel: +49 621 339960
Bihl+Wiedemann GmbH Fax: +49 621 3392239
Floßwörthstraße 41 e-mail: lholzheid at bihl-wiedemann.de
D-68199 Mannheim, Germany
---------------------------------------------------------------
-------------- next part --------------
diff -ur --exclude '*.lcd' splint-3.1.1/lib/standard.h splint-3.1.1.modified/lib/standard.h
--- splint-3.1.1/lib/standard.h 2003-04-21 00:45:10.000000000 +0200
+++ splint-3.1.1.modified/lib/standard.h 2006-07-09 21:08:52.000000000 +0200
@@ -1159,16 +1159,16 @@
** These types are OPTIONAL. Provide warnings on use.
*/
-typedef /*@integraltype@*/ int8_t
+typedef /*@signedintegraltype@*/ int8_t
/*@warn implementationoptional "ISO99 specifies as optional type, implementation need not provide. Consider int_least8_t instead."@*/ ;
-typedef /*@integraltype@*/ int16_t
+typedef /*@signedintegraltype@*/ int16_t
/*@warn implementationoptional "ISO99 specifies as optional type, implementation need not provide. Consider int_least16_t instead."@*/ ;
-typedef /*@integraltype@*/ int32_t
+typedef /*@signedintegraltype@*/ int32_t
/*@warn implementationoptional "ISO99 specifies as optional type, implementation need not provide. Consider int_least32_t instead."@*/ ;
-typedef /*@integraltype@*/ int64_t
+typedef /*@signedintegraltype@*/ int64_t
/*@warn implementationoptional "ISO99 specifies as optional type, implementation need not provide. Consider int_least64_t instead."@*/ ;
typedef /*@unsignedintegraltype@*/ uint8_t
@@ -1183,20 +1183,20 @@
typedef /*@unsignedintegraltype@*/ uint64_t
/*@warn implementationoptional "ISO99 specifies as optional type, implementation need not provide. Consider uint_least64_t instead."@*/ ;
-typedef /*@integraltype@*/ int_least8_t;
-typedef /*@integraltype@*/ int_least16_t;
-typedef /*@integraltype@*/ int_least32_t;
-typedef /*@integraltype@*/ int_least64_t;
+typedef /*@signedintegraltype@*/ int_least8_t;
+typedef /*@signedintegraltype@*/ int_least16_t;
+typedef /*@signedintegraltype@*/ int_least32_t;
+typedef /*@signedintegraltype@*/ int_least64_t;
typedef /*@unsignedintegraltype@*/ uint_least8_t;
typedef /*@unsignedintegraltype@*/ uint_least16_t;
typedef /*@unsignedintegraltype@*/ uint_least32_t;
typedef /*@unsignedintegraltype@*/ uint_least64_t;
-typedef /*@integraltype@*/ int_fast8_t;
-typedef /*@integraltype@*/ int_fast16_t;
-typedef /*@integraltype@*/ int_fast32_t;
-typedef /*@integraltype@*/ int_fast64_t;
+typedef /*@signedintegraltype@*/ int_fast8_t;
+typedef /*@signedintegraltype@*/ int_fast16_t;
+typedef /*@signedintegraltype@*/ int_fast32_t;
+typedef /*@signedintegraltype@*/ int_fast64_t;
typedef /*@unsignedintegraltype@*/ uint_fast8_t;
typedef /*@unsignedintegraltype@*/ uint_fast16_t;
diff -ur --exclude '*.lcd' splint-3.1.1/src/cprim.c splint-3.1.1.modified/src/cprim.c
--- splint-3.1.1/src/cprim.c 2003-03-02 20:59:12.000000000 +0100
+++ splint-3.1.1.modified/src/cprim.c 2006-07-09 21:15:12.000000000 +0200
@@ -126,9 +126,15 @@
{
return (cprim_closeEnough (CTX_ULINT, c2));
}
+ else if (context_getFlag (FLG_IGNORESIGNS))
+ {
+ return (cprim_isAnyInt (c2)
+ || (cprim_isAnyChar (c2) && context_msgCharInt ()));
+ }
else
{
- return FALSE;
+ return (cprim_isAnyUnsignedInt (c2)
+ || (cprim_isUnsignedChar (c2) && context_msgCharInt ()));
}
}
@@ -144,9 +150,15 @@
{
return (cprim_closeEnough (CTX_LINT, c2));
}
+ else if (context_getFlag (FLG_IGNORESIGNS))
+ {
+ return (cprim_isAnyInt (c2)
+ || (cprim_isAnyChar (c2) && context_msgCharInt ()));
+ }
else
{
- return FALSE;
+ return (cprim_isAnySignedInt (c2)
+ || (cprim_isSignedChar (c2) && context_msgCharInt ()));
}
}
@@ -182,9 +194,15 @@
{
return (cprim_closeEnough (c1, CTX_ULINT));
}
+ else if (context_getFlag (FLG_IGNORESIGNS))
+ {
+ return (cprim_isAnyInt (c1)
+ || (cprim_isAnyChar (c1) && context_msgCharInt ()));
+ }
else
{
- return FALSE;
+ return (cprim_isAnyUnsignedInt (c1)
+ || (cprim_isUnsignedChar (c1) && context_msgCharInt ()));
}
}
@@ -199,9 +217,15 @@
{
return (cprim_closeEnough (c1, CTX_LINT));
}
+ else if (context_getFlag (FLG_IGNORESIGNS))
+ {
+ return (cprim_isAnyInt (c1)
+ || (cprim_isAnyChar (c1) && context_msgCharInt ()));
+ }
else
{
- return FALSE;
+ return (cprim_isAnySignedInt (c1)
+ || (cprim_isSignedChar (c1) && context_msgCharInt ()));
}
}
diff -ur --exclude '*.lcd' splint-3.1.1/src/Headers/cprim.h splint-3.1.1.modified/src/Headers/cprim.h
--- splint-3.1.1/src/Headers/cprim.h 2003-03-02 21:18:44.000000000 +0100
+++ splint-3.1.1.modified/src/Headers/cprim.h 2006-07-09 18:41:36.000000000 +0200
@@ -99,6 +99,12 @@
# define cprim_isAnyUnsignedInt(c) ((c) == CTX_UINT || (c) == CTX_USINT \
|| (c) == CTX_ULINT || (c) == CTX_ULLINT \
|| (c) == CTX_UNSIGNEDINTEGRAL)
+
+extern bool cprim_isAnySignedInt (/*@sef@*/ cprim p_c);
+# define cprim_isAnySignedInt(c) ((c) == CTX_INT || (c) == CTX_SINT \
+ || (c) == CTX_LINT || (c) == CTX_LLINT \
+ || (c) == CTX_SIGNEDINTEGRAL)
+
# define cprim_isAnyReal(c) ((c) >= CTX_FLOAT && (c) <= CTX_LDOUBLE)
/*@constant int CTX_LAST;@*/
More information about the splint-discuss
mailing list