diam_dict.l,wimaxasncp_dict.l: fix -Werror=stringop-truncation

The given "len" is the size of the string in "txt" excluding the NUL
terminator. GCC 8.2.1+20181127-1 rightfully complains that strncpy will
not terminate the destination buffer.

Change-Id: I592c7c218cf07c13697de4e60f454326a93d1124
Reviewed-on: https://code.wireshark.org/review/31600
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Peter Wu 2019-01-19 00:32:49 +01:00 committed by Anders Broman
parent 7e7caaddf8
commit 5eb8edf1cb
2 changed files with 4 additions and 5 deletions

View File

@ -664,13 +664,13 @@ append_to_buffer(const char* txt, unsigned len, DiamDict_scanner_state_t *statep
statep->write_ptr = statep->strbuf;
}
if ( (statep->len_strbuf + len) >= statep->size_strbuf ) {
if (statep->len_strbuf + len >= statep->size_strbuf) {
statep->strbuf = (char*)g_realloc(statep->strbuf,statep->size_strbuf *= 2);
statep->read_ptr = statep->strbuf;
}
statep->write_ptr = statep->strbuf + statep->len_strbuf;
strncpy(statep->write_ptr,txt,len);
memcpy(statep->write_ptr, txt, len + 1);
statep->len_strbuf += len;
}

View File

@ -593,14 +593,13 @@ static void append_to_buffer(const gchar *txt, int len, WimaxasncpDict_scanner_s
state->read_ptr = state->write_ptr = state->strbuf = (gchar *)g_malloc(state->size_strbuf);
}
if ( (state->len_strbuf + len + 1) >= state->size_strbuf ) {
if (state->len_strbuf + len >= state->size_strbuf) {
state->read_ptr = state->strbuf = (gchar *)g_realloc(state->strbuf,state->size_strbuf *= 2);
}
state->write_ptr = state->strbuf + state->len_strbuf;
strncpy(state->write_ptr,txt,len);
memcpy(state->write_ptr, txt, len + 1);
state->len_strbuf += len;
state->strbuf[state->len_strbuf] = '\0';
}
static size_t file_input(gchar *buf, size_t max, yyscan_t scanner) {