Commit ccfd61b4 authored by Stephen Morris's avatar Stephen Morris

[3430] Changes in a bid to avoid a Coverity warning

Coverity picked up that a construct like "&array[ARRAY_LENGTH]" is
an access to an invalid element, although it is a valid marker
as the end of an STL range.  This change alters that construct
to "array + ARRAY_LENGTH".
parent 35860175
......@@ -366,8 +366,8 @@ Pkt4::setSname(const uint8_t* sname, size_t snameLen /*= MAX_SNAME_LEN*/) {
isc_throw(InvalidParameter, "Invalid sname specified");
}
std::copy(&sname[0], &sname[snameLen], &sname_[0]);
std::fill(&sname_[snameLen], &sname_[MAX_SNAME_LEN], 0);
std::copy(sname, (sname + snameLen), sname_);
std::fill((sname_ + snameLen), (sname_ + MAX_SNAME_LEN), 0);
// No need to store snameLen as any empty space is filled with 0s
}
......@@ -382,8 +382,8 @@ Pkt4::setFile(const uint8_t* file, size_t fileLen /*= MAX_FILE_LEN*/) {
isc_throw(InvalidParameter, "Invalid file name specified");
}
std::copy(&file[0], &file[fileLen], &file_[0]);
std::fill(&file_[fileLen], &file_[MAX_FILE_LEN], 0);
std::copy(file, (file + fileLen), file_);
std::fill((file_ + fileLen), (file_ + MAX_FILE_LEN), 0);
// No need to store fileLen as any empty space is filled with 0s
}
......
......@@ -491,12 +491,12 @@ TEST_F(Pkt4Test, sname) {
scoped_ptr<Pkt4> pkt;
// Let's test each sname length, from 0 till 64
for (int snameLen = 0; snameLen < Pkt4::MAX_SNAME_LEN; snameLen++) {
for (int i = 0; i < Pkt4::MAX_SNAME_LEN; i++) {
sname[i] = 0;
for (int snameLen = 0; snameLen < Pkt4::MAX_SNAME_LEN; ++snameLen) {
for (int i = 0; i < snameLen; ++i) {
sname[i] = i + 1;
}
for (int i = 0; i < snameLen; i++) {
sname[i] = i;
for (int i = snameLen; i < Pkt4::MAX_SNAME_LEN; ++i) {
sname[i] = 0;
}
// Type and transaction doesn't matter in this test
......@@ -529,12 +529,12 @@ TEST_F(Pkt4Test, file) {
scoped_ptr<Pkt4> pkt;
// Let's test each file length, from 0 till 128.
for (int fileLen = 0; fileLen < Pkt4::MAX_FILE_LEN; fileLen++) {
for (int i = 0; i < Pkt4::MAX_FILE_LEN; i++) {
file[i] = 0;
for (int fileLen = 0; fileLen < Pkt4::MAX_FILE_LEN; ++fileLen) {
for (int i = 0; i < fileLen; ++i) {
file[i] = i + 1;
}
for (int i = 0; i < fileLen; i++) {
file[i] = i;
for (int i = fileLen; i < Pkt4::MAX_FILE_LEN; ++i) {
file[i] = 0;
}
// Type and transaction doesn't matter in this test.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment