+/*checks for the case expr2 == sizeof buf1 and buf1 is a fixed array*/
+static bool sizeofBufComp(constraintExpr buf1, constraintExpr expr2)
+{
+ constraintTerm ct;
+ exprNode e, t;
+ sRef s1, s2;
+
+ llassertfatal(constraintExpr_isDefined(buf1) &&
+ constraintExpr_isDefined(expr2) );
+
+ /*@access constraintExpr@*/
+
+ if ((expr2->kind != term) && (buf1->kind != term) )
+ return FALSE;
+
+
+ ct = constraintExprData_termGetTerm(expr2->data);
+
+ if (!constraintTerm_isExprNode(ct) )
+ return FALSE;
+
+ e = constraintTerm_getExprNode(ct);
+
+ llassert (exprNode_isDefined(e));
+
+ if (! (exprNode_isDefined(e)))
+ return FALSE;
+
+ if (e->kind != XPR_SIZEOF)
+ return FALSE;
+
+ t = exprData_getSingle (e->edata);
+ s1 = exprNode_getSref (t);
+
+ s2 = constraintTerm_getsRef(constraintExprData_termGetTerm(buf1->data) );
+
+ /*drl this may be the wronge thing to test for but this
+ seems to work correctly*/
+ if (sRef_similarRelaxed(s1, s2) || sRef_sameName (s1, s2) )
+ {
+ /* origly checked that ctype_isFixedArray(sRef_getType(s2)) but
+ removed that test */
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/* look for the special case of
+ maxSet(buf) >= sizeof(buf) - 1
+*/
+
+/*drl eventually it would be good to check that
+ buf is of type char.*/
+
+static bool sizeOfMaxSet( /*@observer@*/ /*@temp@*/ constraint c)
+{
+ constraintExpr l, r, buf1, buf2, con;
+
+ DPRINTF(( message("sizeOfMaxSet: checking %s ", constraint_unparse(c) )
+ ));
+
+ llassertfatal (constraint_isDefined(c) );
+
+ l = c->lexpr;
+ r = c->expr;
+
+ if (!((c->ar == EQ) || (c->ar == GTE) || (c->ar == LTE) ) )
+ return FALSE;
+
+ llassert (constraintExpr_isDefined(l) );
+ llassert (constraintExpr_isDefined(r) );
+
+ /*check if the constraintExpr is MaxSet(buf) */
+ if (l->kind == unaryExpr)
+ {
+ if (constraintExprData_unaryExprGetOp(l->data) == MAXSET)
+ {
+ buf1 = constraintExprData_unaryExprGetExpr(l->data);
+ }
+ else
+ return FALSE;
+ }
+ else
+ return FALSE;
+
+
+ if (r->kind != binaryexpr)
+ return FALSE;
+
+ buf2 = constraintExprData_binaryExprGetExpr1(r->data);
+ con = constraintExprData_binaryExprGetExpr2(r->data);
+
+ if (constraintExprData_binaryExprGetOp(r->data) == BINARYOP_MINUS)
+ {
+ if (constraintExpr_canGetValue(con) )
+ {
+ long i;
+
+ i = constraintExpr_getValue(con);
+ if (i != 1)
+ {
+ return FALSE;
+ }
+ }
+ else
+ return FALSE;
+ }
+
+ if (constraintExprData_binaryExprGetOp(r->data) == BINARYOP_PLUS)
+ {
+ if (constraintExpr_canGetValue(con) )
+ {
+ long i;
+
+ i = constraintExpr_getValue(con);
+ if (i != -1)
+ {
+ return FALSE;
+ }
+ }
+ else
+ return FALSE;
+ }
+
+ if (sizeofBufComp(buf1, buf2))
+ {
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+}
+/*@noaccess constraintExpr@*/
+