never use strncpy, anywhere.

This commit is contained in:
Enno Rehling 2017-01-06 21:24:31 +01:00
parent 9463642687
commit 8d02d5a5aa
3 changed files with 4 additions and 3 deletions

View File

@ -3,6 +3,7 @@
#include <platform.h>
#include <kernel/config.h>
#include <kernel/jsonconf.h>
#include <util/bsdstring.h>
#include <util/log.h>
#include <util/language.h>
#include <cJSON.h>
@ -45,7 +46,7 @@ int config_parse(const char *json)
if (xp >= ep) break;
}
xp = (ep > json + 10) ? ep - 10 : json;
strncpy(buffer, xp, sizeof(buffer));
strlcpy(buffer, xp, sizeof(buffer));
buffer[9] = 0;
log_error("json parse error in line %d, position %d, near `%s`\n", line, ep - lp, buffer);
}

View File

@ -167,7 +167,7 @@ static int lua_callspell(castorder * co)
if (hashpos != NULL) {
ptrdiff_t len = hashpos - fname;
assert(len < (ptrdiff_t) sizeof(fbuf));
strncpy(fbuf, fname, len);
memcpy(fbuf, fname, len);
fbuf[len] = '\0';
fname = fbuf;
}

View File

@ -12,7 +12,7 @@ void log_string(void *data, int level, const char *module, const char *format, v
unused_arg(format);
unused_arg(module);
unused_arg(level);
strncpy(str, arg, 32);
strcpy(str, arg);
}
static void test_logging(CuTest * tc)