Skip to content

Commit 1bba685

Browse files
authored
Merge pull request #1858 from petterreinholdtsen/src-halcmd-strlimcpy-len
Correct string length handling in strlimcpy in halcmd.c
2 parents 9d025fa + 9cb46a2 commit 1bba685

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/hal/utils/halcmd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,10 +678,10 @@ static int strip_comments ( char *buf )
678678
679679
*/
680680
static int strlimcpy(char **dest, char *src, int srclen, int *destspace) {
681-
if (*destspace < srclen) {
681+
if (*destspace < srclen+1) {
682682
return -1;
683683
} else {
684-
strncpy(*dest, src, srclen);
684+
strncpy(*dest, src, *destspace);
685685
(*dest)[srclen] = '\0';
686686
srclen = strlen(*dest); /* use the actual number of bytes copied */
687687
*destspace -= srclen;

0 commit comments

Comments
 (0)