[petsc-dev] array bounds exceeded?

Jed Brown jed at jedbrown.org
Mon Jan 23 22:11:51 CST 2017


Matthew Knepley <knepley at gmail.com> writes:

> I don't think the engine understands mod.

It's not the mod, it's that the compiler can't prove that dim+d < 6.

/home/jed/petsc/src/dm/impls/plex/plexgeometry.c: In function ‘DMPlexComputeGridHash_Internal’:
/home/jed/petsc/src/dm/impls/plex/plexgeometry.c:493:90: warning: array subscript is above array bounds [-Warray-bounds]
             for (d = 0; d < dim; ++d) {segA[d] = PetscRealPart(ccoords[edge*dim+d]); segA[dim+d] = PetscRealPart(ccoords[((edge+1)%(dim+1))*dim+d]);}
                                                                                      ~~~~^~~~~~~

This would silence the warning, though if you were to some day extend to
higher than dim=3, it would make this part produce silently wrong
results instead of an error:

diff --git i/src/dm/impls/plex/plexgeometry.c w/src/dm/impls/plex/plexgeometry.c
index 9e1522b..5ac5032 100644
--- i/src/dm/impls/plex/plexgeometry.c
+++ w/src/dm/impls/plex/plexgeometry.c
@@ -490,7 +490,7 @@ PetscErrorCode DMPlexComputeGridHash_Internal(DM dm, PetscGridHash *localBox)
           for (edge = 0; edge < dim+1; ++edge) {
             PetscReal segA[6], segB[6];

-            for (d = 0; d < dim; ++d) {segA[d] = PetscRealPart(ccoords[edge*dim+d]); segA[dim+d] = PetscRealPart(ccoords[((edge+1)%(dim+1))*dim+d]);}
+            for (d = 0; d < dim; ++d) {segA[d] = PetscRealPart(ccoords[edge*dim+d]); segA[(dim+d)%6] = PetscRealPart(ccoords[((edge+1)%(dim+1))*dim+d]);}
             for (kk = 0; kk < (dim > 2 ? 2 : 1); ++kk) {
               if (dim > 2) {segB[2]     = PetscRealPart(point[2]);
                             segB[dim+2] = PetscRealPart(point[2]) + kk*h[2];}


>    Matt
>
> On Mon, Jan 23, 2017 at 4:30 PM, Adrian Croucher <a.croucher at auckland.ac.nz>
> wrote:
>
>> I just pulled the latest 'next' branch and compiled. I noticed the
>> following warning- can this be ignored or is it possibly trouble?
>>
>>           CC linux-gnu-c-opt/obj/src/dm/impls/plex/plexgeometry.o
>> /home/acro018/software/PETSc/code/src/dm/impls/plex/plexgeometry.c: In
>> function ‘DMPlexComputeGridHash_Internal’:
>> /home/acro018/software/PETSc/code/src/dm/impls/plex/plexgeometry.c:493:90:
>> warning: array subscript is above array bounds [-Warray-bounds]
>>              for (d = 0; d < dim; ++d) {segA[d] =
>> PetscRealPart(ccoords[edge*dim+d]); segA[dim+d] =
>> PetscRealPart(ccoords[((edge+1)%(dim+1))*dim+d]);}
>>
>> - Adrian
>>
>> --
>> Dr Adrian Croucher
>> Senior Research Fellow
>> Department of Engineering Science
>> University of Auckland, New Zealand
>> email: a.croucher at auckland.ac.nz
>> tel: +64 (0)9 923 4611
>>
>>
>
>
> -- 
> What most experimenters take for granted before they begin their
> experiments is infinitely more interesting than any results to which their
> experiments lead.
> -- Norbert Wiener
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 800 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20170123/9c8e6519/attachment.sig>


More information about the petsc-dev mailing list