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

Barry Smith bsmith at petsc.dev
Fri Jul 12 08:40:51 CDT 2024


   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 <knepley at gmail.com> 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 <ivanluthfi5 at gmail.com <mailto:ivanluthfi5 at gmail.com>> 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_uCfscf7eWS!dMw87FGcY2KugOvdL79R4oeCp3123y3KJM7PolI9-vEhud2d9hXWYW_Us21eQGtkLa2GeY8mG9eiTO7R0_03y2w$  <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/e99600fc/attachment-0001.html>


More information about the petsc-users mailing list