[petsc-users] Warning [-Wformat-overflow]

Matthew Knepley knepley at gmail.com
Fri Jul 12 05:53:21 CDT 2024


On Fri, Jul 12, 2024 at 2:26 AM Ivan Luthfi <ivanluthfi5 at gmail.com> wrote:

> 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,
> ZjQcmQRYFpfptBannerStart
> This Message Is From an External Sender
> This message came from outside your organization.
>
> ZjQcmQRYFpfptBannerEnd
> 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_uCfscf7eWS!YNtOwQCCJYLu6JV0ph8gXnJeFhrQXAiTdZyhV_C0bBut_pZLBhsZw-xORAasjijkRzFe_0udBt4lKebIWfMb$  <https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!YNtOwQCCJYLu6JV0ph8gXnJeFhrQXAiTdZyhV_C0bBut_pZLBhsZw-xORAasjijkRzFe_0udBt4lKX2xYfz0$ >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20240712/d60d720d/attachment.html>


More information about the petsc-users mailing list