all repos — mgba @ 3795a64b775107bac77e03bbd2601402de57e043

mGBA Game Boy Advance Emulator

Test: I added strlcpy for a reason
Vicki Pfau vi@endrift.com
Sat, 25 Jul 2020 23:37:06 -0700
commit

3795a64b775107bac77e03bbd2601402de57e043

parent

79d2e95d02c3e68d2420bf75ace07f739a383a03

1 files changed, 12 insertions(+), 11 deletions(-)

jump to
M src/platform/test/cinema-main.csrc/platform/test/cinema-main.c

@@ -11,6 +11,7 @@ #include <mgba/feature/commandline.h>

#include <mgba/feature/video-logger.h> #include <mgba-util/png-io.h> +#include <mgba-util/string.h> #include <mgba-util/table.h> #include <mgba-util/vector.h> #include <mgba-util/vfs.h>

@@ -127,7 +128,7 @@ return false;

} break; case 'b': - strncpy(base, optarg, sizeof(base)); + strlcpy(base, optarg, sizeof(base)); // TODO: Verify path exists break; case 'd':

@@ -140,7 +141,7 @@ case 'n':

dryRun = true; break; case 'o': - strncpy(outdir, optarg, sizeof(outdir)); + strlcpy(outdir, optarg, sizeof(outdir)); // TODO: Make directory break; case 'q':

@@ -244,7 +245,7 @@ }

} static void testToPath(const char* testName, char* path) { - strncpy(path, base, PATH_MAX); + strlcpy(path, base, PATH_MAX); bool dotSeen = true; size_t i;

@@ -253,7 +254,7 @@ if (testName[0] == '.') {

dotSeen = true; } else { if (dotSeen) { - strncpy(&path[i], PATH_SEP, PATH_MAX - i); + strlcpy(&path[i], PATH_SEP, PATH_MAX - i); i += strlen(PATH_SEP); dotSeen = false; if (!i) {

@@ -268,7 +269,7 @@ }

static void _loadConfigTree(struct Table* configTree, const char* testName) { char key[MAX_TEST]; - strncpy(key, testName, sizeof(key) - 1); + strlcpy(key, testName, sizeof(key)); struct mCoreConfig* config; while (!(config = HashTableLookup(configTree, key))) {

@@ -301,7 +302,7 @@ static const char* _lookupValue(struct Table* configTree, const char* testName, const char* key) {

_loadConfigTree(configTree, testName); char testKey[MAX_TEST]; - strncpy(testKey, testName, sizeof(testKey) - 1); + strlcpy(testKey, testName, sizeof(testKey)); struct mCoreConfig* config; while (true) {

@@ -378,10 +379,10 @@ if (strncmp(base, directory, strlen(base)) != 0) {

return false; } memset(test, 0, sizeof(*test)); - strncpy(test->directory, directory, sizeof(test->directory) - 1); - strncpy(test->filename, filename, sizeof(test->filename) - 1); + strlcpy(test->directory, directory, sizeof(test->directory)); + strlcpy(test->filename, filename, sizeof(test->filename)); directory += strlen(base) + 1; - strncpy(test->name, directory, sizeof(test->name) - 1); + strlcpy(test->name, directory, sizeof(test->name)); char* str = strstr(test->name, PATH_SEP); while (str) { str[0] = '.';

@@ -446,7 +447,7 @@ }

static struct VDir* _makeOutDir(const char* testName) { char path[PATH_MAX] = {0}; - strncpy(path, outdir, sizeof(path) - 1); + strlcpy(path, outdir, sizeof(path)); char* pathEnd = path + strlen(path); const char* pos; while (true) {

@@ -768,7 +769,7 @@ }

#ifndef _WIN32 char* rbase = realpath(base, NULL); if (rbase) { - strncpy(base, rbase, PATH_MAX); + strlcpy(base, rbase, sizeof(base)); free(rbase); } #endif