gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master cb3b918: Library (txt): integers are only read


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master cb3b918: Library (txt): integers are only read in base 10
Date: Sun, 20 Sep 2020 16:51:51 -0400 (EDT)

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

    Library (txt): integers are only read in base 10
    
    Until now, if an integer was written in the format of '008' for example to
    fill empty character columns (which is done by some databases, like
    http://www.astro.gsu.edu/wds), the values would be interpretted in octal
    format (the standard C library behavior of 'strtol'). But rarely do
    datasets contain octal values, so this caused wrong reading of the values
    or crashs (when there were numerical characters equal and larger than 8).
    
    So with this commit, the third argument of 'strtol', which is the base of
    the string, is set to '10' so it is always interpretted as base-10. Later,
    if it becomes necessary to deal with octal strings (or any other base), we
    can define a special option for the base of integers.
---
 lib/txt.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/lib/txt.c b/lib/txt.c
index 8158f3e..79a6bc8 100644
--- a/lib/txt.c
+++ b/lib/txt.c
@@ -779,49 +779,49 @@ txt_read_token(gal_data_t *data, gal_data_t *info, char 
*token,
           break;
 
         case GAL_TYPE_UINT8:
-          uc[i]=strtol(token, &tailptr, 0);
+          uc[i]=strtol(token, &tailptr, 10);
           if( (ucb=info->array) && *ucb==uc[i] )
             uc[i]=GAL_BLANK_UINT8;
           break;
 
         case GAL_TYPE_INT8:
-          c[i]=strtol(token, &tailptr, 0);
+          c[i]=strtol(token, &tailptr, 10);
           if( (cb=info->array) && *cb==c[i] )
             c[i]=GAL_BLANK_INT8;
           break;
 
         case GAL_TYPE_UINT16:
-          us[i]=strtol(token, &tailptr, 0);
+          us[i]=strtol(token, &tailptr, 10);
           if( (usb=info->array) && *usb==us[i] )
             us[i]=GAL_BLANK_UINT16;
           break;
 
         case GAL_TYPE_INT16:
-          s[i]=strtol(token, &tailptr, 0);
+          s[i]=strtol(token, &tailptr, 10);
           if( (sb=info->array) && *sb==s[i] )
             s[i]=GAL_BLANK_INT16;
           break;
 
         case GAL_TYPE_UINT32:
-          ui[i]=strtol(token, &tailptr, 0);
+          ui[i]=strtol(token, &tailptr, 10);
           if( (uib=info->array) && *uib==ui[i] )
             ui[i]=GAL_BLANK_UINT32;
           break;
 
         case GAL_TYPE_INT32:
-          ii[i]=strtol(token, &tailptr, 0);
+          ii[i]=strtol(token, &tailptr, 10);
           if( (ib=info->array) && *ib==ii[i] )
             ii[i]=GAL_BLANK_INT32;
           break;
 
         case GAL_TYPE_UINT64:
-          ul[i]=strtoul(token, &tailptr, 0);
+          ul[i]=strtoul(token, &tailptr, 10);
           if( (ulb=info->array) && *ulb==ul[i] )
             ul[i]=GAL_BLANK_UINT64;
           break;
 
         case GAL_TYPE_INT64:
-          l[i]=strtol(token, &tailptr, 0);
+          l[i]=strtol(token, &tailptr, 10);
           if( (lb=info->array) && *lb==l[i] )
             l[i]=GAL_BLANK_INT64;
           break;



reply via email to

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