Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xml writing strings with newlines doesn't respect max buffer length #82

Open
bernstei opened this issue Aug 16, 2024 · 1 comment
Open

Comments

@bernstei
Copy link
Contributor

Can anyone explain the logic of this if statem and the block it controls?

if (i>0) then

I'm finding that fortran (gfortran 9.4 on linux, specifically), complains about an end of record when I try to write a string with long lines (~2500 characters) separated by newlines, with the error in line 221.

From what I can tell, i (calculated in the previous source line) is the location of the newline, arbitrarily far into the string, so an arbitrarily large integer. As a result, the write statement that runs if a newline is found (i > 0) writes an arbitrarily long string to the file (from current location n to n+i-2).

I think some other logic is supposed to be used (maybe just put this if clause after the one that checks against MAX_BUF_SIZE?), but I don't quite understand what's supposed to be happening.

@bernstei
Copy link
Contributor Author

I think this is a sufficient fix, but I'm not sure I fully understand the logic to be confident

diff --git a/common/m_common_buffer.F90 b/common/m_common_buffer.F90
index 0bf5183..de463ec 100644
--- a/common/m_common_buffer.F90
+++ b/common/m_common_buffer.F90
@@ -216,7 +216,8 @@ contains
     do while (n<=len(s2))
       ! Note this is an XML-1.0 only definition of newline
       i = scan(s2(n:), achar(10)//achar(13))
-      if (i>0) then
+      if (i>0 .and. i-2<MAX_BUFF_SIZE) then
+        ! close enough newline, use it
         ! turn that newline into an output newline ...
         write(buffer%unit, '(a)') s2(n:n+i-2)
         n = n + i

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant