- `get_pdb_atomnumber`
GCC was worried that we're copying up to 4 bytes to a buffer of
length 4, not leaving the space for terminating \0. The source string
is guaranteed to have length 3 + terminator, so not a problem.
Changed to strcpy, since it should be safe here.
While at it, renamed a variable, gave a name to a magic constant,
added a static_assert to ensure safety.
- `read_vsite_database`
GCC was complaining that we're copying 4094 bytes from a string of
length 4094, possibly truncating the terminating \0. The string was
guaranteed to have a terminator in its first 4093 bytes (fgets2 will
put it no later than STRLEN-2, and we also skip the first character).
But to make GCC happy, I see no harm in adding 1 more byte to strncpy.
Another warning from GCC is an actual error, fixed in MR !1487.
atomNumberSet = true;
}
}
- std::string buf;
+ static constexpr size_t sc_maxElementNameLength = 3;
+ static_assert(sizeof(atoms->atom[i].elem) >= sc_maxElementNameLength + 1);
+ std::string element;
if (atomNumberSet)
{
atoms->atom[i].atomnumber = atomnumber;
- buf = aps->elementFromAtomNumber(atomnumber);
+ element = aps->elementFromAtomNumber(atomnumber);
if (debug)
{
fprintf(debug, "Atomnumber for atom '%s' is %d\n", anm, atomnumber);
}
}
- buf.resize(3);
- std::strncpy(atoms->atom[i].elem, buf.c_str(), 4);
+ element.resize(sc_maxElementNameLength);
+ std::strcpy(atoms->atom[i].elem, element.c_str());
}
}
{
if (pline[0] == OPENDIR)
{
- strncpy(dirstr, pline + 1, STRLEN - 2);
+ strncpy(dirstr, pline + 1, STRLEN - 1);
if ((ch = strchr(dirstr, CLOSEDIR)) != nullptr)
{
(*ch) = 0;