From a7a0868a813ee34e40e65b602553918cd60fd03b Mon Sep 17 00:00:00 2001 From: KIT! Date: Wed, 24 Apr 2024 14:27:27 +0200 Subject: [PATCH] Fixed an off-by-one error and config loading for reader name Reading card 3 and above resulted in an off by one error that always threw a "this line isn't X bytes long" error. Readername now always gets properly loaded from config : I've added comments in the config file to make it obvious what each line does but that fucked up the reader name config. i'm now discarding the comment after loading the line. --- src/aimeio.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/aimeio.c b/src/aimeio.c index 3cad94e..3d6d3f1 100644 --- a/src/aimeio.c +++ b/src/aimeio.c @@ -9,6 +9,27 @@ static struct aime_io_config aime_io_cfg; static struct card_data card_data; #pragma region CONFIG +// This is used because otherwise loading a reader with a given name while keeping the comment inline in the config file fails.. +void RemoveCommentAndTruncate(wchar_t *value) +{ + size_t len = wcslen(value); + wchar_t *semicolon = NULL; + + // Remove comments + semicolon = wcschr(value, L';'); + if (semicolon != NULL) + { + *semicolon = L'\0'; + len = wcslen(value); + } + + // Trim trailing whitespaces + while (len > 0 && (value[len - 1] == L' ' || value[len - 1] == L'\t' || value[len - 1] == L'\r' || value[len - 1] == L'\n')) + { + value[--len] = L'\0'; + } +} + static void aime_io_config_read(struct aime_io_config *cfg, const wchar_t *filename) { assert(cfg != NULL); @@ -43,6 +64,7 @@ static void aime_io_config_read(struct aime_io_config *cfg, const wchar_t *filen cfg->reader_name, _countof(cfg->reader_name), filename); + RemoveCommentAndTruncate(cfg->reader_name); cfg->reader_optional = GetPrivateProfileIntW( L"aimeio", @@ -95,7 +117,10 @@ static HRESULT aime_io_read_id_file(const wchar_t *path, uint8_t *bytes, size_t } if (c == '\n') + { currentLine++; + offset++; + } offset++; }