mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 16:10:36 +00:00
addons/LoadState.cpp used strncpy, which MSVC deprecates (C4996) and which does not terminate on truncation, so the call site had to add the terminator itself. frame/Attributes.cpp had already met that warning and answered it with a local BoundedCopy helper. Promote that helper to Common rather than copy it a second time, and point both files at it. The helper treats a null source as empty, so LoadState loses its null-name branch as well. Behavior is unchanged: strncpy(dst, src, kMaxName - 1) plus a manual terminator wrote at most kMaxName - 1 characters, and so does BoundedCopy(dst, src, kMaxName). strncpy_s was the other option and is worse here. It invokes the invalid-parameter handler on truncation unless the caller passes _TRUNCATE, and LoadState runs inside an engine hook.
27 lines
1.1 KiB
C++
27 lines
1.1 KiB
C++
// This file is part of ClassicAPI.
|
|
//
|
|
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
|
// of the GNU General Public License as published by the Free Software Foundation, either
|
|
// version 3 of the License, or (at your option) any later version.
|
|
//
|
|
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
// PURPOSE. See the GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License along with
|
|
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
#include <cstddef>
|
|
|
|
namespace Common {
|
|
|
|
bool PatchBytes(void *dst, const void *src, size_t len);
|
|
|
|
// Bounded, always-terminated string copy: writes at most `n - 1`
|
|
// characters plus the terminator, and treats a null `src` as empty. `n`
|
|
// is the size of `dst`. Stands in for `strncpy`, which MSVC deprecates
|
|
// (C4996) and which does not terminate on truncation.
|
|
void BoundedCopy(char *dst, const char *src, size_t n);
|
|
|
|
} // namespace Common
|