From ab39ef6ba5dadad9a99ba50ef15a44d0827360d1 Mon Sep 17 00:00:00 2001
From: Mathieu Faverge <mathieu.faverge@inria.fr>
Date: Thu, 14 May 2020 16:50:58 +0200
Subject: [PATCH] Minor fixes reported by coverity

---
 include/spm/const.h  | 2 +-
 src/spm.c            | 2 +-
 src/spm_dof_extend.c | 2 +-
 src/spm_gather.c     | 2 +-
 src/z_spm.h          | 2 +-
 src/z_spm_norm.c     | 2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/include/spm/const.h b/include/spm/const.h
index adff0081..01f9de53 100644
--- a/include/spm/const.h
+++ b/include/spm/const.h
@@ -189,7 +189,7 @@ typedef enum spm_normtype_e {
     SpmOneNorm       = 171, /**< One norm:       max_j( sum_i( |a_{ij}| ) )   */
     SpmFrobeniusNorm = 174, /**< Frobenius norm: sqrt( sum_{i,j} (a_{ij}^2) ) */
     SpmInfNorm       = 175, /**< Inifinite norm: max_i( sum_j( |a_{ij}| ) )   */
-    SpmMaxNorm       = 177  /**< Inifinite norm: max_{i,j}( | a_{ij} | )      */
+    SpmMaxNorm       = 177  /**< Max norm:       max_{i,j}( | a_{ij} | )      */
 } spm_normtype_t;
 
 /**
diff --git a/src/spm.c b/src/spm.c
index 2fc61e1c..03328a0f 100644
--- a/src/spm.c
+++ b/src/spm.c
@@ -321,7 +321,7 @@ spmBase( spmatrix_t *spm,
         }
     }
     if (spm->dofs != NULL) {
-        for (i = 0; i <= n; i++) {
+        for (i = 0; i <= spm->gN; i++) {
             spm->dofs[i] += baseadj;
         }
     }
diff --git a/src/spm_dof_extend.c b/src/spm_dof_extend.c
index 18eed840..64ddfdaa 100644
--- a/src/spm_dof_extend.c
+++ b/src/spm_dof_extend.c
@@ -86,8 +86,8 @@ spmDofExtend( const spmatrix_t *spm,
          * Initialize the dofs array where the degree of freedom of vertex i is
          * dof[i+1] - dof[i]
          */
-        *dofptr = baseval;
         if( spm->clustnum == 0 ) {
+            *dofptr = baseval;
             for(i=0; i<spm->gN; i++, dofptr++) {
                 dofi = 1 + ( rand() % dof );
                 dofptr[1] = dofptr[0] + dofi;
diff --git a/src/spm_gather.c b/src/spm_gather.c
index 91f23184..a918ca69 100644
--- a/src/spm_gather.c
+++ b/src/spm_gather.c
@@ -116,7 +116,7 @@ spm_gather_csx_update( const spmatrix_t *spm,
     for ( c=1; c<spm->clustnbr; c++ ) {
         /* Let's start shifting the value after the first array */
         spm_int_t shift = recvdispls[c];
-        spm_int_t end   = ( c == spm->clustnbr-1 ) ? spm->gN+1 : recvdispls[c+1];
+        spm_int_t end   = ( c < (spm->clustnbr-1) ) ? recvdispls[c+1] : spm->gN+1;
         spm_int_t i;
 
         to_add += recvcounts[c-1];
diff --git a/src/z_spm.h b/src/z_spm.h
index eff04607..f7eb42fe 100644
--- a/src/z_spm.h
+++ b/src/z_spm.h
@@ -64,7 +64,7 @@ int spm_zspmm( spm_side_t             side,
 /**
  * Norm computation routines
  */
-double z_spmNorm( int ntype, const spmatrix_t *spm );
+double z_spmNorm( spm_normtype_t ntype, const spmatrix_t *spm );
 
 /**
  * Extra routines
diff --git a/src/z_spm_norm.c b/src/z_spm_norm.c
index 861a4f53..29e9ccfd 100644
--- a/src/z_spm_norm.c
+++ b/src/z_spm_norm.c
@@ -386,7 +386,7 @@ z_spmOneNorm( const spmatrix_t *spm )
  *
  *******************************************************************************/
 double
-z_spmNorm( int ntype,
+z_spmNorm( spm_normtype_t    ntype,
            const spmatrix_t *spm )
 {
     double norm = 0.;
-- 
GitLab