Re: 0 or -1 / _Bool or int

From: Murray S. Kucherawy <msk_at_blackops.org>
Date: Sun, 11 Dec 2011 20:24:06 -0800 (PST)

On Sat, 10 Dec 2011, Andreas Schulze wrote:
> I let create a daily dump of my statistics db. I found the message table
> entries mostly end with -1,0.
> For me that are the atsp and spam fields defined in the same way:
> atps integer not null default -1,
> spam integer not null default -1,
> I ask me, why the lines end not -1,-1 ...
>
> looking in the source I found 2 variables: mctx_atps defined as int and
> mctx_spam defined as _Bool.
>
> mctx_atps is initialized with DKIM_ATPS_UNKNOWN (-1)
> mctx_spam is not explicit initialized ( I expect FALSE because of a memzero )
> or set TRUE somewhere in the source.
>
> But in opendkim/stats.c/dkimf_stats_record both are declared as int.
> I think that results in -1,0 database entries.
>
> Because scripts like opendkim-gengraphs contains sqlcode like "AND NOT
> spam = -1", I applied the attached patch to write -1 instead of 0.
>
> Am I wrong?

The intent is to have the databases contain -1 for those fields if the
filter never checked for them, or if on checking an error occurred; 0 if
the test is false; 1 if the test is true.

For ATPS, it's possible to compile without "--enable-atps", so -1 makes
sense in that case. For spam, in 2.5.0 the check is always there in some
way (including "no rule was defined", meaning spam is never detected), so
-1 never makes sense. That's why ATPS is an int, but spam is a _Bool.

In the database definition, the "default -1" is there in case I get an
older stats report that doesn't include a column for spam. In that case
we do want to record the "I don't know" just so the record is complete.
It would be the same thing as allowing NULL and using a "tinyint
unsigned", I suppose.

-MSK
Received on Mon Dec 12 2011 - 04:24:36 PST

This archive was generated by hypermail 2.2.0+W3C-0.50 : Mon Dec 12 2011 - 14:50:05 PST