commit 03652fe9f02a1e030e8c0a91438a6345670b8a51
parent 69e9b31398228ace6e46e2f11dca69c3257047bf
Author: Johannes Lorenz <j.git@lorenz-ho.me>
Date: Tue, 15 Dec 2020 19:27:52 +0100
Fix snprintf warning (small target buffer)
Compiler raises issues if it knows that for `snprintf`, the target
buffer may be too small for the format string. This would not lead to
memory issues, but information could get lost by truncation.
Using `strncpy` eliminates the warning.
Diffstat:
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/Misc/Microtonal.cpp b/src/Misc/Microtonal.cpp
@@ -637,8 +637,10 @@ int Microtonal::loadscl(SclInfo &scl, const char *filename)
if(tmp[i] < 32)
tmp[i] = 0;
- snprintf(scl.Pname, MICROTONAL_MAX_NAME_LEN, "%s", tmp);
- snprintf(scl.Pcomment, MICROTONAL_MAX_NAME_LEN, "%s", tmp);
+ strncpy(scl.Pname, tmp, MICROTONAL_MAX_NAME_LEN);
+ strncpy(scl.Pcomment, tmp, MICROTONAL_MAX_NAME_LEN);
+ scl.Pname[MICROTONAL_MAX_NAME_LEN-1] = 0;
+ scl.Pcomment[MICROTONAL_MAX_NAME_LEN-1] = 0;
//loads the number of the notes
if(loadline(file, &tmp[0]) != 0)