Skip to content

Commit

Permalink
Improved C string copy function
Browse files Browse the repository at this point in the history
  • Loading branch information
kala13x committed Dec 6, 2023
1 parent 2f489b0 commit 12c6f9d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/data/xstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,12 @@ char *xstrfill(size_t nLength, char cFill)
int xstrncpyarg(char *pDest, size_t nSize, const char *pFmt, va_list args)
{
if (pDest == NULL || !nSize) return XSTDERR;
size_t nLength = 0;
pDest[0] = XSTR_NUL;

int nBytes = vsnprintf(pDest, nSize, pFmt, args);
if (nBytes > 0) nLength = XSTD_MIN((size_t)nBytes, nSize - 1);
int nBytes = vsnprintf(pDest, nSize - 1, pFmt, args);
if (nBytes >= 0) pDest[nBytes] = XSTR_NUL;

pDest[nLength] = XSTR_NUL;
return (int)nLength;
return nBytes;
}

char* xstracpyargs(const char *pFmt, va_list args, size_t *nSize)
Expand Down
2 changes: 1 addition & 1 deletion src/xver.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#define XUTILS_VERSION_MAX 2
#define XUTILS_VERSION_MIN 5
#define XUTILS_BUILD_NUMBER 49
#define XUTILS_BUILD_NUMBER 50

#ifdef __cplusplus
extern "C" {
Expand Down

0 comments on commit 12c6f9d

Please sign in to comment.