From rideout at aei.mpg.de Fri Apr 6 08:36:25 2007 From: rideout at aei.mpg.de (David Rideout) Date: Fri, 6 Apr 2007 15:36:25 +0200 (CEST) Subject: [Patches] fix to integer overflow bug in PUGH Message-ID: The malloc calls in PUGH compute the size to allocate from an int expression. This patch casts such expressions to size_t. This fixes PR 2088. Patch also includes a check that malloc returns a non-NULL result... Thanks to Erik Schnetter for pointing me to the solution. -David -------------- next part -------------- Index: Storage.c =================================================================== RCS file: /cactusdevcvs/CactusPUGH/PUGH/src/Storage.c,v retrieving revision 1.52 diff -c -r1.52 Storage.c *** Storage.c 15 Jun 2006 16:15:19 -0000 1.52 --- Storage.c 6 Apr 2007 13:39:16 -0000 *************** *** 613,619 **** GA->padddata = NULL; } ! if (GA->extras->npoints * GA->varsize * GA->vector_size <= 0) { /* only warn if the global array size is also zero */ for (i = 0, global_size = 1; i < GA->extras->dim; i++) --- 613,619 ---- GA->padddata = NULL; } ! if ((size_t) GA->extras->npoints * GA->varsize * GA->vector_size <= 0) { /* only warn if the global array size is also zero */ for (i = 0, global_size = 1; i < GA->extras->dim; i++) *************** *** 631,646 **** else if (! my_padding_active) { /* Easy case. */ ! GA->data = malloc (GA->extras->npoints * GA->varsize * GA->vector_size); GA->padddata = GA->data; } else { /* Use the Cactus Cache alignment function */ GA->data = Util_CacheMalloc (GA->arrayid, ! GA->extras->npoints * GA->varsize * GA->vector_size, &GA->padddata); } GA->npoints = GA->extras->npoints; #ifdef DEBUG_PUGH printf (" PUGH_EnableGArrayDataStorage: new pointer is %p (%p)\n", --- 631,651 ---- else if (! my_padding_active) { /* Easy case. */ ! GA->data = malloc ((size_t) GA->extras->npoints * GA->varsize * GA->vector_size); GA->padddata = GA->data; } else { /* Use the Cactus Cache alignment function */ GA->data = Util_CacheMalloc (GA->arrayid, ! (size_t) GA->extras->npoints * GA->varsize * GA->vector_size, &GA->padddata); } + if (!GA->data) + { + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, "Error allocating memory block of size " + "%lu", (size_t) GA->extras->npoints * GA->varsize * GA->vector_size); + } GA->npoints = GA->extras->npoints; #ifdef DEBUG_PUGH printf (" PUGH_EnableGArrayDataStorage: new pointer is %p (%p)\n", From dprideout at gmail.com Wed Apr 18 08:03:03 2007 From: dprideout at gmail.com (David Rideout) Date: Wed, 18 Apr 2007 14:03:03 +0100 Subject: [Patches] unstructured mesh driver Message-ID: <1ce81abb0704180603p5a846ae9s24a5057b2d2cc7e5@mail.gmail.com> In August 2005 I wrote an implementation of the unstructured mesh specification at http://www.cactuscode.org/specs/Unstructured.html. This includes a driver UMDriver and modifications to the flesh. Both are available at cvs -d:pserver:cvs_anon at cvs.cct.lsu.edu:/Frameworks co CactusUMT I did not submit the flesh changes as a patch, because I did not think them appropriate for version 4.0, however I submit them now for completeness. They can be found in CactusUMT/UMDriver/src/UnstructuredFlesh-5oct005.tbz. Cheers, David