patch for readability of return codes

Nick Simicich njs at scifi.squawk.com
Thu Sep 12 21:22:35 CEST 2002


This is certainly a matter of taste.  Having spent many months reading
code looking for security bugs, I will assert (strongly) that this
practice does nothing but obfuscate the code.  It may improve mnemonic
readability, but when actually debugging or doing security reviews, one is
constantly referring to the definition of the symbols.

On Thu, 12 Sep 2002, David Relson wrote:

> Date: Thu, 12 Sep 2002 14:32:06 -0400
> From: David Relson <relson at osagesoftware.com>
> To: bogofilter at aotto.com
> Subject: patch for readability of return codes
> 
> I find the use of named constants for return codes (instead of numeric 
> constants), to improve program readability and understandability.  For 
> example, where bogofilter.c (version 0.7) currently has:
> 
> 	return((stats.spamicity > SPAM_CUTOFF) ? 0 : 1);
> 
> my private copy has:
> 
> 	return((stats.spamicity > SPAM_CUTOFF) ? RC_SPAM : RC_NONSPAM);
> 
> Below is the code that defines the named constants and that puts them to use:
> 
> diff -ur bogofilter-0.7.1a/bogofilter.h bogofilter-0.7.1b/bogofilter.h
> --- bogofilter-0.7.1a/bogofilter.h	Sat Sep  7 12:12:03 2002
> +++ bogofilter-0.7.1b/bogofilter.h	Thu Sep 12 14:20:50 2002
> @@ -1,5 +1,7 @@
>   //  constants and declarations for bogofilter
> 
> +typedef enum rc_e {RC_SPAM=0, RC_NONSPAM=1}  rc_t;
> +
>   typedef struct
>   {
>       char *name;			// resource name (for debug/verbose messages)
> diff -ur bogofilter-0.7.1a/bogofilter.c bogofilter-0.7.1b/bogofilter.c
> --- bogofilter-0.7.1a/bogofilter.c	Sat Sep  7 13:35:03 2002
> +++ bogofilter-0.7.1b/bogofilter.c	Thu Sep 12 14:30:41 2002
> @@ -500,7 +500,7 @@
>       if (verbose)
>   	printf("Spamicity of %f\n", stats.spamicity);
> 
> -    return((stats.spamicity > SPAM_CUTOFF) ? 0 : 1);
> +    return((stats.spamicity > SPAM_CUTOFF) ? RC_SPAM : RC_NONSPAM);
>   }
> 
>   // Done
> diff -ur bogofilter-0.7.1a/main.c bogofilter-0.7.1b/main.c
> --- bogofilter-0.7.1a/main.c	Thu Sep 12 14:14:52 2002
> +++ bogofilter-0.7.1b/main.c	Thu Sep 12 14:26:33 2002
> @@ -157,7 +157,7 @@
>   	    {
>   		if (inheaders && strncmp(textend->block, "Subject:", 8)==0)
>   		    printf("X-Spam-Status: %s, tests=bogofilter\n",
> -			   status ? "No" : "Yes");
> +			   (status == RC_NONSPAM) ? "No" : "Yes");
>   		else if (strcmp(textend->block, "\n") == 0 && inheaders == 0)
>   		    inheaders = 0;
>   		(void) fputs(textend->block, stdout);
> 
> --------------------------------------------------------
> David Relson                   Osage Software Systems, Inc.
> relson at osagesoftware.com       Ann Arbor, MI 48103
> www.osagesoftware.com          tel:  734.821.8800
> 
> 
> ---------------------------------------------------------------------
> 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