Fixed use of strncpy in xstrcpy()

This commit is contained in:
Lew Rossman
2019-09-30 15:51:17 -04:00
parent 3300ef00cb
commit 38278f7d46

View File

@@ -18,6 +18,8 @@
//*** For the Windows SDK _tempnam function ***//
#ifdef _WIN32
#include <windows.h>
//#else
//#include <unistd.h >
#endif
#include "types.h"
@@ -1092,6 +1094,13 @@ void getTmpName(char *fname)
// --- for non-Windows systems:
#else
// --- use system function mkstemp() to create a temporary file name
/*
int f = -1;
strcpy(fname, "enXXXXXX");
f = mkstemp(fname);
close(f);
remove(fname);
*/
strcpy(fname, "enXXXXXX");
FILE *f = fdopen(mkstemp(fname), "r");
if (f == NULL) strcpy(fname, "");
@@ -1136,7 +1145,7 @@ char *xstrcpy(char **s1, const char *s2, const size_t n)
if (n2 > n1) *s1 = realloc(*s1, (n2 + 1) * sizeof(char));
// Copy the source string into the destination string
strncpy(*s1, s2, n2);
strncpy(*s1, s2, n2+1);
return *s1;
}