gnuastro-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnuastro-commits] master 1ae67c38: Table: properly freeing non-used str


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 1ae67c38: Table: properly freeing non-used string row contents with --tail
Date: Wed, 16 Feb 2022 20:46:10 -0500 (EST)

branch: master
commit 1ae67c38048028cbbd022fd3c1e96d162bcae413
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    Table: properly freeing non-used string row contents with --tail
    
    Until now, when the value to '--tail' was more than half the number of rows
    and the output columns contained strings, Table would crash with a
    segmentation fault. This was because of an incorrect freeing of string
    column arrays for the un-used columns.
    
    With this commit, we now properly account for cases where the number of
    tail rows is more than half of the total number of rows and only free those
    that will not be in the output.
    
    This bug was reported by Manuel Sánchez-Benavente.
    
    This fixes bug #62070.
---
 NEWS              | 4 ++++
 bin/table/table.c | 7 +++++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index 491a1514..cf044d62 100644
--- a/NEWS
+++ b/NEWS
@@ -203,6 +203,10 @@ See the end of the file for license conditions.
               operands are integers of same width, but different sign (for
               example 'int32' and 'uint32'); reported by Zohreh Ghaffari
               and Pedram Ashofteh Ardakani.
+  bug #62070: Segmentation fault in Table's '--tail' option, when string
+              columns are requested and the requested number of rows given
+              to '--tail' is more than half of the number of rows; reported
+              by Manuel Sánchez-Benavente.
 
 
 
diff --git a/bin/table/table.c b/bin/table/table.c
index 341b984f..690a40c2 100644
--- a/bin/table/table.c
+++ b/bin/table/table.c
@@ -711,9 +711,12 @@ table_select_by_position(struct tableparams *p)
             }
           else
             {
-              /* Free their allocated spaces. */
+              /* Set the starting and ending indexs to free the allocated
+                 space of each string. */
               start = p->head!=GAL_BLANK_SIZE_T ? p->head        : 0;
-              end   = p->head!=GAL_BLANK_SIZE_T ? p->table->size : p->tail;
+              end   = ( p->head!=GAL_BLANK_SIZE_T
+                        ? p->table->size
+                        : p->table->size - p->tail );
               for(i=start; i<end; ++i) { free(strarr[i]); strarr[i]=NULL; }
             }
         }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]