RFC: Followup to PR91593

Jerry DeLisle jvdelisle@charter.net
Wed Oct 2 02:49:00 GMT 2019


On 9/30/19 8:57 PM, Steve Kargl wrote:
> On Mon, Sep 30, 2019 at 08:51:51PM -0700, Steve Kargl wrote:
>>
>> Can you just zero memory and remove the explicit setting
>> of the terminating '\0'?
>>
>>    q = buffer;
>>    memset(q, 0, len);
>>
> 
> (may be dup)
> 
> Upon further reading of the code, does buffer have
> 8*len+1 length?  You would need to do memset(q,0,8*len+1).
> 

Commited as obvious.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91593

diff --git a/libgfortran/io/read.c b/libgfortran/io/read.c
index be9f6cb6f76..4a77e4384b7 100644
--- a/libgfortran/io/read.c
+++ b/libgfortran/io/read.c
@@ -638,7 +638,7 @@ read_decimal (st_parameter_dt *dtp, const fnode *f, char 
*dest, int length)
    /* This is a legacy extension, and the frontend will only allow such cases
     * through when -fdec-format-defaults is passed.
     */
-  if (w == DEFAULT_WIDTH)
+  if (w == (size_t) DEFAULT_WIDTH)
      w = default_width_for_integer (length);

    p = read_block_form (dtp, &w);
diff --git a/libgfortran/io/write.c b/libgfortran/io/write.c
index 4ef35561fdd..eacd1f79715 100644
--- a/libgfortran/io/write.c
+++ b/libgfortran/io/write.c
@@ -1048,8 +1048,6 @@ btoa_big (const char *s, char *buffer, int len, 
GFC_UINTEGER_LARGEST *n)
         }
      }

-  *q = '\0';
-
    if (*n == 0)
      return "0";

@@ -1207,6 +1205,9 @@ write_b (st_parameter_dt *dtp, const fnode *f, const char 
*source, int len)
    char itoa_buf[GFC_BTOA_BUF_SIZE];
    GFC_UINTEGER_LARGEST n = 0;

+  /* Ensure we end up with a null terminated string.  */
+  memset(itoa_buf, '\0', GFC_BTOA_BUF_SIZE);
+
    if (len > (int) sizeof (GFC_UINTEGER_LARGEST))
      {
        p = btoa_big (source, itoa_buf, len, &n);



More information about the Fortran mailing list