strspn [was: 0.11.1 debian failures]

David Relson relson at osagesoftware.com
Sun Mar 16 17:50:08 CET 2003


At 11:33 AM 3/16/03, Clint Adams wrote:

> > Attached is a patch for directory bogofilter/src/tests that adds t.strspn
> > and strspn.c.  As I think about it, what you really want is a standalone
> > test.  I think you can create that by a couple of small changes to
> > t.strspn.  First delete the reference to t.frame, then add the appropriate
> > gcc command (which you can cut/paste from the S390 test log).
>
>I'm sorry to say that your test case compiles and executes without
>segfaulting.

Clint,

I guess I trimmed out too much of function read_config_file().  I've 
attached a second version of strspn.c which has a full version of 
read_config_file() and stubs for the functions _it_ calls.  Hopefully this 
will trigger the optimization error.  If not, the gcc folks will just have 
to work with the original.

David
-------------- next part --------------
/* $Id: deqp.c,v 1.2 2003/02/06 17:19:46 relson Exp $ */

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

#include "common.h"

#define MAXBUFFLEN	200

bool simple_test(const char *fname);
bool read_config_file(const char *fname, bool tilde_expand, bool warn_on_error, priority_t precedence);
bool process_config_line(const char *arg, const char *val, void *usr_parms, priority_t precedence);

void *usr_parms = NULL;
void *sys_parms = NULL;
void *fmt_parms = NULL;

void *xmalloc(size_t s);
void xfree(void *p);
char *xstrdup(const char *str);
char *tildeexpand(const char *fname);

char *xstrdup(const char *str)
{
    return strdup(str);
}

char *tildeexpand(const char *fname)
{
    return xstrdup(fname);
}

void *xmalloc(size_t s)
{
    return malloc(s);
}

void xfree(void *p)
{
    free(p);
}

bool process_config_line(const char *arg, const char *val, void *parms, priority_t precedence)
{
    return true;
}

bool simple_test(const char *fname)
{
    bool error = false;
    int lineno = 0;
    FILE *fp;
    char *arg = NULL, *val = NULL;

    fp = fopen(fname, "r");

    if (fp == NULL) {
	fprintf(dbgout, "Cannot open %s: %s\n", fname, strerror(errno));
	return false;
    }

    fprintf(dbgout, "Reading %s\n", fname);

    while (!feof(fp))
    {
	const char delim[] = " \t=";
	size_t len;
	char buff[MAXBUFFLEN];

	memset(buff, '\0', sizeof(buff));		/* for debugging */

	lineno += 1;
	if (fgets(buff, sizeof(buff), fp) == NULL)
	    break;
	len = strlen(buff);

	fprintf(dbgout, "Testing:  %s\n", buff);

	arg = buff;
	if (strcspn(arg, delim) < strlen(arg)) { /* if delimiter present */
	    val = arg + strcspn(arg, delim);
	    *val++ = '\0';
	    val += strspn(val, delim);
	}

    }

    (void)fclose(fp); /* we're just reading, so fclose should succeed */

    return (error);
}

bool read_config_file(const char *fname, bool tilde_expand, bool warn_on_error, priority_t precedence)
{
    bool error = false;
    int lineno = 0;
    FILE *fp;
    char *filename;
    char *arg = NULL, *val = NULL;

    if (tilde_expand) {
	filename = tildeexpand(fname);
    } else {
	filename = xstrdup(fname);
    }

    fp = fopen(filename, "r");

    if (fp == NULL) {
	if (DEBUG_CONFIG(0)) {
	    fprintf(dbgout, "Cannot open %s: %s\n", filename, strerror(errno));
	}
	xfree(filename);
	return false;
    }

    if (DEBUG_CONFIG(0))
	fprintf(dbgout, "Reading %s\n", filename);

    while (!feof(fp))
    {
	const char delim[] = " \t=";
	size_t len;
	char buff[MAXBUFFLEN];

	memset(buff, '\0', sizeof(buff));		/* for debugging */

	lineno += 1;
	if (fgets(buff, sizeof(buff), fp) == NULL)
	    break;
	len = strlen(buff);
	if ( buff[0] == '#' || buff[0] == ';' || buff[0] == '\n' )
	    continue;
	while (iscntrl((unsigned char)buff[len-1]) || isspace((unsigned char)buff[len-1]))
	    buff[--len] = '\0';

	if (DEBUG_CONFIG(1))
	    fprintf(dbgout, "Testing:  %s\n", buff);

	arg = buff;
	if (strcspn(arg, delim) < strlen(arg)) { /* if delimiter present */
	    val = arg + strcspn(arg, delim);
	    *val++ = '\0';
	    val += strspn(val, delim);
	} else {
	    val = NULL;
	}
	if (val == NULL ||
	       (! process_config_line(arg, val, usr_parms, precedence ) &&
		! process_config_line(arg, val, sys_parms, precedence ) &&
		! process_config_line(arg, val, fmt_parms, precedence )))
	{
	    error = true;
	    if (warn_on_error)
		fprintf(stderr, "%s:%d:  Error - bad parameter in '%s ... %s'\n", filename, lineno, buff, val);
	}
    }

    if (ferror(fp)) {
	fprintf(stderr, "Read error while reading file \"%s\".", filename);
	error = true;
    }

    (void)fclose(fp); /* we're just reading, so fclose should succeed */
    xfree(filename);

    return (error);
}

int main( int argc, char **argv)
{
    dbgout = stdout;

    if (argc == 1)
	simple_test( "strspn.cf" );
    else
	read_config_file( argv[1], true, false, PR_NONE );
    return 0;
}



More information about the bogofilter-dev mailing list