tUse snprintf over sprintf - sphere - GPU-based 3D discrete element method algo… | |
git clone git://src.adamsgaard.dk/sphere | |
Log | |
Files | |
Refs | |
LICENSE | |
--- | |
commit c4ee06baa5b3cae0895a35a082579351582b26fd | |
parent c9b37d904623542765501b38f1d70f86951140d0 | |
Author: Anders Damsgaard <[email protected]> | |
Date: Mon, 2 Sep 2019 10:48:22 +0200 | |
Use snprintf over sprintf | |
Diffstat: | |
M src/sphere_status.c | 7 ++++--- | |
1 file changed, 4 insertions(+), 3 deletions(-) | |
--- | |
diff --git a/src/sphere_status.c b/src/sphere_status.c | |
t@@ -31,7 +31,7 @@ int main(int argc, char *argv[]) | |
char* dotpos; | |
char outstring[100]; | |
char* p; | |
- sprintf(outputdir, "%s/output/", cwd); | |
+ snprintf(outputdir, sizeof(outputdir), "%s/output/", cwd); | |
n = scandir(outputdir, &namelist, 0 , alphasort); | |
if (n < 0) { | |
fprintf(stderr, "Error: could not open directory: %s\n", outputdir… | |
t@@ -45,7 +45,8 @@ int main(int argc, char *argv[]) | |
!= NULL) { | |
*dotpos = '\0'; | |
- sprintf(outstring, "%-54s ", namelist[i]->d_name); | |
+ snprintf(outstring, sizeof(outstring), "%-54s ", | |
+ namelist[i]->d_name); | |
for (p = outstring; *p != '\0'; p++) | |
if (*p == ' ') *p = '.'; | |
printf(" %s", outstring); | |
t@@ -86,7 +87,7 @@ int open_status_file(char* cwd, char* sim_name, int format) { | |
// Open the simulation status file | |
FILE *fp; | |
char file[1000]; // Complete file path+name variable | |
- sprintf(file,"%s/output/%s.status.dat", cwd, sim_name); | |
+ snprintf(file, sizeof(file), "%s/output/%s.status.dat", cwd, sim_name); | |
if ((fp = fopen(file, "rt"))) { | |
float time_current; |