[bugs][ bogofilter-Bugs-653523 ] xcalloc 0 elements fail
Fast Bayesian spam filter along lines suggested by Paul Graham
Brought to you by:
m-a
From: <no...@so...> - 2002-12-14 02:26:54
|
Bugs item #653523, was opened at 2002-12-14 01:00 You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=499997&aid=653523&group_id=62265 Category: None Group: None Status: Closed >Resolution: Out of Date Priority: 5 Submitted By: Dan Nguyen (dnn) Assigned to: Nobody/Anonymous (nobody) Summary: xcalloc 0 elements fail Initial Comment: xcalloc wraps around a call to calloc, and then checks the pointer returned. However if calloc is called with either elements or element size set to 0. The return value is implementation defined. http://www.opengroup.org/onlinepubs/007904975/functio ns/calloc.html "If either nelem or elsize is 0, then either a null pointer or a unique pointer value that can be successfully passed to free() shall be returned. " On some platforms, the tests will fail because it thinks the calloc of 0 elements returned NULL, which is not an error condition. The only portable way to detect the error condition is to check the errno value to see if it ENOMEM. ---------------------------------------------------------------------- >Comment By: Matthias Andree (m-a) Date: 2002-12-14 03:26 Message: Logged In: YES user_id=2788 Yes, 0.9.1.2 still had the non-portable xcalloc code that falsely aborted the program when xcalloc(0,0) returned NULL. Please, before reporting the next problem if you have a detailed analysis, look into the CVS repository (you can browse it online) if the latest version fixes the problem. If you cannot spare the time or don't know the exact location of the defect, then please remember to include the bogofilter version number in your report. JFTR: bogofilter -V will print it. ---------------------------------------------------------------------- Comment By: Dan Nguyen (dnn) Date: 2002-12-14 03:10 Message: Logged In: YES user_id=129888 This is 0.9.1.2. This should fix the problem thanks. ---------------------------------------------------------------------- Comment By: Matthias Andree (m-a) Date: 2002-12-14 03:03 Message: Logged In: YES user_id=2788 What version of bogofilter do you refer to? The CVS version (2002-12-06) looks fine to me, even though it doesn't check ENOMEM, it won't fall prey to NULL == calloc(0,x) or NULL == calloc(x,0). It's ugly, but that's the way autoconf recommends. 6 void 7 *xcalloc(size_t nmemb, size_t size){ 8 void *x; 9 x = calloc(nmemb, size); 10 if (x == NULL && (nmemb == 0 || size == 0)) 11 x = calloc(1, 1); 12 if (x == NULL) { 13 xmem_error("xcalloc"); 14 } 15 return x; 16 } Also available from: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/bogofilter/bogofilter/xcalloc.c?rev=1.2&content-type=text/vnd.viewcvs-markup ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=499997&aid=653523&group_id=62265 |