Patch to prevent negative counts [was: Oh oh]

Adrian Otto aotto at aotto.com
Thu Sep 12 19:14:45 CEST 2002


David,

Thanks for the patch. I will be releasing a new version later today or
tomorrow that implements portable file locking on the database files to
prevent data corruption in the event of simultaneous use of the same
wordlist database files by separate bogofilter (or foreign) processes. I'll
roll your patch into my new source tarball when it's ready.

Cheers,

Adrian Otto

> -----Original Message-----
> From: David Relson [mailto:relson at osagesoftware.com]
> Sent: Thursday, September 12, 2002 5:25 AM
> To: bogofilter
> Subject: Patch to prevent negative counts [was: Oh oh]
>
>
> In bogofilter.c, function increment() always adds the new frequency count
> to the word's current count.  In the case of -H and -S, the new count is
> negative so the result of the addition can also be negative.
>
> Here's a patch that sets the result to 0, rather than going negative.
>
> --- bogofilter-0.7.2/bogofilter.c~	Sat Sep  7 20:06:55 2002
> +++ bogofilter-0.7.2/bogofilter.c	Thu Sep 12 08:19:21 2002
> @@ -117,10 +117,14 @@
>   static void increment(char *word,  long incr, wordlist_t *list)
>   /* increment a word usage count in the specified list */
>   {
> -  incr += get_word_value(word, list);
> -  set_word_value(word, incr, list);
> +  long count = get_word_value(word, list);
> +  if ( incr > 0 || count > -incr )
> +      count += incr;
> +  else
> +      count = 0;
> +  set_word_value(word, count, list);
>     if (verbose >= 1)
> -    printf("increment: '%s' has %lu hits\n",word,incr);
> +    printf("increment: '%s' has %lu hits\n",word,count);
>   }
>
>   static int getcount(char *word, wordlist_t *list)
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: bogofilter-unsubscribe at aotto.com
> For summay digest subscription: bogofilter-digest-subscribe at aotto.com
> For more commands, e-mail: bogofilter-help at aotto.com
>
>


For summay digest subscription: bogofilter-digest-subscribe at aotto.com



More information about the Bogofilter mailing list