From d10b83cedda4516ce2c9385544f4b96a3f4897cb Mon Sep 17 00:00:00 2001 From: Arnaud Becheler <8360330+Becheler@users.noreply.github.com> Date: Sun, 24 Aug 2025 21:15:47 +0200 Subject: [PATCH] Update iohb.c to use snprintf Use snprintf if available as some compilers (clang 14.0) issue deprecation warnings for sprintf, see issue #437 --- example/iohb.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/example/iohb.c b/example/iohb.c index 8a216358d..548ba9224 100644 --- a/example/iohb.c +++ b/example/iohb.c @@ -778,13 +778,13 @@ int writeHB_mat_double(const char* filename, int M, int N, if ( Ptrfmt == NULL ) Ptrfmt = "(8I10)"; ParseIfmt(Ptrfmt,&Ptrperline,&Ptrwidth); - sprintf(pformat,"%%%dd",Ptrwidth); + snprintf(pformat, sizeof(pformat), "%%%dd", Ptrwidth); ptrcrd = (N+1)/Ptrperline; if ( (N+1)%Ptrperline != 0) ptrcrd++; if ( Indfmt == NULL ) Indfmt = Ptrfmt; ParseIfmt(Indfmt,&Indperline,&Indwidth); - sprintf(iformat,"%%%dd",Indwidth); + snprintf(iformat, sizeof(iformat), "%%%dd", Indwidth); indcrd = nz/Indperline; if ( nz%Indperline != 0) indcrd++; @@ -793,9 +793,9 @@ int writeHB_mat_double(const char* filename, int M, int N, ParseRfmt(Valfmt,&Valperline,&Valwidth,&Valprec,&Valflag); if (Valflag == 'D') *strchr(Valfmt,'D') = 'E'; if (Valflag == 'F') - sprintf(vformat,"%% %d.%df",Valwidth,Valprec); + snprintf(vformat, sizeof(vformat), "%% %d.%df", Valwidth, Valprec); else - sprintf(vformat,"%% %d.%dE",Valwidth,Valprec); + snprintf(vformat, sizeof(vformat), "%% %d.%dE", Valwidth, Valprec); valcrd = nvalentries/Valperline; if ( nvalentries%Valperline != 0) valcrd++; } else valcrd = 0; @@ -804,9 +804,9 @@ int writeHB_mat_double(const char* filename, int M, int N, if ( Rhsfmt == NULL ) Rhsfmt = Valfmt; ParseRfmt(Rhsfmt,&Rhsperline,&Rhswidth,&Rhsprec, &Rhsflag); if (Rhsflag == 'F') - sprintf(rformat,"%% %d.%df",Rhswidth,Rhsprec); + snprintf(rformat, sizeof(rformat), "%% %d.%df", Rhswidth, Rhsprec); else - sprintf(rformat,"%% %d.%dE",Rhswidth,Rhsprec); + snprintf(rformat, sizeof(rformat), "%% %d.%dE", Rhswidth, Rhsprec); if (Rhsflag == 'D') *strchr(Rhsfmt,'D') = 'E'; rhscrd = nrhsentries/Rhsperline; if ( nrhsentries%Rhsperline != 0) rhscrd++; @@ -1361,16 +1361,16 @@ int writeHB_mat_char(const char* filename, int M, int N, if ( Ptrfmt == NULL ) Ptrfmt = "(8I10)"; ParseIfmt(Ptrfmt,&Ptrperline,&Ptrwidth); - sprintf(pformat,"%%%dd",Ptrwidth); + snprintf(pformat, sizeof(pformat), "%%%dd", Ptrwidth); if ( Indfmt == NULL ) Indfmt = Ptrfmt; ParseIfmt(Indfmt,&Indperline,&Indwidth); - sprintf(iformat,"%%%dd",Indwidth); + snprintf(iformat, sizeof(iformat), "%%%dd", Indwidth); if ( Type[0] != 'P' ) { /* Skip if pattern only */ if ( Valfmt == NULL ) Valfmt = "(4E20.13)"; ParseRfmt(Valfmt,&Valperline,&Valwidth,&Valprec,&Valflag); - sprintf(vformat,"%%%ds",Valwidth); + snprintf(vformat, sizeof(vformat), "%%%ds", Valwidth); } ptrcrd = (N+1)/Ptrperline; @@ -1385,7 +1385,7 @@ int writeHB_mat_char(const char* filename, int M, int N, if ( Nrhs > 0 ) { if ( Rhsfmt == NULL ) Rhsfmt = Valfmt; ParseRfmt(Rhsfmt,&Rhsperline,&Rhswidth,&Rhsprec, &Rhsflag); - sprintf(rformat,"%%%ds",Rhswidth); + snprintf(rformat, sizeof(rformat), "%%%ds", Rhswidth); rhscrd = nrhsentries/Rhsperline; if ( nrhsentries%Rhsperline != 0) rhscrd++; if ( Rhstype[1] == 'G' ) rhscrd+=rhscrd;