[Fortran] check the length of internal file
With the following example, gfortran has runtime error:
program main
character(len=5) :: s
write(s, '(3I0)') [11, 22, 33]
print '(a)', s
end program main
since the written string is longer than string s.
It would be nice to have a check that will determine such situations (especially when runtime values are used).
Hi @foxtran,
Thanks for the suggestion! This idea reminds me of other out-of-bounds accesses that are documented through other checks (e.g., PWR014, PWD004), although this scenario could be addressed in different ways, such as even suggesting an "enough size" check before issuing the write operation. It would also be applicable to string-copy calls in the C language.
We'll leave this issue open to not lose track of the idea, and as always, feel free to open a PR if you'd like to suggest an entry for this potential check!
Steps for adding a new recommendation (click me)
-
Each recommendation resides in its own directory under
Checks/. Create the directory and update the list of checks in theREADME.mdat the root of the repository. -
Add a
README.mdfile that includes the following:-
Title: ID (e.g., the next available
PWRnumber) + Name of the recommendation. - Issue: A brief description (1-2 sentences) of how the discouraged practice impacts the code.
- Actions: A brief explanation (1-2 sentences) of how to refactor the code from the discouraged to the encouraged practice.
- Relevance: A more detailed explanation of why adopting the recommended practice is beneficial, expanding on the previous points.
- Code examples: Include a before-and-after code example to illustrate the improvement.
- References: Add links or references for further reading, if available.
-
Title: ID (e.g., the next available
-
Create standalone
exampleandsolutionsource files containing the code examples. -
Optionally, include a benchmark demonstrating the before-and-after performance impact of the change. In cases like this, the expectation is that the performance of the code should not degrade.
For reference, feel free to check out previous PRs to see how these steps are implemented in practice. For example, this is the PR that added PWR075.
Naturally, don't hesitate to ask at any moment if you have any issues. We'll be glad to help!