public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "dominiq at lps dot ens.fr" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/61632] Memory corruption on error when writing formatted data
Date: Sun, 20 Jul 2014 18:18:00 -0000	[thread overview]
Message-ID: <bug-61632-4-2yMrPudmjA@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-61632-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #22 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
> Created attachment 33160 [details]
> Updated patch taking care of valgrind error
>
> This patch includes fixing the valgrind error by allocating and setting
> the NULL byte at the end of the format string.

With this patch all my tests for this PR pass without problem: no more memory
corruption and the caret is at the right position!-).

I have two questions:

(1) my understanding of 

  offset = (j > 60) ? j - 40 : 0;

  j -= offset;
  width = dtp->format_len - offset;

is to set j to 40 and to decrease width by j-40 if j>60.

This part is now removed, should not we limit offset to something?

(2) Do you need me to package one or two of my tests for the caret position?

Indeed I'ld perfectly happy if the behavior reported in comment 10 would be at
least understood. Note that with the code

      program p
      call ss0()
      call ss()
      end program p
      subroutine ss0
      CHARACTER(3), save :: ZTYP(4)
      DATA ZTYP /'WWW','XXX','YYY','ZZZ'/
      write(10,500,err=10,iostat=iosa) 'AAA','BBB',0.0,ZTYP
 500  FORMAT(2(A3),1PE13.5,A3)
      return
 10   write(10, *)
      write(10, *) 'iostat =', iosa
      end subroutine ss0
      subroutine ss
      CHARACTER(3), save :: ZTYP(4)
      DATA ZTYP /'WWW','XXX','YYY','ZZZ'/
      write(10,600) 'AAA','BBB',0.0,ZTYP
 600  FORMAT(A3,1PE13.5,2(A3))
      end subroutine ss

gives at run time

[Book15] f90/bug% cat fort.10
AAABBB  0.00000E+00WWW

 iostat =        5006

but my mother is saying "le mieux est l'ennemi du bien" (~ the best is against
the good) so I think this should not defer the commit of the patch.


  parent reply	other threads:[~2014-07-20 18:18 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-27 14:33 [Bug fortran/61632] New: memory corruption in Fortran RTL " arnaud02 at users dot sourceforge.net
2014-06-27 22:36 ` [Bug fortran/61632] " dominiq at lps dot ens.fr
2014-06-28 21:20 ` dominiq at lps dot ens.fr
2014-07-12 22:12 ` jvdelisle at gcc dot gnu.org
2014-07-13  7:49 ` dominiq at lps dot ens.fr
2014-07-13 17:05 ` jvdelisle at gcc dot gnu.org
2014-07-13 21:40 ` jvdelisle at gcc dot gnu.org
2014-07-13 22:46 ` dominiq at lps dot ens.fr
2014-07-14  0:47 ` jvdelisle at gcc dot gnu.org
2014-07-14 14:27 ` [Bug fortran/61632] Memory corruption on error " dominiq at lps dot ens.fr
2014-07-14 18:30 ` dominiq at lps dot ens.fr
2014-07-15  2:22 ` jvdelisle at gcc dot gnu.org
2014-07-15  9:08 ` dominiq at lps dot ens.fr
2014-07-15 14:51 ` dominiq at lps dot ens.fr
2014-07-15 14:58 ` sgk at troutmask dot apl.washington.edu
2014-07-15 15:13 ` dominiq at lps dot ens.fr
2014-07-16  3:20 ` jvdelisle at gcc dot gnu.org
2014-07-19  3:24 ` jvdelisle at gcc dot gnu.org
2014-07-20 18:18 ` dominiq at lps dot ens.fr [this message]
2014-07-20 20:04 ` jvdelisle at gcc dot gnu.org
2014-07-25 21:51 ` jvdelisle at gcc dot gnu.org
2015-01-15  4:26 ` jvdelisle at gcc dot gnu.org
2015-02-12  0:25 ` jvdelisle at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-61632-4-2yMrPudmjA@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).