Use safe_strncpy.

This commit is contained in:
Matt Kraai 2001-05-27 14:11:52 +00:00
parent 4f6aea807b
commit 6e9e136fcb
2 changed files with 4 additions and 6 deletions

View File

@ -388,9 +388,8 @@ static int parse_file_cmd(struct sed_cmd *sed_cmd, const char *filecmdstr)
/* the first non-whitespace we get is a filename. the filename ends when we /* the first non-whitespace we get is a filename. the filename ends when we
* hit a normal sed command terminator or end of string */ * hit a normal sed command terminator or end of string */
filenamelen = strcspn(&filecmdstr[idx], "; \n\r\t\v\0"); filenamelen = strcspn(&filecmdstr[idx], "; \n\r\t\v\0");
sed_cmd->filename = xmalloc(sizeof(char) * filenamelen + 1); sed_cmd->filename = xmalloc(filenamelen + 1);
strncpy(sed_cmd->filename, &filecmdstr[idx], filenamelen); safe_strncpy(sed_cmd->filename, &filecmdstr[idx], filenamelen + 1);
sed_cmd->filename[filenamelen] = 0;
return idx + filenamelen; return idx + filenamelen;
} }

5
sed.c
View File

@ -388,9 +388,8 @@ static int parse_file_cmd(struct sed_cmd *sed_cmd, const char *filecmdstr)
/* the first non-whitespace we get is a filename. the filename ends when we /* the first non-whitespace we get is a filename. the filename ends when we
* hit a normal sed command terminator or end of string */ * hit a normal sed command terminator or end of string */
filenamelen = strcspn(&filecmdstr[idx], "; \n\r\t\v\0"); filenamelen = strcspn(&filecmdstr[idx], "; \n\r\t\v\0");
sed_cmd->filename = xmalloc(sizeof(char) * filenamelen + 1); sed_cmd->filename = xmalloc(filenamelen + 1);
strncpy(sed_cmd->filename, &filecmdstr[idx], filenamelen); safe_strncpy(sed_cmd->filename, &filecmdstr[idx], filenamelen + 1);
sed_cmd->filename[filenamelen] = 0;
return idx + filenamelen; return idx + filenamelen;
} }