2014-10-12 20:29:31

by Rickard Strandqvist

[permalink] [raw]
Subject: [PATCH] scripts: docproc.c: Changed from using strncat to strlcat

Changed from using strncat to strlcat to simplify the code

Signed-off-by: Rickard Strandqvist <[email protected]>
---
scripts/docproc.c | 24 +++++++++++-------------
1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/scripts/docproc.c b/scripts/docproc.c
index e267e621..dd1d10a 100644
--- a/scripts/docproc.c
+++ b/scripts/docproc.c
@@ -118,10 +118,10 @@ static void exec_kernel_doc(char **svec)
perror("fork");
exit(1);
case 0:
- memset(real_filename, 0, sizeof(real_filename));
- strncat(real_filename, kernsrctree, PATH_MAX);
- strncat(real_filename, "/" KERNELDOCPATH KERNELDOC,
- PATH_MAX - strlen(real_filename));
+ strlcpy(real_filename, kernsrctree,
+ sizeof(real_filename));
+ strlcat(real_filename, "/" KERNELDOCPATH KERNELDOC,
+ sizeof(real_filename));
execvp(real_filename, svec);
fprintf(stderr, "exec ");
perror(real_filename);
@@ -199,11 +199,9 @@ static void find_export_symbols(char * filename)
char line[MAXLINESZ];
if (filename_exist(filename) == NULL) {
char real_filename[PATH_MAX + 1];
- memset(real_filename, 0, sizeof(real_filename));
- strncat(real_filename, srctree, PATH_MAX);
- strncat(real_filename, "/", PATH_MAX - strlen(real_filename));
- strncat(real_filename, filename,
- PATH_MAX - strlen(real_filename));
+ strlcpy(real_filename, srctree, sizeof(real_filename));
+ strlcat(real_filename, "/", sizeof(real_filename));
+ strlcat(real_filename, filename, sizeof(real_filename));
sym = add_new_file(filename);
fp = fopen(real_filename, "r");
if (fp == NULL) {
@@ -379,10 +377,10 @@ static void find_all_symbols(char *filename)
case 0:
close(pipefd[0]);
dup2(pipefd[1], 1);
- memset(real_filename, 0, sizeof(real_filename));
- strncat(real_filename, kernsrctree, PATH_MAX);
- strncat(real_filename, "/" KERNELDOCPATH KERNELDOC,
- PATH_MAX - strlen(real_filename));
+ strlcpy(real_filename, kernsrctree,
+ sizeof(real_filename));
+ strlcat(real_filename, "/" KERNELDOCPATH KERNELDOC,
+ sizeof(real_filename));
execvp(real_filename, vec);
fprintf(stderr, "exec ");
perror(real_filename);
--
1.7.10.4