Skip to content

Commit

Permalink
Merge pull request #67 from epics-modules/fix_strNcpy
Browse files Browse the repository at this point in the history
Protect against deferencing null pointers in strNcpy macro
  • Loading branch information
keenanlang authored Aug 26, 2024
2 parents 74435e2 + f52a458 commit ec4a5dc
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions asApp/src/save_restore.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,12 @@ extern int appendToFile(const char *filename, const char *line);
extern float mySafeDoubleToFloat(double d);

/* strncpy sucks (may copy extra characters, may not null-terminate) */
#define strNcpy(dest, src, N) \
{ \
int ii; \
char *dd = dest; \
const char *ss = src; \
for (ii = 0; *ss && ii < N - 1; ii++) *dd++ = *ss++; \
*dd = '\0'; \
#define strNcpy(dest, src, N) \
{ \
int ii; \
char *dd = dest; \
const char *ss = src; \
if (dd && ss) \
for (ii = 0; *ss && ii < N - 1; ii++) *dd++ = *ss++; \
*dd = '\0'; \
}

0 comments on commit ec4a5dc

Please sign in to comment.