building paths

David Relson relson at osagesoftware.com
Fri Jan 14 03:27:06 CET 2005


Matthias,

I've been looking at the manner in which bogofilter builds wordlist
paths.  In general, the wordlist path is built from (1) a filename
(typically "wordlist.db") and (2) a path (which may be a directory or a
full path, including filename).  Typically it done by calling:

bool build_path(char* dest, size_t size, const char* dir, const char* file);

There are several problems with this.  First, every call (except one) of
this function is preceded by computing the size parameter and malloc'ing
storage for the result.  Second, the return value is never checked.

It would be better if the function is declared:

char *build_path(const char* dir, const char* file);

and the function is responsible for allocating the storage it needs.
NULL could be used to indicate a problem, assuming we find a need to
check the result.

The advantage of doing this is that it centralizes the allocation of
"dest" and removes multiple copies of the current allocation code.

What do you think?

David

Note:  if we change this, related function build_wordlist_path will
also need to be changed.



More information about the bogofilter-dev mailing list