Skip to content
Snippets Groups Projects
Commit f1f7b121 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Use strlcpy instead of sprintf("%.*s") string truncation trick

Resolves MSVC x64 build warnings.

Also fixes a bug with wrong sizeof argument used in readdir() (!)
parent 43a78909
Branches
Tags
No related merge requests found
...@@ -380,7 +380,7 @@ DIR* opendir(const char* dirname) ...@@ -380,7 +380,7 @@ DIR* opendir(const char* dirname)
errno = ENOMEM; errno = ENOMEM;
return NULL; return NULL;
} }
sprintf(dir->filespec, "%.*s", sizeof(dir->filespec) - 5, dirname); strlcpy(dir->filespec, dirname, sizeof(dir->filespec) - 5);
if (*dir->filespec && dir->filespec[strlen(dir->filespec) - 1] != '\\') if (*dir->filespec && dir->filespec[strlen(dir->filespec) - 1] != '\\')
strcat(dir->filespec, "\\"); strcat(dir->filespec, "\\");
strcat(dir->filespec, "*.*"); strcat(dir->filespec, "*.*");
...@@ -400,7 +400,7 @@ struct dirent* readdir(DIR* dir) ...@@ -400,7 +400,7 @@ struct dirent* readdir(DIR* dir)
return NULL; return NULL;
if (dir->handle == -1) if (dir->handle == -1)
return NULL; return NULL;
sprintf(dir->dirent.d_name, "%.*s", sizeof(struct dirent) - 1, dir->finddata.name); strlcpy(dir->dirent.d_name, dir->finddata.name, sizeof(dir->dirent.d_name) - 1);
if (_findnext(dir->handle, &dir->finddata) != 0) if (_findnext(dir->handle, &dir->finddata) != 0)
dir->end = true; dir->end = true;
return &dir->dirent; return &dir->dirent;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment