gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 2fb08e0f: Library (txt.h): accounts for larger


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 2fb08e0f: Library (txt.h): accounts for larger width in str col (when its last)
Date: Mon, 30 May 2022 20:07:58 -0400 (EDT)

branch: master
commit 2fb08e0ff8e886f89a6403430ffb9af09f8c9c08
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    Library (txt.h): accounts for larger width in str col (when its last)
    
    Until now, when the last column of an input table (in plain-text) has a
    string type, but the given width (number of characters) in the column's
    metadata gives a width that is larger than the string, Table will not
    recognize that string column! Therefore, it will either not read that
    column if there are other columns before it, or if that string column is
    the only column, it will complain that "no usable data rows".
    
    With this commit, the solution was found to be a wrongly placed "break" in
    cases where the expected width of a string column (that is also the last
    column!) is larger than the actual characters of the last string column
    (before reaching the new-line character). The check to 'break' the loop
    should have been moved to the start of the 'while' loop, not in the same
    step that the line is being parsed.
    
    This bug was found with the help of Sepideh Eskandarlou.
    
    This fixes bug #62548.
---
 NEWS      |  3 +++
 lib/txt.c | 23 ++++++++++++++---------
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/NEWS b/NEWS
index ed09a778..277832b1 100644
--- a/NEWS
+++ b/NEWS
@@ -90,6 +90,9 @@ See the end of the file for license conditions.
               Eskandarlou.
   bug #62429: Segment prints one line status-progress line when called with
               '--quiet'. Reported by Teet Kuutma.
+  bug #62548: Table doesn't recognize plain-text string column when defined
+              width is larger and it is the last column. Found with the
+              help of Sepideh Eskandarlou.
 
 
 
diff --git a/lib/txt.c b/lib/txt.c
index c02eda30..6491c42a 100644
--- a/lib/txt.c
+++ b/lib/txt.c
@@ -352,6 +352,12 @@ txt_info_from_first_row(char *in_line, gal_data_t 
**datall, int format,
   /* Go over the line check/fill the column information. */
   while(++ncol)
     {
+      /* If 'line' has already passed the end of the actual string (for
+         example when a string column is the last one and its declared
+         width is larger than the actual number of characters it has in
+         that line). */
+      if(line>=end) break;
+
       /* When we are dealing with a text table, check if there is
          information for this column. For a text image, only the number of
          tokens is important (as the second dimension of the image), so
@@ -362,7 +368,6 @@ txt_info_from_first_row(char *in_line, gal_data_t **datall, 
int format,
       else
         col=NULL;
 
-
       /* If there is information for this column, then check if it is a
          string, and if so, don't use 'strtok_r' (because it might have
          delimiters). So manually go ahead in the line till you get to the
@@ -378,18 +383,19 @@ txt_info_from_first_row(char *in_line, gal_data_t 
**datall, int format,
               /* Increment line to the end of the string. */
               line = (token=line) + col->disp_width;
 
-              /* If we haven't reached the end of the line, then set a NULL
-                 character where the string ends, so we can use the
-                 token. VERY IMPORTANT: this should not be '<=end'. If the
-                 given width is larger than line, there is no problem, the
-                 '\0' of the line will also be used to end this last
-                 column.*/
+              /* If we haven't reached the end of the line (so 'line<end'),
+                 then set a NULL character where the current token is
+                 expected to end. In this way, we can use the token (while
+                 preserving the line for the rest of the 'while'
+                 loop). VERY IMPORTANT: to do this, 'line' should not be
+                 '<=end'. If the given width is larger than line, there is
+                 no problem, the '\0' of the line will also be used to end
+                 this last column.*/
               if(line<end)
                 {
                   *line++='\0';
                   /* printf(" col %zu: -%s-\n", i, token); */
                 }
-              else break;
             }
           else
             {
@@ -433,7 +439,6 @@ txt_info_from_first_row(char *in_line, gal_data_t **datall, 
int format,
         }
     }
 
-
   /* When looking at a text table, 'n' is the number of columns (elements
      in the linked list). But when looking at an image, it is the size of
      the second dimension. To unify things from this step forwards, we will



reply via email to

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