Skip to content

Commit 6b2a090

Browse files
stweilzdenop
authored andcommitted
viewer: Fix some compiler warnings (-Wstringop-truncation) (#1399)
gcc warnings: viewer/scrollview.cpp:72:10: warning: ‘char* strncpy(char*, const char*, size_t)’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation] viewer/scrollview.cpp:118:14: warning: ‘char* strncpy(char*, const char*, size_t)’ specified bound depends on the length of the source argument [-Wstringop-overflow=] viewer/scrollview.cpp:746:10: warning: ‘char* strncpy(char*, const char*, size_t)’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation] viewer/scrollview.cpp:830:10: warning: ‘char* strncpy(char*, const char*, size_t)’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation] Signed-off-by: Stefan Weil <[email protected]>
1 parent c222145 commit 6b2a090

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

viewer/scrollview.cpp

+4-7
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ SVEvent* SVEvent::copy() {
6969
any->command_id = command_id;
7070
any->counter = counter;
7171
any->parameter = new char[strlen(parameter) + 1];
72-
strncpy(any->parameter, parameter, strlen(parameter));
73-
any->parameter[strlen(parameter)] = '\0';
72+
strcpy(any->parameter, parameter);
7473
any->type = type;
7574
any->x = x;
7675
any->y = y;
@@ -115,7 +114,7 @@ void* ScrollView::MessageReceiver(void* a) {
115114

116115
if (cur->window != NULL) {
117116
cur->parameter = new char[strlen(p) + 1];
118-
strncpy(cur->parameter, p, strlen(p) + 1);
117+
strcpy(cur->parameter, p);
119118
if (strlen(p) > 0) { // remove the last \n
120119
cur->parameter[strlen(p)] = '\0';
121120
}
@@ -743,8 +742,7 @@ char* ScrollView::ShowInputDialog(const char* msg) {
743742
// wait till an input event (all others are thrown away)
744743
ev = AwaitEvent(SVET_INPUT);
745744
char* p = new char[strlen(ev->parameter) + 1];
746-
strncpy(p, ev->parameter, strlen(ev->parameter));
747-
p[strlen(ev->parameter)] = '\0';
745+
strcpy(p, ev->parameter);
748746
delete ev;
749747
return p;
750748
}
@@ -827,8 +825,7 @@ char* ScrollView::AddEscapeChars(const char* input) {
827825
lastptr = nextptr;
828826
nextptr = strchr(nextptr+1, '\'');
829827
}
830-
strncpy(message+pos, lastptr, strlen(lastptr));
831-
message[pos+strlen(lastptr)] = '\0';
828+
strcpy(message+pos, lastptr);
832829
return message;
833830
}
834831

0 commit comments

Comments
 (0)