Also ensure filename is a sufficiently long string to hold any possible output from the format.
On Jul 12, 2024, at 6:53 AM, Matthew Knepley <[email protected]> wrote:
This Message Is From an External Sender This message came from outside your organization. On Fri, Jul 12, 2024 at 2:26 AM Ivan Luthfi <[email protected] <mailto:[email protected]>> wrote:
This Message Is From an External Sender This message came from outside your organization.
I have warning:
FormatFunction.c: In function 'ComputeStiffnessMatrix': FormatFunction.c:128:46: warning: '%d' directive writing between 1 and 11 bytes into a region of size between 0 and 99 [-Wformat-overflow] (line128) sprintf(filename, "%sc%d_N%dM%d_permeability.log", up->problem_description, up->problem_flag, up->Nx, up->Mx)
do you know why this warning appear? and how to fix it.
You are writing a PetscInt into the spot for an int. You can
1) Cast to int:
sprintf(filename, "%sc%d_N%dM%d_permeability.log", up->problem_description, up->problem_flag, (int)up->Nx, (int)up->Mx)
2) Use the custom format
sprintf(filename, "%sc%d_N%" PetscInt_FMT "M%" PetscInt_FMT "_permeability.log", up->problem_description, up->problem_flag, up->Nx, up->Mx)
Thanks,
Matt
-- Best regards, --
-- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener
https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCf... <https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!YNtOwQCCJYLu6JV0ph8gXnJeFhrQXAiTdZyhV_C0bBut_pZLBhsZw-xORAasjijkRzFe_0udBt4lKX2xYfz0$>