tgrain.c: fail if number of contacts exceed MAXCONTACTS - granular - granular dynamics simulation
 (HTM) git clone git://src.adamsgaard.dk/granular
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 6bfe4343c4a35003808fb1b3bdf94480a7c7d216
 (DIR) parent 4c0f7cd6f3bc47dd2c33141ef0a3da3f9b25f957
 (HTM) Author: Anders Damsgaard <anders@adamsgaard.dk>
       Date:   Wed, 21 Apr 2021 10:18:14 +0200
       
       grain.c: fail if number of contacts exceed MAXCONTACTS
       
       Diffstat:
         M grain.c                             |       8 ++++++--
       
       1 file changed, 6 insertions(+), 2 deletions(-)
       ---
 (DIR) diff --git a/grain.c b/grain.c
       t@@ -322,7 +322,7 @@ grain_register_contact(struct grain *g, size_t i, size_t j,
                int ic, d;
        
                /* first pass: check if contact is already registered */
       -        for (ic = 0; ic <= MAXCONTACTS; ic++)
       +        for (ic = 0; ic < MAXCONTACTS; ic++)
                        if (g->contacts[ic].j == j) {
                                g->contacts[ic].overlap = overlap;
                                for (d = 0; d < 3; d++)
       t@@ -332,7 +332,10 @@ grain_register_contact(struct grain *g, size_t i, size_t j,
        
                /* second pass: register as new contact if overlapping */
                if (overlap < 0.0)
       -                for (ic = 0; ic <= MAXCONTACTS; ic++)
       +                for (ic = 0; ic <= MAXCONTACTS; ic++) {
       +                        if (ic == MAXCONTACTS)
       +                                err(1, "%s: contact %zu exceeds MAXCONTACTS (%d)",
       +                                    __func__, i, MAXCONTACTS);
                                if (!g->contacts[ic].active) {
                                        contact_new(&g->contacts[ic], i, j);
                                        g->ncontacts += 1;
       t@@ -342,4 +345,5 @@ grain_register_contact(struct grain *g, size_t i, size_t j,
                                                g->contacts[ic].tandisp[d] = 0.0;
                                        }
                                }
       +                }
        }