[PATCH v3] cpukit: Edit String Warninng
Aschref Ben-Thabet
aschref.ben-thabet at embedded-brains.de
Thu Aug 13 15:37:18 UTC 2020
From: Aschref Ben Thabet <aschref.ben-thabet at embedded-brains.de>
Using FILENAME_MAX as a parameter in strncpy function can gererate
warnings of type: -Wstringop-truncation. Replacing it with sizeof
(distination_buffer) can avoid this warning.
---
cpukit/libmisc/shell/main_edit.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/cpukit/libmisc/shell/main_edit.c b/cpukit/libmisc/shell/main_edit.c
index e43ff68d2b..feefd6bff1 100644
--- a/cpukit/libmisc/shell/main_edit.c
+++ b/cpukit/libmisc/shell/main_edit.c
@@ -286,7 +286,7 @@ static struct editor *find_editor(struct env *env, char *filename) {
struct editor *ed = env->current;
struct editor *start = ed;
- if (!realpath(filename, fn)) strncpy(fn, filename, FILENAME_MAX);
+ if (!realpath(filename, fn)) strncpy(fn, filename, sizeof(fn)-1);
do {
if (strcmp(fn, ed->filename) == 0) return ed;
@@ -297,8 +297,9 @@ static struct editor *find_editor(struct env *env, char *filename) {
static int new_file(struct editor *ed, char *filename) {
if (*filename) {
- strncpy(ed->filename, filename, FILENAME_MAX);
- } else {
+ strncpy(ed->filename, filename, sizeof(ed->filename)-1);
+ }
+ else {
sprintf(ed->filename, "Untitled-%d", ++ed->env->untitled);
ed->newfile = 1;
}
@@ -1776,7 +1777,7 @@ static void save_editor(struct editor *ed) {
}
}
strncpy(
- ed->filename, (const char*) ed->env->linebuf, FILENAME_MAX);
+ ed->filename, (const char*)ed->env->linebuf, sizeof(ed->filename)-1);
ed->newfile = 0;
}
--
2.26.2
More information about the devel
mailing list