Skip to content

Commit 46559d7

Browse files
Merge pull request #438 from Becheler/patch-1
Update iohb.c to use snprintf
2 parents 1cfeb9a + d10b83c commit 46559d7

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

example/iohb.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -778,13 +778,13 @@ int writeHB_mat_double(const char* filename, int M, int N,
778778

779779
if ( Ptrfmt == NULL ) Ptrfmt = "(8I10)";
780780
ParseIfmt(Ptrfmt,&Ptrperline,&Ptrwidth);
781-
sprintf(pformat,"%%%dd",Ptrwidth);
781+
snprintf(pformat, sizeof(pformat), "%%%dd", Ptrwidth);
782782
ptrcrd = (N+1)/Ptrperline;
783783
if ( (N+1)%Ptrperline != 0) ptrcrd++;
784784

785785
if ( Indfmt == NULL ) Indfmt = Ptrfmt;
786786
ParseIfmt(Indfmt,&Indperline,&Indwidth);
787-
sprintf(iformat,"%%%dd",Indwidth);
787+
snprintf(iformat, sizeof(iformat), "%%%dd", Indwidth);
788788
indcrd = nz/Indperline;
789789
if ( nz%Indperline != 0) indcrd++;
790790

@@ -793,9 +793,9 @@ int writeHB_mat_double(const char* filename, int M, int N,
793793
ParseRfmt(Valfmt,&Valperline,&Valwidth,&Valprec,&Valflag);
794794
if (Valflag == 'D') *strchr(Valfmt,'D') = 'E';
795795
if (Valflag == 'F')
796-
sprintf(vformat,"%% %d.%df",Valwidth,Valprec);
796+
snprintf(vformat, sizeof(vformat), "%% %d.%df", Valwidth, Valprec);
797797
else
798-
sprintf(vformat,"%% %d.%dE",Valwidth,Valprec);
798+
snprintf(vformat, sizeof(vformat), "%% %d.%dE", Valwidth, Valprec);
799799
valcrd = nvalentries/Valperline;
800800
if ( nvalentries%Valperline != 0) valcrd++;
801801
} else valcrd = 0;
@@ -804,9 +804,9 @@ int writeHB_mat_double(const char* filename, int M, int N,
804804
if ( Rhsfmt == NULL ) Rhsfmt = Valfmt;
805805
ParseRfmt(Rhsfmt,&Rhsperline,&Rhswidth,&Rhsprec, &Rhsflag);
806806
if (Rhsflag == 'F')
807-
sprintf(rformat,"%% %d.%df",Rhswidth,Rhsprec);
807+
snprintf(rformat, sizeof(rformat), "%% %d.%df", Rhswidth, Rhsprec);
808808
else
809-
sprintf(rformat,"%% %d.%dE",Rhswidth,Rhsprec);
809+
snprintf(rformat, sizeof(rformat), "%% %d.%dE", Rhswidth, Rhsprec);
810810
if (Rhsflag == 'D') *strchr(Rhsfmt,'D') = 'E';
811811
rhscrd = nrhsentries/Rhsperline;
812812
if ( nrhsentries%Rhsperline != 0) rhscrd++;
@@ -1361,16 +1361,16 @@ int writeHB_mat_char(const char* filename, int M, int N,
13611361

13621362
if ( Ptrfmt == NULL ) Ptrfmt = "(8I10)";
13631363
ParseIfmt(Ptrfmt,&Ptrperline,&Ptrwidth);
1364-
sprintf(pformat,"%%%dd",Ptrwidth);
1364+
snprintf(pformat, sizeof(pformat), "%%%dd", Ptrwidth);
13651365

13661366
if ( Indfmt == NULL ) Indfmt = Ptrfmt;
13671367
ParseIfmt(Indfmt,&Indperline,&Indwidth);
1368-
sprintf(iformat,"%%%dd",Indwidth);
1368+
snprintf(iformat, sizeof(iformat), "%%%dd", Indwidth);
13691369

13701370
if ( Type[0] != 'P' ) { /* Skip if pattern only */
13711371
if ( Valfmt == NULL ) Valfmt = "(4E20.13)";
13721372
ParseRfmt(Valfmt,&Valperline,&Valwidth,&Valprec,&Valflag);
1373-
sprintf(vformat,"%%%ds",Valwidth);
1373+
snprintf(vformat, sizeof(vformat), "%%%ds", Valwidth);
13741374
}
13751375

13761376
ptrcrd = (N+1)/Ptrperline;
@@ -1385,7 +1385,7 @@ int writeHB_mat_char(const char* filename, int M, int N,
13851385
if ( Nrhs > 0 ) {
13861386
if ( Rhsfmt == NULL ) Rhsfmt = Valfmt;
13871387
ParseRfmt(Rhsfmt,&Rhsperline,&Rhswidth,&Rhsprec, &Rhsflag);
1388-
sprintf(rformat,"%%%ds",Rhswidth);
1388+
snprintf(rformat, sizeof(rformat), "%%%ds", Rhswidth);
13891389
rhscrd = nrhsentries/Rhsperline;
13901390
if ( nrhsentries%Rhsperline != 0) rhscrd++;
13911391
if ( Rhstype[1] == 'G' ) rhscrd+=rhscrd;

0 commit comments

Comments
 (0)